dom/base/nsIDOMClassInfo.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     2 /* This Source Code Form is subject to the terms of the Mozilla Public
     3  * License, v. 2.0. If a copy of the MPL was not distributed with this
     4  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     6 #ifndef nsIDOMClassInfo_h___
     7 #define nsIDOMClassInfo_h___
     9 #include "nsIClassInfoImpl.h"
    10 #include "nsDOMClassInfoID.h"
    11 #include "nsIXPCScriptable.h"
    12 #include "nsIServiceManager.h"
    13 #include "nsIDOMScriptObjectFactory.h"
    14 #include "nsDOMCID.h"
    16 #define DOM_BASE_SCRIPTABLE_FLAGS                                          \
    17   (nsIXPCScriptable::USE_JSSTUB_FOR_ADDPROPERTY |                          \
    18    nsIXPCScriptable::USE_JSSTUB_FOR_DELPROPERTY |                          \
    19    nsIXPCScriptable::USE_JSSTUB_FOR_SETPROPERTY |                          \
    20    nsIXPCScriptable::ALLOW_PROP_MODS_TO_PROTOTYPE |                        \
    21    nsIXPCScriptable::DONT_ASK_INSTANCE_FOR_SCRIPTABLE |                    \
    22    nsIXPCScriptable::DONT_REFLECT_INTERFACE_NAMES)
    24 #define DEFAULT_SCRIPTABLE_FLAGS                                           \
    25   (DOM_BASE_SCRIPTABLE_FLAGS |                                             \
    26    nsIXPCScriptable::WANT_NEWRESOLVE |                                     \
    27    nsIXPCScriptable::WANT_PRECREATE)
    29 #define DOM_DEFAULT_SCRIPTABLE_FLAGS                                       \
    30   (DEFAULT_SCRIPTABLE_FLAGS |                                              \
    31    nsIXPCScriptable::DONT_ENUM_QUERY_INTERFACE |                           \
    32    nsIXPCScriptable::CLASSINFO_INTERFACES_ONLY)
    35 #ifdef MOZILLA_INTERNAL_API
    37 // See nsDOMClassInfoID.h
    39 #else
    41 #define NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(_class)                       \
    42   if (aIID.Equals(NS_GET_IID(nsIClassInfo)) ||                             \
    43       aIID.Equals(NS_GET_IID(nsXPCClassInfo))) {                           \
    44     static NS_DEFINE_CID(kDOMSOF_CID, NS_DOM_SCRIPT_OBJECT_FACTORY_CID);   \
    45                                                                            \
    46     nsresult rv;                                                           \
    47     nsCOMPtr<nsIDOMScriptObjectFactory> sof(do_GetService(kDOMSOF_CID,     \
    48                                                           &rv));           \
    49     if (NS_FAILED(rv)) {                                                   \
    50       *aInstancePtr = nullptr;                                              \
    51       return rv;                                                           \
    52     }                                                                      \
    53                                                                            \
    54     foundInterface =                                                       \
    55       sof->GetClassInfoInstance(eDOMClassInfo_##_class##_id);              \
    56   } else
    58 #endif /* MOZILLA_INTERNAL_API */
    60 // Looks up the nsIClassInfo for a class name registered with the 
    61 // nsScriptNamespaceManager. Remember to release NS_CLASSINFO_NAME(_class)
    62 // (eg. when your module unloads).
    63 #define NS_INTERFACE_MAP_ENTRY_EXTERNAL_DOM_CLASSINFO(_class)              \
    64   if (aIID.Equals(NS_GET_IID(nsIClassInfo)) ||                             \
    65       aIID.Equals(NS_GET_IID(nsXPCClassInfo))) {                           \
    66     extern nsISupports *NS_CLASSINFO_NAME(_class);                         \
    67     if (NS_CLASSINFO_NAME(_class)) {                                       \
    68       foundInterface = NS_CLASSINFO_NAME(_class);                          \
    69     } else {                                                               \
    70       static NS_DEFINE_CID(kDOMSOF_CID, NS_DOM_SCRIPT_OBJECT_FACTORY_CID); \
    71                                                                            \
    72       nsresult rv;                                                         \
    73       nsCOMPtr<nsIDOMScriptObjectFactory> sof(do_GetService(kDOMSOF_CID,   \
    74                                                             &rv));         \
    75       if (NS_FAILED(rv)) {                                                 \
    76         *aInstancePtr = nullptr;                                            \
    77         return rv;                                                         \
    78       }                                                                    \
    79                                                                            \
    80       foundInterface =                                                     \
    81         sof->GetExternalClassInfoInstance(NS_LITERAL_STRING(#_class));     \
    82                                                                            \
    83       if (foundInterface) {                                                \
    84         NS_CLASSINFO_NAME(_class) = foundInterface;                        \
    85         NS_CLASSINFO_NAME(_class)->AddRef();                               \
    86       }                                                                    \
    87     }                                                                      \
    88   } else
    91 #define NS_DECL_DOM_CLASSINFO(_class) \
    92   nsISupports *NS_CLASSINFO_NAME(_class) = nullptr;
    94 // {891a7b01-1b61-11d6-a7f2-f690b638899c}
    95 #define NS_IDOMCI_EXTENSION_IID  \
    96 { 0x891a7b01, 0x1b61, 0x11d6, \
    97 { 0xa7, 0xf2, 0xf6, 0x90, 0xb6, 0x38, 0x89, 0x9c } }
    99 class nsIDOMScriptObjectFactory;
   101 class nsIDOMCIExtension : public nsISupports {
   102 public:  
   103   NS_DECLARE_STATIC_IID_ACCESSOR(NS_IDOMCI_EXTENSION_IID)
   105   NS_IMETHOD RegisterDOMCI(const char* aName,
   106                            nsIDOMScriptObjectFactory* aDOMSOFactory) = 0;
   107 };
   109 NS_DEFINE_STATIC_IID_ACCESSOR(nsIDOMCIExtension, NS_IDOMCI_EXTENSION_IID)
   111 #define NS_DOMCI_EXTENSION_NAME(_module) ns##_module##DOMCIExtension
   112 #define NS_DOMCI_EXTENSION_CONSTRUCTOR(_module) \
   113   ns##_module##DOMCIExtensionConstructor
   114 #define NS_DOMCI_EXTENSION_CONSTRUCTOR_IMP(_extension) \
   115   NS_GENERIC_FACTORY_CONSTRUCTOR(_extension)
   117 #define NS_DOMCI_EXTENSION(_module)                                       \
   118 class NS_DOMCI_EXTENSION_NAME(_module) : public nsIDOMCIExtension         \
   119 {                                                                         \
   120 public:                                                                   \
   121   NS_DOMCI_EXTENSION_NAME(_module)();                                     \
   122   virtual ~NS_DOMCI_EXTENSION_NAME(_module)();                            \
   123                                                                           \
   124   NS_DECL_ISUPPORTS                                                       \
   125                                                                           \
   126   NS_IMETHOD RegisterDOMCI(const char* aName,                             \
   127                            nsIDOMScriptObjectFactory* aDOMSOFactory);     \
   128 };                                                                        \
   129                                                                           \
   130 NS_DOMCI_EXTENSION_CONSTRUCTOR_IMP(NS_DOMCI_EXTENSION_NAME(_module))      \
   131                                                                           \
   132 NS_DOMCI_EXTENSION_NAME(_module)::NS_DOMCI_EXTENSION_NAME(_module)()      \
   133 {                                                                         \
   134 }                                                                         \
   135                                                                           \
   136 NS_DOMCI_EXTENSION_NAME(_module)::~NS_DOMCI_EXTENSION_NAME(_module)()     \
   137 {                                                                         \
   138 }                                                                         \
   139                                                                           \
   140 NS_IMPL_ISUPPORTS(NS_DOMCI_EXTENSION_NAME(_module), nsIDOMCIExtension)    \
   141                                                                           \
   142 NS_IMETHODIMP                                                             \
   143 NS_DOMCI_EXTENSION_NAME(_module)::RegisterDOMCI(const char* aName,        \
   144                                                 nsIDOMScriptObjectFactory* aDOMSOFactory) \
   145 {
   147 #define NS_DOMCI_EXTENSION_ENTRY_BEGIN(_class)                            \
   148   if (nsCRT::strcmp(aName, #_class) == 0) {                               \
   149     static const nsIID* interfaces[] = {
   151 #define NS_DOMCI_EXTENSION_ENTRY_INTERFACE(_interface)                    \
   152       &NS_GET_IID(_interface),
   154 // Don't forget to register the primary interface (_proto) in the 
   155 // JAVASCRIPT_DOM_INTERFACE category, or prototypes for this class
   156 // won't work (except if the interface name starts with nsIDOM).
   157 #define NS_DOMCI_EXTENSION_ENTRY_END_HELPER(_class, _proto, _hasclassif,  \
   158                                             _constructorcid)              \
   159       nullptr                                                              \
   160     };                                                                    \
   161     aDOMSOFactory->RegisterDOMClassInfo(#_class, nullptr, _proto,          \
   162                                         interfaces,                       \
   163                                         DOM_DEFAULT_SCRIPTABLE_FLAGS,     \
   164                                         _hasclassif, _constructorcid);    \
   165     return NS_OK;                                                         \
   166   }
   168 #define NS_DOMCI_EXTENSION_ENTRY_END(_class, _proto, _hasclassif,         \
   169                                      _constructorcid)                     \
   170   NS_DOMCI_EXTENSION_ENTRY_END_HELPER(_class, &NS_GET_IID(_proto),        \
   171                                       _hasclassif, _constructorcid)
   173 #define NS_DOMCI_EXTENSION_ENTRY_END_NO_PRIMARY_IF(_class, _hasclassif,   \
   174                                                    _constructorcid)       \
   175   NS_DOMCI_EXTENSION_ENTRY_END_HELPER(_class, nullptr, _hasclassif,        \
   176                                       _constructorcid)
   178 #define NS_DOMCI_EXTENSION_END                                            \
   179   return NS_ERROR_FAILURE;                                                \
   180 }
   183 #endif /* nsIDOMClassInfo_h___ */

mercurial