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->GetOuterWindowID(),
aLoadInfo->GetParentOuterWindowID(),
aLoadInfo->GetTopOuterWindowID(),
aLoadInfo->GetFrameOuterWindowID(),
aLoadInfo->GetEnforceSecurity(),
aLoadInfo->GetInitialSecurityCheckDone(),
@ -482,6 +483,7 @@ LoadInfoArgsToLoadInfo(const OptionalLoadInfoArgs& aOptionalLoadInfoArgs,
loadInfoArgs.innerWindowID(),
loadInfoArgs.outerWindowID(),
loadInfoArgs.parentOuterWindowID(),
loadInfoArgs.topOuterWindowID(),
loadInfoArgs.frameOuterWindowID(),
loadInfoArgs.enforceSecurity(),
loadInfoArgs.initialSecurityCheckDone(),

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

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

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

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

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

@ -507,15 +507,17 @@ interface nsILoadInfo : nsISupports
/**
* These are the window IDs of the window in which the element being
* 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
* available. parentOuterWindowID will be the same as outerWindowID if the
* window has no parent.
* available. parentOuterWindowID and topOuterWindowID will be the same as
* outerWindowID if the window has no parent.
*/
[infallible] readonly attribute unsigned long long innerWindowID;
[infallible] readonly attribute unsigned long long outerWindowID;
[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">

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

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