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),
mNumOfOpenWebSockets(0)
{
if (aOuterWindow) {
mTimeoutManager =
MakeUnique<mozilla::dom::TimeoutManager>(*nsGlobalWindowInner::Cast(AsInner()));
}
}
template<class T>

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

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

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

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

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

@ -127,11 +127,6 @@ template<class T>
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<nsPIDOMWindowOuter*>(AsOuter());
}
bool IsInnerWindow() const
{
return mIsInnerWindow;
@ -763,6 +747,17 @@ class nsPIDOMWindowInner : public nsPIDOMWindow<mozIDOMWindow>
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<nsPIDOMWindowInner*>(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<nsPIDOMWindowOuter*>(this);
}
static nsPIDOMWindowOuter* From(mozIDOMWindowProxy* aFrom) {
return static_cast<nsPIDOMWindowOuter*>(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;

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

@ -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<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
nsPIDOMWindow<T>::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<T>::IsLoading() const
return !mIsDocumentLoaded;
}
template <class T>
bool
nsPIDOMWindow<T>::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!");