mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-02-15 04:39:31 +00:00
Bug 1570701: Part 1 - Add IsClassThreadAwareInprocServer utility function to MSCOM; r=Jamie
We want to ensure that the code being added in part 2 is only used when it is reasonable and safe to do so. One way to ensure this is to add a check that the desired CLSID is an in-process, thread-aware server. Differential Revision: https://phabricator.services.mozilla.com/D44518 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
10b0ee6e66
commit
b36ad40063
@ -414,5 +414,43 @@ bool IsInterfaceEqualToOrInheritedFrom(REFIID aInterface, REFIID aFrom,
|
||||
|
||||
#endif // defined(ACCESSIBILITY)
|
||||
|
||||
#if defined(MOZILLA_INTERNAL_API)
|
||||
bool IsClassThreadAwareInprocServer(REFCLSID aClsid) {
|
||||
nsAutoString strClsid;
|
||||
GUIDToString(aClsid, strClsid);
|
||||
|
||||
nsAutoString inprocServerSubkey(NS_LITERAL_STRING("CLSID\\"));
|
||||
inprocServerSubkey.Append(strClsid);
|
||||
inprocServerSubkey.Append(NS_LITERAL_STRING("\\InprocServer32"));
|
||||
|
||||
// Of the possible values, "Apartment" is the longest, so we'll make this
|
||||
// buffer large enough to hold that one.
|
||||
wchar_t threadingModelBuf[ArrayLength(L"Apartment")] = {};
|
||||
|
||||
DWORD numBytes = sizeof(threadingModelBuf);
|
||||
LONG result = ::RegGetValueW(HKEY_CLASSES_ROOT, inprocServerSubkey.get(),
|
||||
L"ThreadingModel", RRF_RT_REG_SZ, nullptr,
|
||||
threadingModelBuf, &numBytes);
|
||||
if (result != ERROR_SUCCESS) {
|
||||
// This will also handle the case where the CLSID is not an inproc server.
|
||||
return false;
|
||||
}
|
||||
|
||||
DWORD numChars = numBytes / sizeof(wchar_t);
|
||||
// numChars includes the null terminator
|
||||
if (numChars <= 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
nsDependentString threadingModel(threadingModelBuf, numChars - 1);
|
||||
|
||||
// Ensure that the threading model is one of the known values that indicates
|
||||
// that the class can operate natively (ie, no proxying) inside a MTA.
|
||||
return threadingModel.EqualsLiteral("Both") ||
|
||||
threadingModel.EqualsLiteral("Free") ||
|
||||
threadingModel.EqualsLiteral("Neutral");
|
||||
}
|
||||
#endif // defined(MOZILLA_INTERNAL_API)
|
||||
|
||||
} // namespace mscom
|
||||
} // namespace mozilla
|
||||
|
@ -51,6 +51,29 @@ uint32_t CreateStream(const uint8_t* aBuf, const uint32_t aBufLen,
|
||||
uint32_t CopySerializedProxy(IStream* aInStream, IStream** aOutStream);
|
||||
|
||||
#if defined(MOZILLA_INTERNAL_API)
|
||||
/**
|
||||
* 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);
|
||||
|
||||
void GUIDToString(REFGUID aGuid, nsAString& aOutString);
|
||||
#endif // defined(MOZILLA_INTERNAL_API)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user