Bug 1163898 part 1. Give DOMEventTargetHelper a sane accessor for getting its nsIGlobalObject. r=smaug

This commit is contained in:
Boris Zbarsky 2015-05-12 15:56:39 -04:00
parent 46b3f4a779
commit 068f758b05
12 changed files with 55 additions and 22 deletions

View File

@ -408,7 +408,7 @@ public:
bool aUseCapture,
const mozilla::dom::Nullable<bool>& aWantsUntrusted,
mozilla::ErrorResult& aRv) override;
virtual nsIDOMWindow* GetOwnerGlobal() override
virtual nsIDOMWindow* GetOwnerGlobalForBindings() override
{
if (IsOuterWindow()) {
return this;
@ -417,6 +417,15 @@ public:
return GetOuterFromCurrentInner(this);
}
virtual nsIGlobalObject* GetOwnerGlobal() const override
{
if (IsOuterWindow()) {
return GetCurrentInnerWindowInternal();
}
return const_cast<nsGlobalWindow*>(this);
}
// nsPIDOMWindow
virtual nsPIDOMWindow* GetPrivateRoot() override;

View File

@ -1296,13 +1296,20 @@ nsINode::GetContextForEventHandlers(nsresult* aRv)
}
nsIDOMWindow*
nsINode::GetOwnerGlobal()
nsINode::GetOwnerGlobalForBindings()
{
bool dummy;
return nsPIDOMWindow::GetOuterFromCurrentInner(
static_cast<nsGlobalWindow*>(OwnerDoc()->GetScriptHandlingObject(dummy)));
}
nsIGlobalObject*
nsINode::GetOwnerGlobal() const
{
bool dummy;
return OwnerDoc()->GetScriptHandlingObject(dummy);
}
bool
nsINode::UnoptimizableCCNode() const
{

View File

@ -988,7 +988,8 @@ public:
const mozilla::dom::Nullable<bool>& aWantsUntrusted,
mozilla::ErrorResult& aRv) override;
using nsIDOMEventTarget::AddSystemEventListener;
virtual nsIDOMWindow* GetOwnerGlobal() override;
virtual nsIDOMWindow* GetOwnerGlobalForBindings() override;
virtual nsIGlobalObject* GetOwnerGlobal() const override;
/**
* Adds a mutation observer to be notified when this node, or any of its

View File

@ -38,7 +38,6 @@ public:
virtual void SetParentTarget(mozilla::dom::EventTarget* aTarget) = 0;
virtual mozilla::dom::EventTarget* GetParentTarget() = 0;
virtual nsIDOMWindow* GetOwnerGlobal() override = 0;
};
NS_DEFINE_STATIC_IID_ACCESSOR(nsPIWindowRoot, NS_IWINDOWROOT_IID)

View File

@ -188,11 +188,20 @@ nsWindowRoot::PostHandleEvent(EventChainPostVisitor& aVisitor)
}
nsIDOMWindow*
nsWindowRoot::GetOwnerGlobal()
nsWindowRoot::GetOwnerGlobalForBindings()
{
return GetWindow();
}
nsIGlobalObject*
nsWindowRoot::GetOwnerGlobal() const
{
nsCOMPtr<nsIGlobalObject> global =
do_QueryInterface(mWindow->GetCurrentInnerWindow());
// We're still holding a ref to it, so returning the raw pointer is ok...
return global;
}
nsPIDOMWindow*
nsWindowRoot::GetWindow()
{

View File

@ -59,7 +59,8 @@ public:
mParent = aTarget;
}
virtual mozilla::dom::EventTarget* GetParentTarget() override { return mParent; }
virtual nsIDOMWindow* GetOwnerGlobal() override;
virtual nsIDOMWindow* GetOwnerGlobalForBindings() override;
virtual nsIGlobalObject* GetOwnerGlobal() const override;
nsIGlobalObject* GetParentObject();

View File

@ -121,7 +121,7 @@ public:
JSContext* aCx,
JS::Value* aValue);
using dom::EventTarget::GetEventHandler;
virtual nsIDOMWindow* GetOwnerGlobal() override
virtual nsIDOMWindow* GetOwnerGlobalForBindings() override
{
return nsPIDOMWindow::GetOuterFromCurrentInner(GetOwner());
}
@ -140,7 +140,12 @@ public:
void BindToOwner(nsPIDOMWindow* aOwner);
void BindToOwner(DOMEventTargetHelper* aOther);
virtual void DisconnectFromOwner();
nsIGlobalObject* GetParentObject() const {
nsIGlobalObject* GetParentObject() const
{
return GetOwnerGlobal();
}
virtual nsIGlobalObject* GetOwnerGlobal() const override
{
nsCOMPtr<nsIGlobalObject> parentObject = do_QueryReferent(mParentObject);
return parentObject;
}

View File

@ -12,6 +12,7 @@
#include "nsIAtom.h"
class nsIDOMWindow;
class nsIGlobalObject;
namespace mozilla {
@ -27,8 +28,8 @@ template <class T> struct Nullable;
// IID for the dom::EventTarget interface
#define NS_EVENTTARGET_IID \
{ 0xce3817d0, 0x177b, 0x402f, \
{ 0xae, 0x75, 0xf8, 0x4e, 0xbe, 0x5a, 0x07, 0xc3 } }
{ 0x605158a9, 0xe229, 0x45b1, \
{ 0xbc, 0x12, 0x02, 0x9f, 0xa3, 0xa9, 0x3f, 0xcb } }
class EventTarget : public nsIDOMEventTarget,
public nsWrapperCache
@ -69,7 +70,12 @@ public:
// Returns an outer window that corresponds to the inner window this event
// target is associated with. Will return null if the inner window is not the
// current inner or if there is no window around at all.
virtual nsIDOMWindow* GetOwnerGlobal() = 0;
virtual nsIDOMWindow* GetOwnerGlobalForBindings() = 0;
// The global object this event target is associated with, if any.
// This may be an inner window or some other global object. This
// will never be an outer window.
virtual nsIGlobalObject* GetOwnerGlobal() const = 0;
/**
* Get the event listener manager, creating it if it does not already exist.

View File

@ -136,21 +136,16 @@ Touch::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
return TouchBinding::Wrap(aCx, this, aGivenProto);
}
// Parent ourselves to the window of the target. This achieves the desirable
// Parent ourselves to the global of the target. This achieves the desirable
// effects of parenting to the target, but avoids making the touch inaccessible
// when the target happens to be NAC and therefore reflected into the XBL scope.
EventTarget*
nsIGlobalObject*
Touch::GetParentObject()
{
if (!mTarget) {
return nullptr;
}
nsCOMPtr<nsPIDOMWindow> outer = do_QueryInterface(mTarget->GetOwnerGlobal());
if (!outer) {
return nullptr;
}
MOZ_ASSERT(outer->IsOuterWindow());
return static_cast<nsGlobalWindow*>(outer->GetCurrentInnerWindow());
return mTarget->GetOwnerGlobal();
}
} // namespace dom

View File

@ -57,7 +57,7 @@ public:
virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
EventTarget* GetParentObject();
nsIGlobalObject* GetParentObject();
// WebIDL
int32_t Identifier() const { return mIdentifier; }

View File

@ -428,7 +428,8 @@ IndexedDatabaseManager::CommonPostHandleEvent(EventChainPostVisitor& aVisitor,
nsEventStatus status = nsEventStatus_eIgnore;
if (NS_IsMainThread()) {
if (nsIDOMWindow* window = eventTarget->GetOwnerGlobal()) {
nsCOMPtr<nsIDOMWindow> window = do_QueryInterface(eventTarget->GetOwnerGlobal());
if (window) {
nsCOMPtr<nsIScriptGlobalObject> sgo = do_QueryInterface(window);
MOZ_ASSERT(sgo);

View File

@ -43,6 +43,6 @@ partial interface EventTarget {
// chrome easier. This returns the window which can be used to create
// events to fire at this EventTarget, or null if there isn't one.
partial interface EventTarget {
[ChromeOnly, Exposed=Window]
[ChromeOnly, Exposed=Window, BinaryName="ownerGlobalForBindings"]
readonly attribute WindowProxy? ownerGlobal;
};