2016-07-27 20:45:08 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* 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/. */
|
|
|
|
|
|
|
|
#ifndef mozilla_mscom_Registration_h
|
|
|
|
#define mozilla_mscom_Registration_h
|
|
|
|
|
|
|
|
#include "mozilla/RefPtr.h"
|
|
|
|
#include "mozilla/UniquePtr.h"
|
|
|
|
|
|
|
|
#include <objbase.h>
|
|
|
|
|
|
|
|
struct ITypeInfo;
|
|
|
|
struct ITypeLib;
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace mscom {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Assumptions:
|
|
|
|
* (1) The DLL exports GetProxyDllInfo. This is not exported by default; it must
|
|
|
|
* be specified in the EXPORTS section of the DLL's module definition file.
|
|
|
|
*/
|
|
|
|
class RegisteredProxy {
|
|
|
|
public:
|
|
|
|
RegisteredProxy(uintptr_t aModule, IUnknown* aClassObject,
|
|
|
|
uint32_t aRegCookie, ITypeLib* aTypeLib);
|
2017-01-17 23:19:40 +03:00
|
|
|
RegisteredProxy(IUnknown* aClassObject, uint32_t aRegCookie,
|
|
|
|
ITypeLib* aTypeLib);
|
2016-07-27 20:45:08 +03:00
|
|
|
explicit RegisteredProxy(ITypeLib* aTypeLib);
|
|
|
|
RegisteredProxy(RegisteredProxy&& aOther);
|
|
|
|
RegisteredProxy& operator=(RegisteredProxy&& aOther);
|
|
|
|
|
|
|
|
~RegisteredProxy();
|
|
|
|
|
2017-02-18 03:30:03 +03:00
|
|
|
HRESULT GetTypeInfoForGuid(REFGUID aGuid, ITypeInfo** aOutTypeInfo) const;
|
2016-07-27 20:45:08 +03:00
|
|
|
|
|
|
|
static bool Find(REFIID aIid, ITypeInfo** aOutTypeInfo);
|
|
|
|
|
|
|
|
private:
|
|
|
|
RegisteredProxy() = delete;
|
|
|
|
RegisteredProxy(RegisteredProxy&) = delete;
|
|
|
|
RegisteredProxy& operator=(RegisteredProxy&) = delete;
|
|
|
|
|
2019-03-20 03:29:27 +03:00
|
|
|
void Clear();
|
|
|
|
|
2016-07-27 20:45:08 +03:00
|
|
|
static void AddToRegistry(RegisteredProxy* aProxy);
|
|
|
|
static void DeleteFromRegistry(RegisteredProxy* aProxy);
|
|
|
|
|
|
|
|
private:
|
|
|
|
// Not using Windows types here: We shouldn't #include windows.h
|
|
|
|
// since it might pull in COM code which we want to do very carefully in
|
|
|
|
// Registration.cpp.
|
|
|
|
uintptr_t mModule;
|
|
|
|
IUnknown* mClassObject;
|
|
|
|
uint32_t mRegCookie;
|
|
|
|
ITypeLib* mTypeLib;
|
2017-02-16 00:37:20 +03:00
|
|
|
#if defined(MOZILLA_INTERNAL_API)
|
2016-09-08 01:10:45 +03:00
|
|
|
bool mIsRegisteredInMTA;
|
2017-02-16 00:37:20 +03:00
|
|
|
#endif // defined(MOZILLA_INTERNAL_API)
|
2016-07-27 20:45:08 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
enum class RegistrationFlags { eUseBinDirectory, eUseSystemDirectory };
|
|
|
|
|
2017-01-17 23:19:40 +03:00
|
|
|
// For our own DLL that we are currently executing in (ie, xul).
|
|
|
|
// Assumes corresponding TLB is embedded in resources.
|
|
|
|
UniquePtr<RegisteredProxy> RegisterProxy();
|
|
|
|
|
2016-07-27 20:45:08 +03:00
|
|
|
// For DLL files. Assumes corresponding TLB is embedded in resources.
|
|
|
|
UniquePtr<RegisteredProxy> RegisterProxy(
|
|
|
|
const wchar_t* aLeafName,
|
|
|
|
RegistrationFlags aFlags = RegistrationFlags::eUseBinDirectory);
|
|
|
|
// For standalone TLB files.
|
|
|
|
UniquePtr<RegisteredProxy> RegisterTypelib(
|
|
|
|
const wchar_t* aLeafName,
|
|
|
|
RegistrationFlags aFlags = RegistrationFlags::eUseBinDirectory);
|
|
|
|
|
2017-02-16 00:37:20 +03:00
|
|
|
#if defined(MOZILLA_INTERNAL_API)
|
|
|
|
|
2016-07-27 20:45:08 +03:00
|
|
|
/**
|
|
|
|
* The COM interceptor uses type library information to build its interface
|
|
|
|
* proxies. Unfortunately type libraries do not encode size_is and length_is
|
|
|
|
* annotations that have been specified in IDL. This structure allows us to
|
|
|
|
* explicitly declare such relationships so that the COM interceptor may
|
|
|
|
* be made aware of them.
|
|
|
|
*/
|
|
|
|
struct ArrayData {
|
2016-11-08 02:04:06 +03:00
|
|
|
enum class Flag {
|
|
|
|
eNone = 0,
|
|
|
|
eAllocatedByServer = 1 // This implies an extra level of indirection
|
|
|
|
};
|
|
|
|
|
2016-07-27 20:45:08 +03:00
|
|
|
ArrayData(REFIID aIid, ULONG aMethodIndex, ULONG aArrayParamIndex,
|
|
|
|
VARTYPE aArrayParamType, REFIID aArrayParamIid,
|
2016-11-08 02:04:06 +03:00
|
|
|
ULONG aLengthParamIndex, Flag aFlag = Flag::eNone)
|
2016-07-27 20:45:08 +03:00
|
|
|
: mIid(aIid),
|
|
|
|
mMethodIndex(aMethodIndex),
|
|
|
|
mArrayParamIndex(aArrayParamIndex),
|
|
|
|
mArrayParamType(aArrayParamType),
|
|
|
|
mArrayParamIid(aArrayParamIid),
|
|
|
|
mLengthParamIndex(aLengthParamIndex),
|
2016-11-08 02:04:06 +03:00
|
|
|
mFlag(aFlag) {}
|
|
|
|
|
2016-07-27 20:45:08 +03:00
|
|
|
ArrayData(const ArrayData& aOther) { *this = aOther; }
|
2016-11-08 02:04:06 +03:00
|
|
|
|
2016-07-27 20:45:08 +03:00
|
|
|
ArrayData& operator=(const ArrayData& aOther) {
|
|
|
|
mIid = aOther.mIid;
|
|
|
|
mMethodIndex = aOther.mMethodIndex;
|
|
|
|
mArrayParamIndex = aOther.mArrayParamIndex;
|
|
|
|
mArrayParamType = aOther.mArrayParamType;
|
|
|
|
mArrayParamIid = aOther.mArrayParamIid;
|
|
|
|
mLengthParamIndex = aOther.mLengthParamIndex;
|
2016-11-08 02:04:06 +03:00
|
|
|
mFlag = aOther.mFlag;
|
2016-07-27 20:45:08 +03:00
|
|
|
return *this;
|
|
|
|
}
|
2016-11-08 02:04:06 +03:00
|
|
|
|
2016-07-27 20:45:08 +03:00
|
|
|
IID mIid;
|
|
|
|
ULONG mMethodIndex;
|
|
|
|
ULONG mArrayParamIndex;
|
|
|
|
VARTYPE mArrayParamType;
|
|
|
|
IID mArrayParamIid;
|
|
|
|
ULONG mLengthParamIndex;
|
2016-11-08 02:04:06 +03:00
|
|
|
Flag mFlag;
|
2016-07-27 20:45:08 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
void RegisterArrayData(const ArrayData* aArrayData, size_t aLength);
|
|
|
|
|
|
|
|
template <size_t N>
|
|
|
|
inline void RegisterArrayData(const ArrayData (&aData)[N]) {
|
|
|
|
RegisterArrayData(aData, N);
|
|
|
|
}
|
|
|
|
|
|
|
|
const ArrayData* FindArrayData(REFIID aIid, ULONG aMethodIndex);
|
2017-02-16 00:37:20 +03:00
|
|
|
|
2016-07-27 20:45:08 +03:00
|
|
|
#endif // defined(MOZILLA_INTERNAL_API)
|
|
|
|
|
|
|
|
} // namespace mscom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_mscom_Registration_h
|