Bug 1419144 - Part 18: Move AsInner() and AsOuter() off of nsPIDOMWindow<T>, r=smaug

MozReview-Commit-ID: IA29zmacrJ4
This commit is contained in:
Nika Layzell 2017-11-17 18:33:21 -05:00
Родитель cc1a61fcdc
Коммит b1a42230f1
5 изменённых файлов: 56 добавлений и 73 удалений

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

@ -319,10 +319,6 @@ nsPIDOMWindow<T>::nsPIDOMWindow(nsPIDOMWindowOuter *aOuterWindow)
mNumOfIndexedDBDatabases(0), mNumOfIndexedDBDatabases(0),
mNumOfOpenWebSockets(0) mNumOfOpenWebSockets(0)
{ {
if (aOuterWindow) {
mTimeoutManager =
MakeUnique<mozilla::dom::TimeoutManager>(*nsGlobalWindowInner::Cast(AsInner()));
}
} }
template<class T> template<class T>

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

@ -650,6 +650,9 @@ nsGlobalWindowInner::nsGlobalWindowInner(nsGlobalWindowOuter *aOuterWindow)
// window list of inners. // window list of inners.
PR_INSERT_AFTER(this, aOuterWindow); PR_INSERT_AFTER(this, aOuterWindow);
mTimeoutManager =
MakeUnique<mozilla::dom::TimeoutManager>(*nsGlobalWindowInner::Cast(AsInner()));
mObserver = new nsGlobalWindowObserver(this); mObserver = new nsGlobalWindowObserver(this);
if (mObserver) { if (mObserver) {
nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService(); nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();

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

@ -291,7 +291,7 @@ public:
// nsWrapperCache // nsWrapperCache
virtual JSObject *WrapObject(JSContext *cx, JS::Handle<JSObject*> aGivenProto) override virtual JSObject *WrapObject(JSContext *cx, JS::Handle<JSObject*> aGivenProto) override
{ {
return IsInnerWindow() || AsOuter()->EnsureInnerWindow() ? GetWrapper() : nullptr; return GetWrapper();
} }
// nsIGlobalJSObjectHolder // nsIGlobalJSObjectHolder

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

@ -127,11 +127,6 @@ template<class T>
class nsPIDOMWindow : public T class nsPIDOMWindow : public T
{ {
public: public:
nsPIDOMWindowInner* AsInner();
const nsPIDOMWindowInner* AsInner() const;
nsPIDOMWindowOuter* AsOuter();
const nsPIDOMWindowOuter* AsOuter() const;
virtual nsPIDOMWindowOuter* GetPrivateRoot() = 0; virtual nsPIDOMWindowOuter* GetPrivateRoot() = 0;
virtual mozilla::dom::CustomElementRegistry* CustomElements() = 0; virtual mozilla::dom::CustomElementRegistry* CustomElements() = 0;
// Outer windows only. // Outer windows only.
@ -223,10 +218,6 @@ protected:
void MaybeCreateDoc(); void MaybeCreateDoc();
public: 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 // Set the window up with an about:blank document with the current subject
// principal. // principal.
// Outer windows only. // Outer windows only.
@ -255,13 +246,6 @@ public:
// the window was frozen. // the window was frozen.
virtual nsresult FireDelayedDOMEvents() = 0; virtual nsresult FireDelayedDOMEvents() = 0;
nsPIDOMWindowOuter* GetOuterWindow() const
{
return mIsInnerWindow
? mOuterWindow.get()
: const_cast<nsPIDOMWindowOuter*>(AsOuter());
}
bool IsInnerWindow() const bool IsInnerWindow() const
{ {
return mIsInnerWindow; return mIsInnerWindow;
@ -763,6 +747,17 @@ class nsPIDOMWindowInner : public nsPIDOMWindow<mozIDOMWindow>
public: public:
NS_DECLARE_STATIC_IID_ACCESSOR(NS_PIDOMWINDOWINNER_IID) 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) { static nsPIDOMWindowInner* From(mozIDOMWindow* aFrom) {
return static_cast<nsPIDOMWindowInner*>(aFrom); return static_cast<nsPIDOMWindowInner*>(aFrom);
} }
@ -779,6 +774,10 @@ public:
// Returns true if this window is the same as mTopInnerWindow // Returns true if this window is the same as mTopInnerWindow
inline bool IsTopInnerWindow() const; 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); bool AddAudioContext(mozilla::dom::AudioContext* aAudioContext);
void RemoveAudioContext(mozilla::dom::AudioContext* aAudioContext); void RemoveAudioContext(mozilla::dom::AudioContext* aAudioContext);
void MuteAudioContexts(); void MuteAudioContexts();
@ -958,6 +957,17 @@ protected:
public: public:
NS_DECLARE_STATIC_IID_ACCESSOR(NS_PIDOMWINDOWOUTER_IID) NS_DECLARE_STATIC_IID_ACCESSOR(NS_PIDOMWINDOWOUTER_IID)
nsPIDOMWindowOuter* AsOuter() {
return this;
}
const nsPIDOMWindowOuter* AsOuter() const {
return this;
}
nsPIDOMWindowOuter* GetOuterWindow() const {
return const_cast<nsPIDOMWindowOuter*>(this);
}
static nsPIDOMWindowOuter* From(mozIDOMWindowProxy* aFrom) { static nsPIDOMWindowOuter* From(mozIDOMWindowProxy* aFrom) {
return static_cast<nsPIDOMWindowOuter*>(aFrom); return static_cast<nsPIDOMWindowOuter*>(aFrom);
} }
@ -966,6 +976,10 @@ public:
// Otherwise (argument null or not an inner or not current) return null. // Otherwise (argument null or not an inner or not current) return null.
static nsPIDOMWindowOuter* GetFromCurrentInner(nsPIDOMWindowInner* aInner); static nsPIDOMWindowOuter* GetFromCurrentInner(nsPIDOMWindowInner* aInner);
// Check whether a document is currently loading
inline bool IsLoading() const;
inline bool IsHandlingResizeEvent() const;
nsPIDOMWindowInner* GetCurrentInnerWindow() const nsPIDOMWindowInner* GetCurrentInnerWindow() const
{ {
return mInnerWindow; return mInnerWindow;

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

@ -4,54 +4,23 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this * 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/. */ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
template<class T>
nsPIDOMWindowInner*
nsPIDOMWindow<T>::AsInner()
{
MOZ_ASSERT(IsInnerWindow());
return reinterpret_cast<nsPIDOMWindowInner*>(this);
}
template<class T>
const nsPIDOMWindowInner*
nsPIDOMWindow<T>::AsInner() const
{
MOZ_ASSERT(IsInnerWindow());
return reinterpret_cast<const nsPIDOMWindowInner*>(this);
}
template<class T>
nsPIDOMWindowOuter*
nsPIDOMWindow<T>::AsOuter()
{
MOZ_ASSERT(IsOuterWindow());
return reinterpret_cast<nsPIDOMWindowOuter*>(this);
}
template<class T>
const nsPIDOMWindowOuter*
nsPIDOMWindow<T>::AsOuter() const
{
MOZ_ASSERT(IsOuterWindow());
return reinterpret_cast<const nsPIDOMWindowOuter*>(this);
}
template <class T>
bool bool
nsPIDOMWindow<T>::IsLoading() const nsPIDOMWindowOuter::IsLoading() const
{ {
if (IsOuterWindow()) { auto* win = GetCurrentInnerWindow();
auto* win = AsOuter()->GetCurrentInnerWindow();
if (!win) { if (!win) {
NS_ERROR("No current inner window available!"); NS_ERROR("No current inner window available!");
return false; return false;
}
return win->IsLoading();
} }
return win->IsLoading();
}
bool
nsPIDOMWindowInner::IsLoading() const
{
if (!mOuterWindow) { if (!mOuterWindow) {
NS_ERROR("IsLoading() called on orphan inner window!"); NS_ERROR("IsLoading() called on orphan inner window!");
@ -61,22 +30,23 @@ nsPIDOMWindow<T>::IsLoading() const
return !mIsDocumentLoaded; return !mIsDocumentLoaded;
} }
template <class T>
bool bool
nsPIDOMWindow<T>::IsHandlingResizeEvent() const nsPIDOMWindowOuter::IsHandlingResizeEvent() const
{ {
if (IsOuterWindow()) { auto* win = GetCurrentInnerWindow();
auto* win = AsOuter()->GetCurrentInnerWindow();
if (!win) { if (!win) {
NS_ERROR("No current inner window available!"); NS_ERROR("No current inner window available!");
return false; return false;
}
return win->IsHandlingResizeEvent();
} }
return win->IsHandlingResizeEvent();
}
bool
nsPIDOMWindowInner::IsHandlingResizeEvent() const
{
if (!mOuterWindow) { if (!mOuterWindow) {
NS_ERROR("IsHandlingResizeEvent() called on orphan inner window!"); NS_ERROR("IsHandlingResizeEvent() called on orphan inner window!");