LCOV - code coverage report
Current view: top level - dom/base - nsDOMClassInfo.h (source / functions) Hit Total Coverage
Test: output.info Lines: 18 30 60.0 %
Date: 2017-07-14 16:53:18 Functions: 10 23 43.5 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
       2             : /* vim: set ts=8 sts=2 et sw=2 tw=80: */
       3             : /* This Source Code Form is subject to the terms of the Mozilla Public
       4             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       5             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
       6             : 
       7             : #ifndef nsDOMClassInfo_h___
       8             : #define nsDOMClassInfo_h___
       9             : 
      10             : #include "mozilla/Attributes.h"
      11             : #include "nsDOMClassInfoID.h"
      12             : #include "nsIXPCScriptable.h"
      13             : #include "nsIScriptGlobalObject.h"
      14             : #include "js/Class.h"
      15             : #include "js/Id.h"
      16             : #include "nsIXPConnect.h"
      17             : 
      18             : #ifdef XP_WIN
      19             : #undef GetClassName
      20             : #endif
      21             : 
      22             : struct nsGlobalNameStruct;
      23             : class nsGlobalWindow;
      24             : 
      25             : struct nsDOMClassInfoData;
      26             : 
      27             : typedef nsIClassInfo* (*nsDOMClassInfoConstructorFnc)
      28             :   (nsDOMClassInfoData* aData);
      29             : 
      30             : typedef nsresult (*nsDOMConstructorFunc)(nsISupports** aNewObject);
      31             : 
      32             : struct nsDOMClassInfoData
      33             : {
      34             :   // The ASCII name is available as mClass.name.
      35             :   const char16_t *mNameUTF16;
      36             :   const js::ClassOps mClassOps;
      37             :   const js::Class mClass;
      38             :   nsDOMClassInfoConstructorFnc mConstructorFptr;
      39             : 
      40             :   nsIClassInfo *mCachedClassInfo;
      41             :   const nsIID *mProtoChainInterface;
      42             :   const nsIID **mInterfaces;
      43             :   uint32_t mScriptableFlags : 31; // flags must not use more than 31 bits!
      44             :   uint32_t mHasClassInterface : 1;
      45             :   bool mChromeOnly : 1;
      46             :   bool mAllowXBL : 1;
      47             :   bool mDisabled : 1;
      48             : #ifdef DEBUG
      49             :   uint32_t mDebugID;
      50             : #endif
      51             : };
      52             : 
      53             : class nsWindowSH;
      54             : 
      55             : class nsDOMClassInfo : public nsXPCClassInfo
      56             : {
      57             :   friend class nsWindowSH;
      58             : 
      59             : protected:
      60           0 :   virtual ~nsDOMClassInfo() {};
      61             : 
      62             : public:
      63             :   explicit nsDOMClassInfo(nsDOMClassInfoData* aData);
      64             : 
      65             :   NS_DECL_NSIXPCSCRIPTABLE
      66             : 
      67             :   NS_DECL_ISUPPORTS
      68             : 
      69             :   NS_DECL_NSICLASSINFO
      70             : 
      71             :   static nsresult Init();
      72             :   static void ShutDown();
      73             : 
      74           2 :   static nsIClassInfo *doCreate(nsDOMClassInfoData* aData)
      75             :   {
      76           2 :     return new nsDOMClassInfo(aData);
      77             :   }
      78             : 
      79             :   /*
      80             :    * The following two functions exist because of the way that Xray wrappers
      81             :    * work. In order to allow scriptable helpers to define non-IDL defined but
      82             :    * still "safe" properties for Xray wrappers, we call into the scriptable
      83             :    * helper with |obj| being the wrapper.
      84             :    *
      85             :    * Ideally, that would be the end of the story, however due to complications
      86             :    * dealing with document.domain, it's possible to end up in a scriptable
      87             :    * helper with a wrapper, even though we should be treating the lookup as a
      88             :    * transparent one.
      89             :    *
      90             :    * Note: So ObjectIsNativeWrapper(cx, obj) check usually means "through xray
      91             :    * wrapper this part is not visible".
      92             :    */
      93             :   static bool ObjectIsNativeWrapper(JSContext* cx, JSObject* obj);
      94             : 
      95             :   static nsISupports *GetNative(nsIXPConnectWrappedNative *wrapper, JSObject *obj);
      96             : 
      97             :   static nsIXPConnect *XPConnect()
      98             :   {
      99             :     return sXPConnect;
     100             :   }
     101             : 
     102             : protected:
     103             :   friend nsIClassInfo* NS_GetDOMClassInfoInstance(nsDOMClassInfoID aID);
     104             : 
     105             :   const nsDOMClassInfoData* mData;
     106             : 
     107           0 :   virtual void PreserveWrapper(nsISupports *aNative) override
     108             :   {
     109           0 :   }
     110             : 
     111             :   static nsresult RegisterClassProtos(int32_t aDOMClassInfoID);
     112             : 
     113             :   static nsIXPConnect *sXPConnect;
     114             : 
     115             :   // nsIXPCScriptable code
     116             :   static nsresult DefineStaticJSVals();
     117             : 
     118             :   static bool sIsInitialized;
     119             : 
     120             : public:
     121             :   static jsid sConstructor_id;
     122             :   static jsid sWrappedJSObject_id;
     123             : };
     124             : 
     125             : // THIS ONE ISN'T SAFE!! It assumes that the private of the JSObject is
     126             : // an nsISupports.
     127             : inline
     128             : const nsQueryInterface
     129             : do_QueryWrappedNative(nsIXPConnectWrappedNative *wrapper, JSObject *obj)
     130             : {
     131             :   return nsQueryInterface(nsDOMClassInfo::GetNative(wrapper, obj));
     132             : }
     133             : 
     134             : // THIS ONE ISN'T SAFE!! It assumes that the private of the JSObject is
     135             : // an nsISupports.
     136             : inline
     137             : const nsQueryInterfaceWithError
     138             : do_QueryWrappedNative(nsIXPConnectWrappedNative *wrapper, JSObject *obj,
     139             :                       nsresult *aError)
     140             : 
     141             : {
     142             :   return nsQueryInterfaceWithError(nsDOMClassInfo::GetNative(wrapper, obj),
     143             :                                    aError);
     144             : }
     145             : 
     146             : typedef nsDOMClassInfo nsDOMGenericSH;
     147             : 
     148             : // Makes sure that the wrapper is preserved if new properties are added.
     149             : class nsEventTargetSH : public nsDOMGenericSH
     150             : {
     151             : protected:
     152           2 :   explicit nsEventTargetSH(nsDOMClassInfoData* aData) : nsDOMGenericSH(aData)
     153             :   {
     154           2 :   }
     155             : 
     156           0 :   virtual ~nsEventTargetSH()
     157           0 :   {
     158           0 :   }
     159             : public:
     160             :   NS_IMETHOD PreCreate(nsISupports *nativeObj, JSContext *cx,
     161             :                        JSObject *globalObj, JSObject **parentObj) override;
     162             : 
     163             :   virtual void PreserveWrapper(nsISupports *aNative) override;
     164             : };
     165             : 
     166             : // A place to hang some static methods that we should really consider
     167             : // moving to be nsGlobalWindow member methods.  See bug 1062418.
     168             : class nsWindowSH
     169             : {
     170             : protected:
     171             :   static nsresult GlobalResolve(nsGlobalWindow *aWin, JSContext *cx,
     172             :                                 JS::Handle<JSObject*> obj, JS::Handle<jsid> id,
     173             :                                 JS::MutableHandle<JS::PropertyDescriptor> desc);
     174             : 
     175             :   friend class nsGlobalWindow;
     176             : public:
     177             :   static bool NameStructEnabled(JSContext* aCx, nsGlobalWindow *aWin,
     178             :                                 const nsAString& aName,
     179             :                                 const nsGlobalNameStruct& aNameStruct);
     180             : };
     181             : 
     182             : 
     183             : // Event handler 'this' translator class, this is called by XPConnect
     184             : // when a "function interface" (nsIDOMEventListener) is called, this
     185             : // class extracts 'this' fomr the first argument to the called
     186             : // function (nsIDOMEventListener::HandleEvent(in nsIDOMEvent)), this
     187             : // class will pass back nsIDOMEvent::currentTarget to be used as
     188             : // 'this'.
     189             : 
     190             : class nsEventListenerThisTranslator : public nsIXPCFunctionThisTranslator
     191             : {
     192           0 :   virtual ~nsEventListenerThisTranslator()
     193           0 :   {
     194           0 :   }
     195             : 
     196             : public:
     197           3 :   nsEventListenerThisTranslator()
     198           3 :   {
     199           3 :   }
     200             : 
     201             :   // nsISupports
     202             :   NS_DECL_ISUPPORTS
     203             : 
     204             :   // nsIXPCFunctionThisTranslator
     205             :   NS_DECL_NSIXPCFUNCTIONTHISTRANSLATOR
     206             : };
     207             : 
     208           0 : class nsDOMConstructorSH : public nsDOMGenericSH
     209             : {
     210             : protected:
     211           1 :   explicit nsDOMConstructorSH(nsDOMClassInfoData* aData) : nsDOMGenericSH(aData)
     212             :   {
     213           1 :   }
     214             : 
     215             : public:
     216             :   NS_IMETHOD PreCreate(nsISupports *nativeObj, JSContext *cx,
     217             :                        JSObject *globalObj, JSObject **parentObj) override;
     218           1 :   NS_IMETHOD PostCreatePrototype(JSContext * cx, JSObject * proto) override
     219             :   {
     220           1 :     return NS_OK;
     221             :   }
     222             :   NS_IMETHOD Resolve(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
     223             :                      JSObject *obj, jsid id, bool *resolvedp,
     224             :                      bool *_retval) override;
     225             :   NS_IMETHOD Call(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
     226             :                   JSObject *obj, const JS::CallArgs &args, bool *_retval) override;
     227             : 
     228             :   NS_IMETHOD Construct(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
     229             :                        JSObject *obj, const JS::CallArgs &args, bool *_retval) override;
     230             : 
     231             :   NS_IMETHOD HasInstance(nsIXPConnectWrappedNative *wrapper, JSContext *cx,
     232             :                          JSObject *obj, JS::Handle<JS::Value> val, bool *bp,
     233             :                          bool *_retval) override;
     234             : 
     235           1 :   static nsIClassInfo *doCreate(nsDOMClassInfoData* aData)
     236             :   {
     237           1 :     return new nsDOMConstructorSH(aData);
     238             :   }
     239             : };
     240             : 
     241             : template<typename Super>
     242             : class nsMessageManagerSH : public Super
     243             : {
     244             : protected:
     245           5 :   explicit nsMessageManagerSH(nsDOMClassInfoData* aData)
     246           5 :     : Super(aData)
     247             :   {
     248           5 :   }
     249             : 
     250           0 :   virtual ~nsMessageManagerSH()
     251             :   {
     252           0 :   }
     253             : public:
     254             :   NS_IMETHOD Resolve(nsIXPConnectWrappedNative* wrapper, JSContext* cx,
     255             :                      JSObject* obj_, jsid id_, bool* resolvedp,
     256             :                      bool* _retval) override;
     257             :   NS_IMETHOD Enumerate(nsIXPConnectWrappedNative* wrapper, JSContext* cx,
     258             :                        JSObject* obj_, bool* _retval) override;
     259             : 
     260           5 :   static nsIClassInfo *doCreate(nsDOMClassInfoData* aData)
     261             :   {
     262           5 :     return new nsMessageManagerSH(aData);
     263             :   }
     264             : };
     265             : 
     266             : #endif /* nsDOMClassInfo_h___ */

Generated by: LCOV version 1.13