2016-07-15 01:55:31 +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_Utils_h
|
|
|
|
#define mozilla_mscom_Utils_h
|
|
|
|
|
2017-05-05 00:41:35 +03:00
|
|
|
#if defined(MOZILLA_INTERNAL_API)
|
|
|
|
# include "nsString.h"
|
|
|
|
#endif // defined(MOZILLA_INTERNAL_API)
|
|
|
|
|
2018-07-02 08:17:12 +03:00
|
|
|
#include "mozilla/Attributes.h"
|
2017-02-11 00:16:29 +03:00
|
|
|
#include <guiddef.h>
|
|
|
|
|
2017-08-22 19:48:12 +03:00
|
|
|
struct IStream;
|
2016-07-15 01:55:31 +03:00
|
|
|
struct IUnknown;
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace mscom {
|
|
|
|
|
2018-09-12 21:56:10 +03:00
|
|
|
bool IsCOMInitializedOnCurrentThread();
|
2016-07-18 22:47:34 +03:00
|
|
|
bool IsCurrentThreadMTA();
|
2019-08-27 04:48:08 +03:00
|
|
|
bool IsCurrentThreadExplicitMTA();
|
|
|
|
bool IsCurrentThreadImplicitMTA();
|
2016-07-15 01:55:31 +03:00
|
|
|
bool IsProxy(IUnknown* aUnknown);
|
2017-03-14 20:04:46 +03:00
|
|
|
bool IsValidGUID(REFGUID aCheckGuid);
|
2017-06-13 23:50:05 +03:00
|
|
|
uintptr_t GetContainingModuleHandle();
|
2017-02-21 23:27:18 +03:00
|
|
|
|
2017-08-22 19:48:12 +03:00
|
|
|
/**
|
|
|
|
* Given a buffer, create a new IStream object.
|
|
|
|
* @param aBuf Buffer containing data to initialize the stream. This parameter
|
|
|
|
* may be nullptr, causing the stream to be created with aBufLen
|
|
|
|
* bytes of uninitialized data.
|
|
|
|
* @param aBufLen Length of data in aBuf, or desired stream size if aBuf is
|
|
|
|
* nullptr.
|
|
|
|
* @param aOutStream Outparam to receive the newly created stream.
|
|
|
|
* @return HRESULT error code.
|
|
|
|
*/
|
|
|
|
uint32_t CreateStream(const uint8_t* aBuf, const uint32_t aBufLen,
|
|
|
|
IStream** aOutStream);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a deep copy of a proxy contained in a stream.
|
|
|
|
* @param aInStream Stream containing the proxy to copy. Its seek pointer must
|
|
|
|
* be positioned to point at the beginning of the proxy data.
|
|
|
|
* @param aOutStream Outparam to receive the newly created stream.
|
|
|
|
* @return HRESULT error code.
|
|
|
|
*/
|
|
|
|
uint32_t CopySerializedProxy(IStream* aInStream, IStream** aOutStream);
|
|
|
|
|
2017-05-05 00:41:35 +03:00
|
|
|
#if defined(MOZILLA_INTERNAL_API)
|
2019-09-04 02:58:39 +03:00
|
|
|
/**
|
|
|
|
* Checks the registry to see if |aClsid| is a thread-aware in-process server.
|
|
|
|
*
|
|
|
|
* In DCOM, an in-process server is a server that is implemented inside a DLL
|
|
|
|
* that is loaded into the client's process for execution. If |aClsid| declares
|
|
|
|
* itself to be a local server (that is, a server that resides in another
|
|
|
|
* process), this function returns false.
|
|
|
|
*
|
|
|
|
* For the server to be thread-aware, its registry entry must declare a
|
|
|
|
* ThreadingModel that is one of "Free", "Both", or "Neutral". If the threading
|
|
|
|
* model is "Apartment" or some other, invalid value, the class is treated as
|
|
|
|
* being single-threaded.
|
|
|
|
*
|
|
|
|
* NB: This function cannot check CLSIDs that were registered via manifests,
|
|
|
|
* as unfortunately there is not a documented API available to query for those.
|
|
|
|
* This should not be an issue for most CLSIDs that Gecko is interested in, as
|
|
|
|
* we typically instantiate system CLSIDs which are available in the registry.
|
|
|
|
*
|
|
|
|
* @param aClsid The CLSID of the COM class to be checked.
|
|
|
|
* @return true if the class meets the above criteria, otherwise false.
|
|
|
|
*/
|
|
|
|
bool IsClassThreadAwareInprocServer(REFCLSID aClsid);
|
|
|
|
|
2017-05-05 00:41:35 +03:00
|
|
|
void GUIDToString(REFGUID aGuid, nsAString& aOutString);
|
|
|
|
#endif // defined(MOZILLA_INTERNAL_API)
|
|
|
|
|
|
|
|
#if defined(ACCESSIBILITY)
|
2017-02-11 00:16:29 +03:00
|
|
|
bool IsVtableIndexFromParentInterface(REFIID aInterface,
|
|
|
|
unsigned long aVtableIndex);
|
2017-06-13 23:50:05 +03:00
|
|
|
|
2017-06-07 02:35:51 +03:00
|
|
|
# if defined(MOZILLA_INTERNAL_API)
|
2017-08-28 21:27:28 +03:00
|
|
|
bool IsCallerExternalProcess();
|
|
|
|
|
2017-02-11 00:16:29 +03:00
|
|
|
bool IsInterfaceEqualToOrInheritedFrom(REFIID aInterface, REFIID aFrom,
|
|
|
|
unsigned long aVtableIndexHint);
|
2017-06-07 02:35:51 +03:00
|
|
|
# endif // defined(MOZILLA_INTERNAL_API)
|
2017-06-13 23:50:05 +03:00
|
|
|
|
2017-05-05 00:41:35 +03:00
|
|
|
#endif // defined(ACCESSIBILITY)
|
2016-07-15 01:55:31 +03:00
|
|
|
|
2018-07-02 08:17:12 +03:00
|
|
|
/**
|
|
|
|
* Execute cleanup code when going out of scope if a condition is met.
|
|
|
|
* This is useful when, for example, particular cleanup needs to be performed
|
|
|
|
* whenever a call returns a failure HRESULT.
|
|
|
|
* Both the condition and cleanup code are provided as functions (usually
|
|
|
|
* lambdas).
|
|
|
|
*/
|
|
|
|
template <typename CondFnT, typename ExeFnT>
|
|
|
|
class MOZ_RAII ExecuteWhen final {
|
|
|
|
public:
|
|
|
|
ExecuteWhen(CondFnT& aCondFn, ExeFnT& aExeFn)
|
|
|
|
: mCondFn(aCondFn), mExeFn(aExeFn) {}
|
|
|
|
|
|
|
|
~ExecuteWhen() {
|
|
|
|
if (mCondFn()) {
|
|
|
|
mExeFn();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ExecuteWhen(const ExecuteWhen&) = delete;
|
|
|
|
ExecuteWhen(ExecuteWhen&&) = delete;
|
|
|
|
ExecuteWhen& operator=(const ExecuteWhen&) = delete;
|
|
|
|
ExecuteWhen& operator=(ExecuteWhen&&) = delete;
|
|
|
|
|
|
|
|
private:
|
|
|
|
CondFnT& mCondFn;
|
|
|
|
ExeFnT& mExeFn;
|
|
|
|
};
|
|
|
|
|
2016-07-15 01:55:31 +03:00
|
|
|
} // namespace mscom
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_mscom_Utils_h
|