Commit e61cc054 authored by Gijs Kruitbosch's avatar Gijs Kruitbosch
Browse files

Bug 1493634 - make docshell responsible for outer window IDs, r=bzbarsky

Differential Revision: https://phabricator.services.mozilla.com/D7702

--HG--
extra : moz-landing-system : lando
parent 3ef88382
......@@ -313,6 +313,7 @@ DecreasePrivateDocShellCount()
nsDocShell::nsDocShell()
: nsDocLoader()
, mContentWindowID(NextWindowID())
, mForcedCharset(nullptr)
, mParentCharset(nullptr)
, mTreeOwner(nullptr)
......@@ -1286,6 +1287,13 @@ nsDocShell::GetContentViewer(nsIContentViewer** aContentViewer)
return NS_OK;
}
NS_IMETHODIMP
nsDocShell::GetOuterWindowID(uint64_t *aWindowID)
{
*aWindowID = mContentWindowID;
return NS_OK;
}
NS_IMETHODIMP
nsDocShell::SetChromeEventHandler(EventTarget* aChromeEventHandler)
{
......@@ -12726,11 +12734,9 @@ nsDocShell::EnsureScriptEnvironment()
// If our window is modal and we're not opened as chrome, make
// this window a modal content window.
mScriptGlobal = NS_NewScriptGlobalObject(mItemType == typeChrome);
mScriptGlobal = nsGlobalWindowOuter::Create(this, mItemType == typeChrome);
MOZ_ASSERT(mScriptGlobal);
mScriptGlobal->SetDocShell(this);
// Ensure the script object is set up to run script.
return mScriptGlobal->EnsureScriptEnvironment();
}
......
......@@ -936,6 +936,7 @@ private: // data members
nsCOMPtr<nsIMutableArray> mRefreshURIList;
nsCOMPtr<nsIMutableArray> mSavedRefreshURIList;
nsCOMPtr<nsIDOMStorageManager> mSessionStorageManager;
uint64_t mContentWindowID;
nsCOMPtr<nsIContentViewer> mContentViewer;
nsCOMPtr<nsIWidget> mParentWidget;
RefPtr<mozilla::dom::ChildSHistory> mSessionHistory;
......
......@@ -265,6 +265,11 @@ interface nsIDocShell : nsIDocShellTreeItem
*/
readonly attribute nsIContentViewer contentViewer;
/**
* Get the id of the outer window that is or will be in this docshell.
*/
[infallible] readonly attribute unsigned long long outerWindowID;
/**
* This attribute allows chrome to tie in to handle DOM events that may
* be of interest to chrome.
......
......@@ -812,8 +812,8 @@ NewOuterWindowProxy(JSContext *cx, JS::Handle<JSObject*> global, bool isChrome)
//*** nsGlobalWindowOuter: Object Management
//*****************************************************************************
nsGlobalWindowOuter::nsGlobalWindowOuter()
: nsPIDOMWindowOuter(),
nsGlobalWindowOuter::nsGlobalWindowOuter(uint64_t aWindowID)
: nsPIDOMWindowOuter(aWindowID),
mIdleFuzzFactor(0),
mIdleCallbackIndex(-1),
mCurrentlyIdle(false),
......@@ -7661,12 +7661,14 @@ nsPIDOMWindowOuter::TabGroup()
}
/* static */ already_AddRefed<nsGlobalWindowOuter>
nsGlobalWindowOuter::Create(bool aIsChrome)
nsGlobalWindowOuter::Create(nsIDocShell* aDocShell, bool aIsChrome)
{
RefPtr<nsGlobalWindowOuter> window = new nsGlobalWindowOuter();
uint64_t outerWindowID = aDocShell->GetOuterWindowID();
RefPtr<nsGlobalWindowOuter> window = new nsGlobalWindowOuter(outerWindowID);
if (aIsChrome) {
window->mIsChrome = true;
}
window->SetDocShell(aDocShell);
window->InitWasOffline();
return window.forget();
......@@ -7715,15 +7717,7 @@ nsPIDOMWindowOuter::GetDocGroup() const
return nullptr;
}
// XXX: Can we define this in a header instead of here?
namespace mozilla {
namespace dom {
extern uint64_t
NextWindowID();
} // namespace dom
} // namespace mozilla
nsPIDOMWindowOuter::nsPIDOMWindowOuter()
nsPIDOMWindowOuter::nsPIDOMWindowOuter(uint64_t aWindowID)
: mFrameElement(nullptr)
, mDocShell(nullptr)
, mModalStateDepth(0)
......@@ -7738,9 +7732,7 @@ nsPIDOMWindowOuter::nsPIDOMWindowOuter()
, mDesktopModeViewport(false)
, mIsRootOuterWindow(false)
, mInnerWindow(nullptr)
,
// Make sure no actual window ends up with mWindowID == 0
mWindowID(NextWindowID())
, mWindowID(aWindowID)
, mMarkedCCGeneration(0)
, mServiceWorkersTestingEnabled(false)
, mLargeAllocStatus(LargeAllocStatus::NONE)
......
......@@ -219,7 +219,7 @@ public:
return (nsGlobalWindowOuter *)(mozilla::dom::EventTarget *)supports;
}
static already_AddRefed<nsGlobalWindowOuter> Create(bool aIsChrome);
static already_AddRefed<nsGlobalWindowOuter> Create(nsIDocShell* aDocShell, bool aIsChrome);
// public methods
nsPIDOMWindowOuter* GetPrivateParent();
......@@ -320,7 +320,6 @@ public:
// Outer windows only.
bool WouldReuseInnerWindow(nsIDocument* aNewDocument);
void SetDocShell(nsIDocShell* aDocShell);
void DetachFromDocShell();
virtual nsresult SetNewDocument(nsIDocument *aDocument,
......@@ -581,7 +580,6 @@ public:
nsresult GetPrompter(nsIPrompt** aPrompt) override;
protected:
explicit nsGlobalWindowOuter();
nsPIDOMWindowOuter* GetOpenerWindowOuter();
// Initializes the mWasOffline member variable
void InitWasOffline();
......@@ -831,6 +829,8 @@ protected:
nsPIDOMWindowOuter** _retval) override;
private:
explicit nsGlobalWindowOuter(uint64_t aWindowID);
/**
* @param aUrl the URL we intend to load into the window. If aNavigate is
* true, we'll actually load this URL into the window. Otherwise,
......@@ -1047,6 +1047,8 @@ private:
SecureContextFlags aFlags =
SecureContextFlags::eDefault);
void SetDocShell(nsIDocShell* aDocShell);
// nsPIDOMWindow{Inner,Outer} should be able to see these helper methods.
friend class nsPIDOMWindowInner;
friend class nsPIDOMWindowOuter;
......@@ -1258,11 +1260,4 @@ nsGlobalWindowOuter::MaybeClearInnerWindow(nsGlobalWindowInner* aExpectedInner)
}
}
/* factory function */
inline already_AddRefed<nsGlobalWindowOuter>
NS_NewScriptGlobalObject(bool aIsChrome)
{
return nsGlobalWindowOuter::Create(aIsChrome);
}
#endif /* nsGlobalWindowOuter_h___ */
......@@ -716,7 +716,7 @@ NS_DEFINE_STATIC_IID_ACCESSOR(nsPIDOMWindowInner, NS_PIDOMWINDOWINNER_IID)
class nsPIDOMWindowOuter : public mozIDOMWindowProxy
{
protected:
explicit nsPIDOMWindowOuter();
explicit nsPIDOMWindowOuter(uint64_t aWindowID);
~nsPIDOMWindowOuter();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment