From b1a42230f1c1274d497d6d9a5cbc04b060e19fbb Mon Sep 17 00:00:00 2001 From: Nika Layzell Date: Fri, 17 Nov 2017 18:33:21 -0500 Subject: [PATCH] Bug 1419144 - Part 18: Move AsInner() and AsOuter() off of nsPIDOMWindow, r=smaug MozReview-Commit-ID: IA29zmacrJ4 --- dom/base/nsGlobalWindow.cpp | 4 -- dom/base/nsGlobalWindowInner.cpp | 3 ++ dom/base/nsGlobalWindowInner.h | 2 +- dom/base/nsPIDOMWindow.h | 46 +++++++++++++------- dom/base/nsPIDOMWindowInlines.h | 74 ++++++++++---------------------- 5 files changed, 56 insertions(+), 73 deletions(-) diff --git a/dom/base/nsGlobalWindow.cpp b/dom/base/nsGlobalWindow.cpp index 8944e067abd1..2a11eb450a36 100644 --- a/dom/base/nsGlobalWindow.cpp +++ b/dom/base/nsGlobalWindow.cpp @@ -319,10 +319,6 @@ nsPIDOMWindow::nsPIDOMWindow(nsPIDOMWindowOuter *aOuterWindow) mNumOfIndexedDBDatabases(0), mNumOfOpenWebSockets(0) { - if (aOuterWindow) { - mTimeoutManager = - MakeUnique(*nsGlobalWindowInner::Cast(AsInner())); - } } template diff --git a/dom/base/nsGlobalWindowInner.cpp b/dom/base/nsGlobalWindowInner.cpp index 9a762043e976..dae49038e671 100644 --- a/dom/base/nsGlobalWindowInner.cpp +++ b/dom/base/nsGlobalWindowInner.cpp @@ -650,6 +650,9 @@ nsGlobalWindowInner::nsGlobalWindowInner(nsGlobalWindowOuter *aOuterWindow) // window list of inners. PR_INSERT_AFTER(this, aOuterWindow); + mTimeoutManager = + MakeUnique(*nsGlobalWindowInner::Cast(AsInner())); + mObserver = new nsGlobalWindowObserver(this); if (mObserver) { nsCOMPtr os = mozilla::services::GetObserverService(); diff --git a/dom/base/nsGlobalWindowInner.h b/dom/base/nsGlobalWindowInner.h index 39e89261e2d1..d2085ec4fa57 100644 --- a/dom/base/nsGlobalWindowInner.h +++ b/dom/base/nsGlobalWindowInner.h @@ -291,7 +291,7 @@ public: // nsWrapperCache virtual JSObject *WrapObject(JSContext *cx, JS::Handle aGivenProto) override { - return IsInnerWindow() || AsOuter()->EnsureInnerWindow() ? GetWrapper() : nullptr; + return GetWrapper(); } // nsIGlobalJSObjectHolder diff --git a/dom/base/nsPIDOMWindow.h b/dom/base/nsPIDOMWindow.h index b2d944a7e6a5..7371b8488d34 100644 --- a/dom/base/nsPIDOMWindow.h +++ b/dom/base/nsPIDOMWindow.h @@ -127,11 +127,6 @@ template class nsPIDOMWindow : public T { public: - nsPIDOMWindowInner* AsInner(); - const nsPIDOMWindowInner* AsInner() const; - nsPIDOMWindowOuter* AsOuter(); - const nsPIDOMWindowOuter* AsOuter() const; - virtual nsPIDOMWindowOuter* GetPrivateRoot() = 0; virtual mozilla::dom::CustomElementRegistry* CustomElements() = 0; // Outer windows only. @@ -223,10 +218,6 @@ protected: void MaybeCreateDoc(); public: - // Check whether a document is currently loading - inline bool IsLoading() const; - inline bool IsHandlingResizeEvent() const; - // Set the window up with an about:blank document with the current subject // principal. // Outer windows only. @@ -255,13 +246,6 @@ public: // the window was frozen. virtual nsresult FireDelayedDOMEvents() = 0; - nsPIDOMWindowOuter* GetOuterWindow() const - { - return mIsInnerWindow - ? mOuterWindow.get() - : const_cast(AsOuter()); - } - bool IsInnerWindow() const { return mIsInnerWindow; @@ -763,6 +747,17 @@ class nsPIDOMWindowInner : public nsPIDOMWindow public: NS_DECLARE_STATIC_IID_ACCESSOR(NS_PIDOMWINDOWINNER_IID) + nsPIDOMWindowInner* AsInner() { + return this; + } + const nsPIDOMWindowInner* AsInner() const { + return this; + } + + nsPIDOMWindowOuter* GetOuterWindow() const { + return mOuterWindow; + } + static nsPIDOMWindowInner* From(mozIDOMWindow* aFrom) { return static_cast(aFrom); } @@ -779,6 +774,10 @@ public: // Returns true if this window is the same as mTopInnerWindow inline bool IsTopInnerWindow() const; + // Check whether a document is currently loading + inline bool IsLoading() const; + inline bool IsHandlingResizeEvent() const; + bool AddAudioContext(mozilla::dom::AudioContext* aAudioContext); void RemoveAudioContext(mozilla::dom::AudioContext* aAudioContext); void MuteAudioContexts(); @@ -958,6 +957,17 @@ protected: public: NS_DECLARE_STATIC_IID_ACCESSOR(NS_PIDOMWINDOWOUTER_IID) + nsPIDOMWindowOuter* AsOuter() { + return this; + } + const nsPIDOMWindowOuter* AsOuter() const { + return this; + } + + nsPIDOMWindowOuter* GetOuterWindow() const { + return const_cast(this); + } + static nsPIDOMWindowOuter* From(mozIDOMWindowProxy* aFrom) { return static_cast(aFrom); } @@ -966,6 +976,10 @@ public: // Otherwise (argument null or not an inner or not current) return null. static nsPIDOMWindowOuter* GetFromCurrentInner(nsPIDOMWindowInner* aInner); + // Check whether a document is currently loading + inline bool IsLoading() const; + inline bool IsHandlingResizeEvent() const; + nsPIDOMWindowInner* GetCurrentInnerWindow() const { return mInnerWindow; diff --git a/dom/base/nsPIDOMWindowInlines.h b/dom/base/nsPIDOMWindowInlines.h index 2327969908f9..aef157c262e8 100644 --- a/dom/base/nsPIDOMWindowInlines.h +++ b/dom/base/nsPIDOMWindowInlines.h @@ -4,54 +4,23 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -template -nsPIDOMWindowInner* -nsPIDOMWindow::AsInner() -{ - MOZ_ASSERT(IsInnerWindow()); - return reinterpret_cast(this); -} - -template -const nsPIDOMWindowInner* -nsPIDOMWindow::AsInner() const -{ - MOZ_ASSERT(IsInnerWindow()); - return reinterpret_cast(this); -} - -template -nsPIDOMWindowOuter* -nsPIDOMWindow::AsOuter() -{ - MOZ_ASSERT(IsOuterWindow()); - return reinterpret_cast(this); -} - -template -const nsPIDOMWindowOuter* -nsPIDOMWindow::AsOuter() const -{ - MOZ_ASSERT(IsOuterWindow()); - return reinterpret_cast(this); -} - -template bool -nsPIDOMWindow::IsLoading() const +nsPIDOMWindowOuter::IsLoading() const { - if (IsOuterWindow()) { - auto* win = AsOuter()->GetCurrentInnerWindow(); + auto* win = GetCurrentInnerWindow(); - if (!win) { - NS_ERROR("No current inner window available!"); + if (!win) { + NS_ERROR("No current inner window available!"); - return false; - } - - return win->IsLoading(); + return false; } + return win->IsLoading(); +} + +bool +nsPIDOMWindowInner::IsLoading() const +{ if (!mOuterWindow) { NS_ERROR("IsLoading() called on orphan inner window!"); @@ -61,22 +30,23 @@ nsPIDOMWindow::IsLoading() const return !mIsDocumentLoaded; } -template bool -nsPIDOMWindow::IsHandlingResizeEvent() const +nsPIDOMWindowOuter::IsHandlingResizeEvent() const { - if (IsOuterWindow()) { - auto* win = AsOuter()->GetCurrentInnerWindow(); + auto* win = GetCurrentInnerWindow(); - if (!win) { - NS_ERROR("No current inner window available!"); + if (!win) { + NS_ERROR("No current inner window available!"); - return false; - } - - return win->IsHandlingResizeEvent(); + return false; } + return win->IsHandlingResizeEvent(); +} + +bool +nsPIDOMWindowInner::IsHandlingResizeEvent() const +{ if (!mOuterWindow) { NS_ERROR("IsHandlingResizeEvent() called on orphan inner window!");