Bug 1135151. Add a WrapNativeParent specialization for the nsIGlobalObject case, and make Event return nsIGlobalObject as its parent object. r=smaug

This commit is contained in:
Boris Zbarsky 2015-02-23 10:03:40 -05:00
parent 607c3dee53
commit 11743e14d0
4 changed files with 28 additions and 20 deletions

View File

@ -28,6 +28,7 @@
#include "mozilla/MemoryReporting.h"
#include "mozilla/CycleCollectedJSRuntime.h"
#include "nsCycleCollector.h"
#include "nsIGlobalObject.h"
#include "nsIXPConnect.h"
#include "nsJSUtils.h"
#include "nsISupportsImpl.h"
@ -1577,6 +1578,15 @@ WrapNativeParent(JSContext* cx, const T& p)
return WrapNativeParent(cx, GetParentPointer(p), GetWrapperCache(p), GetUseXBLScope(p));
}
// Specialization for the case of nsIGlobalObject, since in that case
// we can just get the JSObject* directly.
template<>
inline JSObject*
WrapNativeParent(JSContext* cx, nsIGlobalObject* const& p)
{
return p ? p->GetGlobalJSObject() : JS::CurrentGlobalOrNull(cx);
}
template<typename T, bool WrapperCached=NativeHasMember<T>::GetParentObject>
struct GetParentObject
{

View File

@ -16,8 +16,9 @@ DataContainerEvent::DataContainerEvent(EventTarget* aOwner,
WidgetEvent* aEvent)
: Event(aOwner, aPresContext, aEvent)
{
if (mOwner) {
if (nsIDocument* doc = mOwner->GetExtantDoc()) {
nsCOMPtr<nsPIDOMWindow> win = do_QueryInterface(mOwner);
if (win) {
if (nsIDocument* doc = win->GetExtantDoc()) {
doc->WarnOnceAbout(nsIDocument::eDataContainerEvent);
}
}

View File

@ -1026,7 +1026,11 @@ Event::TimeStamp() const
return 0.0;
}
nsPerformance* perf = mOwner->GetPerformance();
nsCOMPtr<nsPIDOMWindow> win = do_QueryInterface(mOwner);
if (NS_WARN_IF(!win)) {
return 0.0;
}
nsPerformance* perf = win->GetPerformance();
if (NS_WARN_IF(!perf)) {
return 0.0;
}
@ -1049,8 +1053,9 @@ Event::TimeStamp() const
bool
Event::GetPreventDefault() const
{
if (mOwner) {
if (nsIDocument* doc = mOwner->GetExtantDoc()) {
nsCOMPtr<nsPIDOMWindow> win(do_QueryInterface(mOwner));
if (win) {
if (nsIDocument* doc = win->GetExtantDoc()) {
doc->WarnOnceAbout(nsIDocument::eGetPreventDefault);
}
}
@ -1130,23 +1135,23 @@ Event::SetOwner(mozilla::dom::EventTarget* aOwner)
nsCOMPtr<nsINode> n = do_QueryInterface(aOwner);
if (n) {
mOwner = do_QueryInterface(n->OwnerDoc()->GetScopeObject());
mOwner = n->OwnerDoc()->GetScopeObject();
return;
}
nsCOMPtr<nsPIDOMWindow> w = do_QueryInterface(aOwner);
if (w) {
if (w->IsOuterWindow()) {
mOwner = w->GetCurrentInnerWindow();
mOwner = do_QueryInterface(w->GetCurrentInnerWindow());
} else {
mOwner.swap(w);
mOwner = do_QueryInterface(w);
}
return;
}
nsCOMPtr<DOMEventTargetHelper> eth = do_QueryInterface(aOwner);
if (eth) {
mOwner = eth->GetOwner();
mOwner = eth->GetParentObject();
return;
}

View File

@ -19,6 +19,7 @@
#include "nsIScriptGlobalObject.h"
#include "Units.h"
#include "js/TypeDecls.h"
#include "nsIGlobalObject.h"
class nsIContent;
class nsIDOMEventTarget;
@ -63,15 +64,6 @@ private:
WidgetEvent* aEvent);
public:
void GetParentObject(nsIScriptGlobalObject** aParentObject)
{
if (mOwner) {
CallQueryInterface(mOwner, aParentObject);
} else {
*aParentObject = nullptr;
}
}
static Event* FromSupports(nsISupports* aSupports)
{
nsIDOMEvent* event =
@ -93,7 +85,7 @@ public:
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS(Event)
nsISupports* GetParentObject()
nsIGlobalObject* GetParentObject()
{
return mOwner;
}
@ -274,7 +266,7 @@ protected:
mozilla::WidgetEvent* mEvent;
nsRefPtr<nsPresContext> mPresContext;
nsCOMPtr<EventTarget> mExplicitOriginalTarget;
nsCOMPtr<nsPIDOMWindow> mOwner; // nsPIDOMWindow for now.
nsCOMPtr<nsIGlobalObject> mOwner;
bool mEventIsInternal;
bool mPrivateDataDuplicated;
bool mIsMainThreadEvent;