Bug 1396856: Part 2 - Add top outer window ID to LoadInfo. r=ehsan

The WebRequest API needs to know if a given window ID is at the top level, for
various reasons. It currently figures this out by mapping a channel's load
context to a <browser> element, which tracks its current top outer window ID.
But this is inefficient, and not friendly to C++ callers.

Adding the top window ID to the load info simplifies things considerably.

MozReview-Commit-ID: Fy0gxTqQZMZ

--HG--
extra : rebase_source : bb5b1e1b3294004ca5e713fc88c4e20652296e53
This commit is contained in:
Kris Maglione 2017-09-06 14:25:23 -07:00
Родитель 9cf6734391
Коммит c79059605f
5 изменённых файлов: 34 добавлений и 3 удалений

Просмотреть файл

@ -387,6 +387,7 @@ LoadInfoToLoadInfoArgs(nsILoadInfo *aLoadInfo,
aLoadInfo->GetInnerWindowID(), aLoadInfo->GetInnerWindowID(),
aLoadInfo->GetOuterWindowID(), aLoadInfo->GetOuterWindowID(),
aLoadInfo->GetParentOuterWindowID(), aLoadInfo->GetParentOuterWindowID(),
aLoadInfo->GetTopOuterWindowID(),
aLoadInfo->GetFrameOuterWindowID(), aLoadInfo->GetFrameOuterWindowID(),
aLoadInfo->GetEnforceSecurity(), aLoadInfo->GetEnforceSecurity(),
aLoadInfo->GetInitialSecurityCheckDone(), aLoadInfo->GetInitialSecurityCheckDone(),
@ -482,6 +483,7 @@ LoadInfoArgsToLoadInfo(const OptionalLoadInfoArgs& aOptionalLoadInfoArgs,
loadInfoArgs.innerWindowID(), loadInfoArgs.innerWindowID(),
loadInfoArgs.outerWindowID(), loadInfoArgs.outerWindowID(),
loadInfoArgs.parentOuterWindowID(), loadInfoArgs.parentOuterWindowID(),
loadInfoArgs.topOuterWindowID(),
loadInfoArgs.frameOuterWindowID(), loadInfoArgs.frameOuterWindowID(),
loadInfoArgs.enforceSecurity(), loadInfoArgs.enforceSecurity(),
loadInfoArgs.initialSecurityCheckDone(), loadInfoArgs.initialSecurityCheckDone(),

Просмотреть файл

@ -29,6 +29,16 @@ using namespace mozilla::dom;
namespace mozilla { namespace mozilla {
namespace net { namespace net {
static uint64_t
FindTopOuterWindowID(nsPIDOMWindowOuter* aOuter)
{
nsCOMPtr<nsPIDOMWindowOuter> outer = aOuter;
while (nsCOMPtr<nsPIDOMWindowOuter> parent = outer->GetScriptableParentOrNull()) {
outer = parent;
}
return outer->WindowID();
}
LoadInfo::LoadInfo(nsIPrincipal* aLoadingPrincipal, LoadInfo::LoadInfo(nsIPrincipal* aLoadingPrincipal,
nsIPrincipal* aTriggeringPrincipal, nsIPrincipal* aTriggeringPrincipal,
nsINode* aLoadingContext, nsINode* aLoadingContext,
@ -51,6 +61,7 @@ LoadInfo::LoadInfo(nsIPrincipal* aLoadingPrincipal,
, mInnerWindowID(0) , mInnerWindowID(0)
, mOuterWindowID(0) , mOuterWindowID(0)
, mParentOuterWindowID(0) , mParentOuterWindowID(0)
, mTopOuterWindowID(0)
, mFrameOuterWindowID(0) , mFrameOuterWindowID(0)
, mEnforceSecurity(false) , mEnforceSecurity(false)
, mInitialSecurityCheckDone(false) , mInitialSecurityCheckDone(false)
@ -103,6 +114,7 @@ LoadInfo::LoadInfo(nsIPrincipal* aLoadingPrincipal,
mOuterWindowID = contextOuter->WindowID(); mOuterWindowID = contextOuter->WindowID();
nsCOMPtr<nsPIDOMWindowOuter> parent = contextOuter->GetScriptableParent(); nsCOMPtr<nsPIDOMWindowOuter> parent = contextOuter->GetScriptableParent();
mParentOuterWindowID = parent ? parent->WindowID() : mOuterWindowID; mParentOuterWindowID = parent ? parent->WindowID() : mOuterWindowID;
mTopOuterWindowID = FindTopOuterWindowID(contextOuter);
} }
mInnerWindowID = aLoadingContext->OwnerDoc()->InnerWindowID(); mInnerWindowID = aLoadingContext->OwnerDoc()->InnerWindowID();
@ -228,6 +240,7 @@ LoadInfo::LoadInfo(nsPIDOMWindowOuter* aOuterWindow,
, mInnerWindowID(0) , mInnerWindowID(0)
, mOuterWindowID(0) , mOuterWindowID(0)
, mParentOuterWindowID(0) , mParentOuterWindowID(0)
, mTopOuterWindowID(0)
, mFrameOuterWindowID(0) , mFrameOuterWindowID(0)
, mEnforceSecurity(false) , mEnforceSecurity(false)
, mInitialSecurityCheckDone(false) , mInitialSecurityCheckDone(false)
@ -258,6 +271,7 @@ LoadInfo::LoadInfo(nsPIDOMWindowOuter* aOuterWindow,
// with the hidden window. // with the hidden window.
nsCOMPtr<nsPIDOMWindowOuter> parent = aOuterWindow->GetScriptableParent(); nsCOMPtr<nsPIDOMWindowOuter> parent = aOuterWindow->GetScriptableParent();
mParentOuterWindowID = parent ? parent->WindowID() : 0; mParentOuterWindowID = parent ? parent->WindowID() : 0;
mTopOuterWindowID = FindTopOuterWindowID(aOuterWindow);
// get the docshell from the outerwindow, and then get the originattributes // get the docshell from the outerwindow, and then get the originattributes
nsCOMPtr<nsIDocShell> docShell = aOuterWindow->GetDocShell(); nsCOMPtr<nsIDocShell> docShell = aOuterWindow->GetDocShell();
@ -290,6 +304,7 @@ LoadInfo::LoadInfo(const LoadInfo& rhs)
, mInnerWindowID(rhs.mInnerWindowID) , mInnerWindowID(rhs.mInnerWindowID)
, mOuterWindowID(rhs.mOuterWindowID) , mOuterWindowID(rhs.mOuterWindowID)
, mParentOuterWindowID(rhs.mParentOuterWindowID) , mParentOuterWindowID(rhs.mParentOuterWindowID)
, mTopOuterWindowID(rhs.mTopOuterWindowID)
, mFrameOuterWindowID(rhs.mFrameOuterWindowID) , mFrameOuterWindowID(rhs.mFrameOuterWindowID)
, mEnforceSecurity(rhs.mEnforceSecurity) , mEnforceSecurity(rhs.mEnforceSecurity)
, mInitialSecurityCheckDone(rhs.mInitialSecurityCheckDone) , mInitialSecurityCheckDone(rhs.mInitialSecurityCheckDone)
@ -323,6 +338,7 @@ LoadInfo::LoadInfo(nsIPrincipal* aLoadingPrincipal,
uint64_t aInnerWindowID, uint64_t aInnerWindowID,
uint64_t aOuterWindowID, uint64_t aOuterWindowID,
uint64_t aParentOuterWindowID, uint64_t aParentOuterWindowID,
uint64_t aTopOuterWindowID,
uint64_t aFrameOuterWindowID, uint64_t aFrameOuterWindowID,
bool aEnforceSecurity, bool aEnforceSecurity,
bool aInitialSecurityCheckDone, bool aInitialSecurityCheckDone,
@ -351,6 +367,7 @@ LoadInfo::LoadInfo(nsIPrincipal* aLoadingPrincipal,
, mInnerWindowID(aInnerWindowID) , mInnerWindowID(aInnerWindowID)
, mOuterWindowID(aOuterWindowID) , mOuterWindowID(aOuterWindowID)
, mParentOuterWindowID(aParentOuterWindowID) , mParentOuterWindowID(aParentOuterWindowID)
, mTopOuterWindowID(aTopOuterWindowID)
, mFrameOuterWindowID(aFrameOuterWindowID) , mFrameOuterWindowID(aFrameOuterWindowID)
, mEnforceSecurity(aEnforceSecurity) , mEnforceSecurity(aEnforceSecurity)
, mInitialSecurityCheckDone(aInitialSecurityCheckDone) , mInitialSecurityCheckDone(aInitialSecurityCheckDone)
@ -724,6 +741,13 @@ LoadInfo::GetParentOuterWindowID(uint64_t* aResult)
return NS_OK; return NS_OK;
} }
NS_IMETHODIMP
LoadInfo::GetTopOuterWindowID(uint64_t* aResult)
{
*aResult = mTopOuterWindowID;
return NS_OK;
}
NS_IMETHODIMP NS_IMETHODIMP
LoadInfo::GetFrameOuterWindowID(uint64_t* aResult) LoadInfo::GetFrameOuterWindowID(uint64_t* aResult)
{ {

Просмотреть файл

@ -107,6 +107,7 @@ private:
uint64_t aInnerWindowID, uint64_t aInnerWindowID,
uint64_t aOuterWindowID, uint64_t aOuterWindowID,
uint64_t aParentOuterWindowID, uint64_t aParentOuterWindowID,
uint64_t aTopOuterWindowID,
uint64_t aFrameOuterWindowID, uint64_t aFrameOuterWindowID,
bool aEnforceSecurity, bool aEnforceSecurity,
bool aInitialSecurityCheckDone, bool aInitialSecurityCheckDone,
@ -159,6 +160,7 @@ private:
uint64_t mInnerWindowID; uint64_t mInnerWindowID;
uint64_t mOuterWindowID; uint64_t mOuterWindowID;
uint64_t mParentOuterWindowID; uint64_t mParentOuterWindowID;
uint64_t mTopOuterWindowID;
uint64_t mFrameOuterWindowID; uint64_t mFrameOuterWindowID;
bool mEnforceSecurity; bool mEnforceSecurity;
bool mInitialSecurityCheckDone; bool mInitialSecurityCheckDone;

Просмотреть файл

@ -507,15 +507,17 @@ interface nsILoadInfo : nsISupports
/** /**
* These are the window IDs of the window in which the element being * These are the window IDs of the window in which the element being
* loaded lives. parentOuterWindowID is the window ID of this window's * loaded lives. parentOuterWindowID is the window ID of this window's
* parent. * parent. topOuterWindowID is the ID of the top-level window of the same
* docShell type.
* *
* Note that these window IDs can be 0 if the window is not * Note that these window IDs can be 0 if the window is not
* available. parentOuterWindowID will be the same as outerWindowID if the * available. parentOuterWindowID and topOuterWindowID will be the same as
* window has no parent. * outerWindowID if the window has no parent.
*/ */
[infallible] readonly attribute unsigned long long innerWindowID; [infallible] readonly attribute unsigned long long innerWindowID;
[infallible] readonly attribute unsigned long long outerWindowID; [infallible] readonly attribute unsigned long long outerWindowID;
[infallible] readonly attribute unsigned long long parentOuterWindowID; [infallible] readonly attribute unsigned long long parentOuterWindowID;
[infallible] readonly attribute unsigned long long topOuterWindowID;
/** /**
* Only when the element being loaded is <frame src="foo.html"> * Only when the element being loaded is <frame src="foo.html">

Просмотреть файл

@ -51,6 +51,7 @@ struct LoadInfoArgs
uint64_t innerWindowID; uint64_t innerWindowID;
uint64_t outerWindowID; uint64_t outerWindowID;
uint64_t parentOuterWindowID; uint64_t parentOuterWindowID;
uint64_t topOuterWindowID;
uint64_t frameOuterWindowID; uint64_t frameOuterWindowID;
bool enforceSecurity; bool enforceSecurity;
bool initialSecurityCheckDone; bool initialSecurityCheckDone;