Bug 1265072 part 1. Add GetWindowIfCurrent and GetDocumentIfCurrent helpers to DOMEventTargetHelper. r=smaug

This commit is contained in:
Boris Zbarsky 2016-04-20 18:04:29 -04:00
Родитель f47810cb12
Коммит 00db6e6eed
2 изменённых файлов: 29 добавлений и 1 удалений

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

@ -160,6 +160,27 @@ DOMEventTargetHelper::DisconnectFromOwner()
}
}
nsPIDOMWindowInner*
DOMEventTargetHelper::GetWindowIfCurrent() const
{
if (NS_FAILED(CheckInnerWindowCorrectness())) {
return nullptr;
}
return GetOwner();
}
nsIDocument*
DOMEventTargetHelper::GetDocumentIfCurrent() const
{
nsPIDOMWindowInner* win = GetWindowIfCurrent();
if (!win) {
return nullptr;
}
return win->GetDoc();
}
NS_IMETHODIMP
DOMEventTargetHelper::RemoveEventListener(const nsAString& aType,
nsIDOMEventListener* aListener,

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

@ -20,6 +20,7 @@
#include "mozilla/dom/EventTarget.h"
struct JSCompartment;
class nsIDocument;
namespace mozilla {
@ -126,7 +127,7 @@ public:
return nsPIDOMWindowOuter::GetFromCurrentInner(GetOwner());
}
nsresult CheckInnerWindowCorrectness()
nsresult CheckInnerWindowCorrectness() const
{
NS_ENSURE_STATE(!mHasOrHasHadOwnerWindow || mOwnerWindow);
if (mOwnerWindow && !mOwnerWindow->IsCurrentInnerWindow()) {
@ -136,6 +137,12 @@ public:
}
nsPIDOMWindowInner* GetOwner() const { return mOwnerWindow; }
// Like GetOwner, but only returns non-null if the window being returned is
// current (in the "current document" sense of the HTML spec).
nsPIDOMWindowInner* GetWindowIfCurrent() const;
// Returns the document associated with this event target, if that document is
// the current document of its browsing context. Will return null otherwise.
nsIDocument* GetDocumentIfCurrent() const;
void BindToOwner(nsIGlobalObject* aOwner);
void BindToOwner(nsPIDOMWindowInner* aOwner);
void BindToOwner(DOMEventTargetHelper* aOther);