Bug 1660755 [wpt PR 25207] - [scroll-animations] Allow null source in ScrollTimeline...
[gecko.git] / ipc / mscom / Registration.h
blob3dfd5458cdc6a840bd1d6b6d904a66ead62c7e3b
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/. */
7 #ifndef mozilla_mscom_Registration_h
8 #define mozilla_mscom_Registration_h
10 #include "mozilla/RefPtr.h"
11 #include "mozilla/UniquePtr.h"
13 #include <objbase.h>
15 struct ITypeInfo;
16 struct ITypeLib;
18 namespace mozilla {
19 namespace mscom {
21 /**
22 * Assumptions:
23 * (1) The DLL exports GetProxyDllInfo. This is not exported by default; it must
24 * be specified in the EXPORTS section of the DLL's module definition file.
26 class RegisteredProxy {
27 public:
28 RegisteredProxy(uintptr_t aModule, IUnknown* aClassObject,
29 uint32_t aRegCookie, ITypeLib* aTypeLib);
30 RegisteredProxy(IUnknown* aClassObject, uint32_t aRegCookie,
31 ITypeLib* aTypeLib);
32 explicit RegisteredProxy(ITypeLib* aTypeLib);
33 RegisteredProxy(RegisteredProxy&& aOther);
34 RegisteredProxy& operator=(RegisteredProxy&& aOther);
36 ~RegisteredProxy();
38 HRESULT GetTypeInfoForGuid(REFGUID aGuid, ITypeInfo** aOutTypeInfo) const;
40 static bool Find(REFIID aIid, ITypeInfo** aOutTypeInfo);
42 private:
43 RegisteredProxy() = delete;
44 RegisteredProxy(RegisteredProxy&) = delete;
45 RegisteredProxy& operator=(RegisteredProxy&) = delete;
47 void Clear();
49 static void AddToRegistry(RegisteredProxy* aProxy);
50 static void DeleteFromRegistry(RegisteredProxy* aProxy);
52 private:
53 // Not using Windows types here: We shouldn't #include windows.h
54 // since it might pull in COM code which we want to do very carefully in
55 // Registration.cpp.
56 uintptr_t mModule;
57 IUnknown* mClassObject;
58 uint32_t mRegCookie;
59 ITypeLib* mTypeLib;
60 #if defined(MOZILLA_INTERNAL_API)
61 bool mIsRegisteredInMTA;
62 #endif // defined(MOZILLA_INTERNAL_API)
65 enum class RegistrationFlags { eUseBinDirectory, eUseSystemDirectory };
67 // For our own DLL that we are currently executing in (ie, xul).
68 // Assumes corresponding TLB is embedded in resources.
69 UniquePtr<RegisteredProxy> RegisterProxy();
71 // For DLL files. Assumes corresponding TLB is embedded in resources.
72 UniquePtr<RegisteredProxy> RegisterProxy(
73 const wchar_t* aLeafName,
74 RegistrationFlags aFlags = RegistrationFlags::eUseBinDirectory);
75 // For standalone TLB files.
76 UniquePtr<RegisteredProxy> RegisterTypelib(
77 const wchar_t* aLeafName,
78 RegistrationFlags aFlags = RegistrationFlags::eUseBinDirectory);
80 #if defined(MOZILLA_INTERNAL_API)
82 /**
83 * The COM interceptor uses type library information to build its interface
84 * proxies. Unfortunately type libraries do not encode size_is and length_is
85 * annotations that have been specified in IDL. This structure allows us to
86 * explicitly declare such relationships so that the COM interceptor may
87 * be made aware of them.
89 struct ArrayData {
90 enum class Flag {
91 eNone = 0,
92 eAllocatedByServer = 1 // This implies an extra level of indirection
95 ArrayData(REFIID aIid, ULONG aMethodIndex, ULONG aArrayParamIndex,
96 VARTYPE aArrayParamType, REFIID aArrayParamIid,
97 ULONG aLengthParamIndex, Flag aFlag = Flag::eNone)
98 : mIid(aIid),
99 mMethodIndex(aMethodIndex),
100 mArrayParamIndex(aArrayParamIndex),
101 mArrayParamType(aArrayParamType),
102 mArrayParamIid(aArrayParamIid),
103 mLengthParamIndex(aLengthParamIndex),
104 mFlag(aFlag) {}
106 ArrayData(const ArrayData& aOther) { *this = aOther; }
108 ArrayData& operator=(const ArrayData& aOther) {
109 mIid = aOther.mIid;
110 mMethodIndex = aOther.mMethodIndex;
111 mArrayParamIndex = aOther.mArrayParamIndex;
112 mArrayParamType = aOther.mArrayParamType;
113 mArrayParamIid = aOther.mArrayParamIid;
114 mLengthParamIndex = aOther.mLengthParamIndex;
115 mFlag = aOther.mFlag;
116 return *this;
119 IID mIid;
120 ULONG mMethodIndex;
121 ULONG mArrayParamIndex;
122 VARTYPE mArrayParamType;
123 IID mArrayParamIid;
124 ULONG mLengthParamIndex;
125 Flag mFlag;
128 void RegisterArrayData(const ArrayData* aArrayData, size_t aLength);
130 template <size_t N>
131 inline void RegisterArrayData(const ArrayData (&aData)[N]) {
132 RegisterArrayData(aData, N);
135 const ArrayData* FindArrayData(REFIID aIid, ULONG aMethodIndex);
137 #endif // defined(MOZILLA_INTERNAL_API)
139 } // namespace mscom
140 } // namespace mozilla
142 #endif // mozilla_mscom_Registration_h