2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=2 sw=2 et tw=80: */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* 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/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#ifndef nsDOMClassInfo_h___
|
|
|
|
#define nsDOMClassInfo_h___
|
|
|
|
|
2013-06-05 09:15:48 -07:00
|
|
|
#include "mozilla/Attributes.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIXPCScriptable.h"
|
2009-06-03 08:30:18 -07:00
|
|
|
#include "nsIScriptGlobalObject.h"
|
2013-08-15 11:17:48 -07:00
|
|
|
#include "nsIDOMScriptObjectFactory.h"
|
2013-08-21 22:26:56 -07:00
|
|
|
#include "js/Id.h"
|
2013-09-09 13:37:37 -07:00
|
|
|
#include "nsIXPConnect.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-11-09 07:59:41 -08:00
|
|
|
#ifdef XP_WIN
|
|
|
|
#undef GetClassName
|
|
|
|
#endif
|
|
|
|
|
2012-07-01 16:45:59 -07:00
|
|
|
class nsContentList;
|
2013-07-04 15:53:59 -07:00
|
|
|
class nsDocument;
|
2014-02-15 13:12:34 -08:00
|
|
|
struct nsGlobalNameStruct;
|
2011-04-07 15:44:03 -07:00
|
|
|
class nsGlobalWindow;
|
2013-08-15 11:17:48 -07:00
|
|
|
class nsIScriptSecurityManager;
|
2013-02-16 20:43:16 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
struct nsDOMClassInfoData;
|
|
|
|
|
|
|
|
typedef nsIClassInfo* (*nsDOMClassInfoConstructorFnc)
|
|
|
|
(nsDOMClassInfoData* aData);
|
|
|
|
|
2008-11-05 22:41:52 -08:00
|
|
|
typedef nsresult (*nsDOMConstructorFunc)(nsISupports** aNewObject);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
struct nsDOMClassInfoData
|
|
|
|
{
|
|
|
|
const char *mName;
|
2014-01-04 07:02:17 -08:00
|
|
|
const char16_t *mNameUTF16;
|
2007-03-22 10:30:00 -07:00
|
|
|
union {
|
|
|
|
nsDOMClassInfoConstructorFnc mConstructorFptr;
|
|
|
|
nsDOMClassInfoExternalConstructorFnc mExternalConstructorFptr;
|
|
|
|
} u;
|
|
|
|
|
|
|
|
nsIClassInfo *mCachedClassInfo; // low bit is set to 1 if external,
|
|
|
|
// so be sure to mask if necessary!
|
|
|
|
const nsIID *mProtoChainInterface;
|
|
|
|
const nsIID **mInterfaces;
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t mScriptableFlags : 31; // flags must not use more than 31 bits!
|
|
|
|
uint32_t mHasClassInterface : 1;
|
|
|
|
uint32_t mInterfacesBitmap;
|
2013-08-09 07:35:53 -07:00
|
|
|
bool mChromeOnly : 1;
|
|
|
|
bool mAllowXBL : 1;
|
|
|
|
bool mDisabled : 1;
|
2012-06-25 12:59:42 -07:00
|
|
|
#ifdef DEBUG
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t mDebugID;
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
struct nsExternalDOMClassInfoData : public nsDOMClassInfoData
|
|
|
|
{
|
|
|
|
const nsCID *mConstructorCID;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// To be used with the nsDOMClassInfoData::mCachedClassInfo pointer.
|
|
|
|
// The low bit is set when we created a generic helper for an external
|
|
|
|
// (which holds on to the nsDOMClassInfoData).
|
2012-10-02 01:24:11 -07:00
|
|
|
#define GET_CLEAN_CI_PTR(_ptr) (nsIClassInfo*)(uintptr_t(_ptr) & ~0x1)
|
|
|
|
#define MARK_EXTERNAL(_ptr) (nsIClassInfo*)(uintptr_t(_ptr) | 0x1)
|
|
|
|
#define IS_EXTERNAL(_ptr) (uintptr_t(_ptr) & 0x1)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
|
2009-09-28 14:00:35 -07:00
|
|
|
class nsDOMClassInfo : public nsXPCClassInfo
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-05-16 11:06:21 -07:00
|
|
|
friend class nsHTMLDocumentSH;
|
2014-06-23 12:56:07 -07:00
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual ~nsDOMClassInfo();
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
public:
|
2014-08-08 06:49:39 -07:00
|
|
|
explicit nsDOMClassInfo(nsDOMClassInfoData* aData);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
NS_DECL_NSIXPCSCRIPTABLE
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
NS_DECL_NSICLASSINFO
|
|
|
|
|
|
|
|
// Helper method that returns a *non* refcounted pointer to a
|
|
|
|
// helper. So please note, don't release this pointer, if you do,
|
|
|
|
// you better make sure you've addreffed before release.
|
|
|
|
//
|
|
|
|
// Whaaaaa! I wanted to name this method GetClassInfo, but nooo,
|
|
|
|
// some of Microsoft devstudio's headers #defines GetClassInfo to
|
|
|
|
// GetClassInfoA so I can't, those $%#@^! bastards!!! What gives
|
|
|
|
// them the right to do that?
|
|
|
|
|
|
|
|
static nsIClassInfo* GetClassInfoInstance(nsDOMClassInfoData* aData);
|
|
|
|
|
2014-08-08 06:03:29 -07:00
|
|
|
static nsresult Init();
|
2007-03-22 10:30:00 -07:00
|
|
|
static void ShutDown();
|
|
|
|
|
|
|
|
static nsIClassInfo *doCreate(nsDOMClassInfoData* aData)
|
|
|
|
{
|
|
|
|
return new nsDOMClassInfo(aData);
|
|
|
|
}
|
|
|
|
|
2011-02-16 20:29:14 -08:00
|
|
|
/*
|
|
|
|
* The following two functions exist because of the way that Xray wrappers
|
|
|
|
* work. In order to allow scriptable helpers to define non-IDL defined but
|
|
|
|
* still "safe" properties for Xray wrappers, we call into the scriptable
|
|
|
|
* helper with |obj| being the wrapper.
|
|
|
|
*
|
|
|
|
* Ideally, that would be the end of the story, however due to complications
|
|
|
|
* dealing with document.domain, it's possible to end up in a scriptable
|
|
|
|
* helper with a wrapper, even though we should be treating the lookup as a
|
|
|
|
* transparent one.
|
2012-08-27 06:06:34 -07:00
|
|
|
*
|
|
|
|
* Note: So ObjectIsNativeWrapper(cx, obj) check usually means "through xray
|
|
|
|
* wrapper this part is not visible" while combined with
|
|
|
|
* || xpc::WrapperFactory::XrayWrapperNotShadowing(obj) it means "through
|
|
|
|
* xray wrapper it is visible only if it does not hide any native property."
|
2011-02-16 20:29:14 -08:00
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool ObjectIsNativeWrapper(JSContext* cx, JSObject* obj);
|
2010-07-02 13:54:53 -07:00
|
|
|
|
2010-03-04 16:17:05 -08:00
|
|
|
static nsISupports *GetNative(nsIXPConnectWrappedNative *wrapper, JSObject *obj);
|
2009-05-12 13:20:42 -07:00
|
|
|
|
|
|
|
static nsIXPConnect *XPConnect()
|
|
|
|
{
|
|
|
|
return sXPConnect;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
protected:
|
|
|
|
friend nsIClassInfo* NS_GetDOMClassInfoInstance(nsDOMClassInfoID aID);
|
|
|
|
|
|
|
|
const nsDOMClassInfoData* mData;
|
|
|
|
|
2013-06-05 09:15:48 -07:00
|
|
|
virtual void PreserveWrapper(nsISupports *aNative) MOZ_OVERRIDE
|
2009-11-29 00:32:39 -08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-06-05 09:15:48 -07:00
|
|
|
virtual uint32_t GetInterfacesBitmap() MOZ_OVERRIDE
|
2010-01-12 06:24:00 -08:00
|
|
|
{
|
|
|
|
return mData->mInterfacesBitmap;
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
static nsresult RegisterClassProtos(int32_t aDOMClassInfoID);
|
2007-03-22 10:30:00 -07:00
|
|
|
static nsresult RegisterExternalClasses();
|
|
|
|
nsresult ResolveConstructor(JSContext *cx, JSObject *obj,
|
|
|
|
JSObject **objp);
|
|
|
|
|
|
|
|
static nsIXPConnect *sXPConnect;
|
|
|
|
|
|
|
|
// nsIXPCScriptable code
|
|
|
|
static nsresult DefineStaticJSVals(JSContext *cx);
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool sIsInitialized;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-12-21 08:02:01 -08:00
|
|
|
public:
|
2010-07-14 23:19:36 -07:00
|
|
|
static jsid sLocation_id;
|
|
|
|
static jsid sConstructor_id;
|
2012-08-25 14:56:45 -07:00
|
|
|
static jsid sTop_id;
|
2010-07-14 23:19:36 -07:00
|
|
|
static jsid sDocument_id;
|
2010-09-17 14:54:40 -07:00
|
|
|
static jsid sWrappedJSObject_id;
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
2012-10-29 23:07:09 -07:00
|
|
|
// THIS ONE ISN'T SAFE!! It assumes that the private of the JSObject is
|
|
|
|
// an nsISupports.
|
2009-05-12 13:20:42 -07:00
|
|
|
inline
|
|
|
|
const nsQueryInterface
|
|
|
|
do_QueryWrappedNative(nsIXPConnectWrappedNative *wrapper, JSObject *obj)
|
|
|
|
{
|
|
|
|
return nsQueryInterface(nsDOMClassInfo::GetNative(wrapper, obj));
|
|
|
|
}
|
|
|
|
|
2012-10-29 23:07:09 -07:00
|
|
|
// THIS ONE ISN'T SAFE!! It assumes that the private of the JSObject is
|
|
|
|
// an nsISupports.
|
2009-05-12 13:20:42 -07:00
|
|
|
inline
|
|
|
|
const nsQueryInterfaceWithError
|
|
|
|
do_QueryWrappedNative(nsIXPConnectWrappedNative *wrapper, JSObject *obj,
|
|
|
|
nsresult *aError)
|
|
|
|
|
|
|
|
{
|
|
|
|
return nsQueryInterfaceWithError(nsDOMClassInfo::GetNative(wrapper, obj),
|
|
|
|
aError);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
nsQueryInterface
|
|
|
|
do_QueryWrapper(JSContext *cx, JSObject *obj)
|
|
|
|
{
|
|
|
|
nsISupports *native =
|
|
|
|
nsDOMClassInfo::XPConnect()->GetNativeOfWrapper(cx, obj);
|
|
|
|
return nsQueryInterface(native);
|
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
nsQueryInterfaceWithError
|
|
|
|
do_QueryWrapper(JSContext *cx, JSObject *obj, nsresult* error)
|
|
|
|
{
|
|
|
|
nsISupports *native =
|
|
|
|
nsDOMClassInfo::XPConnect()->GetNativeOfWrapper(cx, obj);
|
|
|
|
return nsQueryInterfaceWithError(native, error);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
typedef nsDOMClassInfo nsDOMGenericSH;
|
|
|
|
|
2010-01-13 05:50:01 -08:00
|
|
|
// Makes sure that the wrapper is preserved if new properties are added.
|
2008-08-14 04:04:43 -07:00
|
|
|
class nsEventTargetSH : public nsDOMGenericSH
|
|
|
|
{
|
|
|
|
protected:
|
2014-08-08 06:49:39 -07:00
|
|
|
explicit nsEventTargetSH(nsDOMClassInfoData* aData) : nsDOMGenericSH(aData)
|
2008-08-14 04:04:43 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~nsEventTargetSH()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
public:
|
2008-11-13 08:54:52 -08:00
|
|
|
NS_IMETHOD PreCreate(nsISupports *nativeObj, JSContext *cx,
|
2013-06-05 09:15:48 -07:00
|
|
|
JSObject *globalObj, JSObject **parentObj) MOZ_OVERRIDE;
|
2008-09-25 07:40:30 -07:00
|
|
|
NS_IMETHOD AddProperty(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
|
2013-08-17 15:50:18 -07:00
|
|
|
JSObject *obj, jsid id, JS::Value *vp, bool *_retval) MOZ_OVERRIDE;
|
2008-08-14 04:04:43 -07:00
|
|
|
|
2013-06-05 09:15:48 -07:00
|
|
|
virtual void PreserveWrapper(nsISupports *aNative) MOZ_OVERRIDE;
|
2009-11-29 00:32:39 -08:00
|
|
|
|
2008-08-14 04:04:43 -07:00
|
|
|
static nsIClassInfo *doCreate(nsDOMClassInfoData* aData)
|
|
|
|
{
|
|
|
|
return new nsEventTargetSH(aData);
|
|
|
|
}
|
|
|
|
};
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Window scriptable helper
|
|
|
|
|
2011-08-24 12:49:25 -07:00
|
|
|
class nsWindowSH : public nsDOMGenericSH
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
protected:
|
2014-08-08 06:49:39 -07:00
|
|
|
explicit nsWindowSH(nsDOMClassInfoData *aData) : nsDOMGenericSH(aData)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-09-17 14:54:40 -07:00
|
|
|
virtual ~nsWindowSH()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static nsresult GlobalResolve(nsGlobalWindow *aWin, JSContext *cx,
|
2013-05-04 00:51:53 -07:00
|
|
|
JS::Handle<JSObject*> obj, JS::Handle<jsid> id,
|
2014-01-29 22:33:23 -08:00
|
|
|
JS::MutableHandle<JSPropertyDescriptor> desc);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-01-29 22:33:25 -08:00
|
|
|
friend class nsGlobalWindow;
|
2007-03-22 10:30:00 -07:00
|
|
|
public:
|
2010-09-17 14:54:40 -07:00
|
|
|
NS_IMETHOD PreCreate(nsISupports *nativeObj, JSContext *cx,
|
2013-06-05 09:15:48 -07:00
|
|
|
JSObject *globalObj, JSObject **parentObj) MOZ_OVERRIDE;
|
2013-07-09 07:45:13 -07:00
|
|
|
NS_IMETHOD PostCreatePrototype(JSContext * cx, JSObject * proto) MOZ_OVERRIDE;
|
2009-06-03 08:30:18 -07:00
|
|
|
NS_IMETHOD PostCreate(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
|
2013-10-08 09:18:40 -07:00
|
|
|
JSObject *obj) MOZ_OVERRIDE;
|
2011-04-08 13:28:05 -07:00
|
|
|
NS_IMETHOD Enumerate(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
|
2013-06-05 09:15:48 -07:00
|
|
|
JSObject *obj, bool *_retval) MOZ_OVERRIDE;
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHOD NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
|
2014-04-25 14:11:02 -07:00
|
|
|
JSObject *obj, jsid id, JSObject **objp,
|
|
|
|
bool *_retval) MOZ_OVERRIDE;
|
2010-09-17 14:54:40 -07:00
|
|
|
NS_IMETHOD OuterObject(nsIXPConnectWrappedNative *wrapper, JSContext * cx,
|
2013-06-05 09:15:48 -07:00
|
|
|
JSObject * obj, JSObject * *_retval) MOZ_OVERRIDE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-02-15 13:12:34 -08:00
|
|
|
static bool NameStructEnabled(JSContext* aCx, nsGlobalWindow *aWin,
|
|
|
|
const nsAString& aName,
|
|
|
|
const nsGlobalNameStruct& aNameStruct);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
static nsIClassInfo *doCreate(nsDOMClassInfoData* aData)
|
|
|
|
{
|
2010-09-17 14:54:40 -07:00
|
|
|
return new nsWindowSH(aData);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Event handler 'this' translator class, this is called by XPConnect
|
|
|
|
// when a "function interface" (nsIDOMEventListener) is called, this
|
|
|
|
// class extracts 'this' fomr the first argument to the called
|
|
|
|
// function (nsIDOMEventListener::HandleEvent(in nsIDOMEvent)), this
|
|
|
|
// class will pass back nsIDOMEvent::currentTarget to be used as
|
|
|
|
// 'this'.
|
|
|
|
|
|
|
|
class nsEventListenerThisTranslator : public nsIXPCFunctionThisTranslator
|
|
|
|
{
|
2014-06-23 12:56:07 -07:00
|
|
|
virtual ~nsEventListenerThisTranslator()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2014-06-23 12:56:07 -07:00
|
|
|
public:
|
|
|
|
nsEventListenerThisTranslator()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// nsISupports
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
// nsIXPCFunctionThisTranslator
|
|
|
|
NS_DECL_NSIXPCFUNCTIONTHISTRANSLATOR
|
|
|
|
};
|
|
|
|
|
|
|
|
class nsDOMConstructorSH : public nsDOMGenericSH
|
|
|
|
{
|
|
|
|
protected:
|
2014-08-08 06:49:39 -07:00
|
|
|
explicit nsDOMConstructorSH(nsDOMClassInfoData* aData) : nsDOMGenericSH(aData)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
2011-01-11 12:15:52 -08:00
|
|
|
NS_IMETHOD PreCreate(nsISupports *nativeObj, JSContext *cx,
|
2013-06-05 09:15:48 -07:00
|
|
|
JSObject *globalObj, JSObject **parentObj) MOZ_OVERRIDE;
|
|
|
|
NS_IMETHOD PostCreatePrototype(JSContext * cx, JSObject * proto) MOZ_OVERRIDE
|
2009-06-03 08:30:18 -07:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2011-09-21 19:16:50 -07:00
|
|
|
NS_IMETHOD NewResolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
|
2014-04-25 14:11:02 -07:00
|
|
|
JSObject *obj, jsid id, JSObject **objp,
|
|
|
|
bool *_retval) MOZ_OVERRIDE;
|
2007-05-09 05:04:59 -07:00
|
|
|
NS_IMETHOD Call(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
|
2013-06-05 09:15:48 -07:00
|
|
|
JSObject *obj, const JS::CallArgs &args, bool *_retval) MOZ_OVERRIDE;
|
2007-05-09 05:04:59 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHOD Construct(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
|
2013-06-05 09:15:48 -07:00
|
|
|
JSObject *obj, const JS::CallArgs &args, bool *_retval) MOZ_OVERRIDE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
NS_IMETHOD HasInstance(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
|
2014-01-09 09:39:36 -08:00
|
|
|
JSObject *obj, JS::Handle<JS::Value> val, bool *bp,
|
2011-09-28 23:19:26 -07:00
|
|
|
bool *_retval);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
static nsIClassInfo *doCreate(nsDOMClassInfoData* aData)
|
|
|
|
{
|
|
|
|
return new nsDOMConstructorSH(aData);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
class nsNonDOMObjectSH : public nsDOMGenericSH
|
|
|
|
{
|
|
|
|
protected:
|
2014-08-08 06:49:39 -07:00
|
|
|
explicit nsNonDOMObjectSH(nsDOMClassInfoData* aData) : nsDOMGenericSH(aData)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ~nsNonDOMObjectSH()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public:
|
2013-06-05 09:15:48 -07:00
|
|
|
NS_IMETHOD GetFlags(uint32_t *aFlags) MOZ_OVERRIDE;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
static nsIClassInfo *doCreate(nsDOMClassInfoData* aData)
|
|
|
|
{
|
|
|
|
return new nsNonDOMObjectSH(aData);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* nsDOMClassInfo_h___ */
|