2016-07-27 20:44:56 +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/. */
|
|
|
|
|
|
|
|
#define INITGUID
|
|
|
|
|
Bug 1609996 - Reorder some includes affected by the previous patches. r=froydnj
This was done by:
This was done by applying:
```
diff --git a/python/mozbuild/mozbuild/code-analysis/mach_commands.py b/python/mozbuild/mozbuild/code-analysis/mach_commands.py
index 789affde7bbf..fe33c4c7d4d1 100644
--- a/python/mozbuild/mozbuild/code-analysis/mach_commands.py
+++ b/python/mozbuild/mozbuild/code-analysis/mach_commands.py
@@ -2007,7 +2007,7 @@ class StaticAnalysis(MachCommandBase):
from subprocess import Popen, PIPE, check_output, CalledProcessError
diff_process = Popen(self._get_clang_format_diff_command(commit), stdout=PIPE)
- args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format]
+ args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format, '-sort-includes']
if not output_file:
args.append("-i")
```
Then running `./mach clang-format -c <commit-hash>`
Then undoing that patch.
Then running check_spidermonkey_style.py --fixup
Then running `./mach clang-format`
I had to fix four things:
* I needed to move <utility> back down in GuardObjects.h because I was hitting
obscure problems with our system include wrappers like this:
0:03.94 /usr/include/stdlib.h:550:14: error: exception specification in declaration does not match previous declaration
0:03.94 extern void *realloc (void *__ptr, size_t __size)
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/malloc_decls.h:53:1: note: previous declaration is here
0:03.94 MALLOC_DECL(realloc, void*, void*, size_t)
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozilla/mozalloc.h:22:32: note: expanded from macro 'MALLOC_DECL'
0:03.94 MOZ_MEMORY_API return_type name##_impl(__VA_ARGS__);
0:03.94 ^
0:03.94 <scratch space>:178:1: note: expanded from here
0:03.94 realloc_impl
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozmemory_wrap.h:142:41: note: expanded from macro 'realloc_impl'
0:03.94 #define realloc_impl mozmem_malloc_impl(realloc)
Which I really didn't feel like digging into.
* I had to restore the order of TrustOverrideUtils.h and related files in nss
because the .inc files depend on TrustOverrideUtils.h being included earlier.
* I had to add a missing include to RollingNumber.h
* Also had to partially restore include order in JsepSessionImpl.cpp to avoid
some -WError issues due to some static inline functions being defined in a
header but not used in the rest of the compilation unit.
Differential Revision: https://phabricator.services.mozilla.com/D60327
--HG--
extra : moz-landing-system : lando
2020-01-20 19:19:48 +03:00
|
|
|
#include "mozilla/mscom/Interceptor.h"
|
|
|
|
|
2020-01-20 19:18:20 +03:00
|
|
|
#include <utility>
|
Bug 1609996 - Reorder some includes affected by the previous patches. r=froydnj
This was done by:
This was done by applying:
```
diff --git a/python/mozbuild/mozbuild/code-analysis/mach_commands.py b/python/mozbuild/mozbuild/code-analysis/mach_commands.py
index 789affde7bbf..fe33c4c7d4d1 100644
--- a/python/mozbuild/mozbuild/code-analysis/mach_commands.py
+++ b/python/mozbuild/mozbuild/code-analysis/mach_commands.py
@@ -2007,7 +2007,7 @@ class StaticAnalysis(MachCommandBase):
from subprocess import Popen, PIPE, check_output, CalledProcessError
diff_process = Popen(self._get_clang_format_diff_command(commit), stdout=PIPE)
- args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format]
+ args = [sys.executable, clang_format_diff, "-p1", "-binary=%s" % clang_format, '-sort-includes']
if not output_file:
args.append("-i")
```
Then running `./mach clang-format -c <commit-hash>`
Then undoing that patch.
Then running check_spidermonkey_style.py --fixup
Then running `./mach clang-format`
I had to fix four things:
* I needed to move <utility> back down in GuardObjects.h because I was hitting
obscure problems with our system include wrappers like this:
0:03.94 /usr/include/stdlib.h:550:14: error: exception specification in declaration does not match previous declaration
0:03.94 extern void *realloc (void *__ptr, size_t __size)
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/malloc_decls.h:53:1: note: previous declaration is here
0:03.94 MALLOC_DECL(realloc, void*, void*, size_t)
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozilla/mozalloc.h:22:32: note: expanded from macro 'MALLOC_DECL'
0:03.94 MOZ_MEMORY_API return_type name##_impl(__VA_ARGS__);
0:03.94 ^
0:03.94 <scratch space>:178:1: note: expanded from here
0:03.94 realloc_impl
0:03.94 ^
0:03.94 /home/emilio/src/moz/gecko-2/obj-debug/dist/include/mozmemory_wrap.h:142:41: note: expanded from macro 'realloc_impl'
0:03.94 #define realloc_impl mozmem_malloc_impl(realloc)
Which I really didn't feel like digging into.
* I had to restore the order of TrustOverrideUtils.h and related files in nss
because the .inc files depend on TrustOverrideUtils.h being included earlier.
* I had to add a missing include to RollingNumber.h
* Also had to partially restore include order in JsepSessionImpl.cpp to avoid
some -WError issues due to some static inline functions being defined in a
header but not used in the rest of the compilation unit.
Differential Revision: https://phabricator.services.mozilla.com/D60327
--HG--
extra : moz-landing-system : lando
2020-01-20 19:19:48 +03:00
|
|
|
|
|
|
|
#include "MainThreadUtils.h"
|
|
|
|
#include "mozilla/Assertions.h"
|
|
|
|
#include "mozilla/ThreadLocal.h"
|
|
|
|
#include "mozilla/Unused.h"
|
2016-08-12 21:12:48 +03:00
|
|
|
#include "mozilla/mscom/DispatchForwarder.h"
|
2017-08-18 00:54:28 +03:00
|
|
|
#include "mozilla/mscom/FastMarshaler.h"
|
2017-03-07 03:22:43 +03:00
|
|
|
#include "mozilla/mscom/InterceptorLog.h"
|
2016-07-27 20:44:56 +03:00
|
|
|
#include "mozilla/mscom/MainThreadInvoker.h"
|
2017-06-07 02:35:51 +03:00
|
|
|
#include "mozilla/mscom/Objref.h"
|
2016-07-27 20:44:56 +03:00
|
|
|
#include "mozilla/mscom/Registration.h"
|
2016-08-30 04:55:37 +03:00
|
|
|
#include "mozilla/mscom/Utils.h"
|
2016-07-27 20:44:56 +03:00
|
|
|
#include "nsDirectoryServiceDefs.h"
|
|
|
|
#include "nsDirectoryServiceUtils.h"
|
2017-10-10 13:06:35 +03:00
|
|
|
#include "nsPrintfCString.h"
|
2017-05-18 22:04:26 +03:00
|
|
|
#include "nsRefPtrHashtable.h"
|
2016-07-27 20:44:56 +03:00
|
|
|
#include "nsThreadUtils.h"
|
2017-06-07 02:35:51 +03:00
|
|
|
#include "nsXULAppAPI.h"
|
2016-07-27 20:44:56 +03:00
|
|
|
|
2017-09-18 19:49:15 +03:00
|
|
|
#define ENSURE_HR_SUCCEEDED(hr) \
|
2018-02-09 08:28:13 +03:00
|
|
|
MOZ_ASSERT(SUCCEEDED((HRESULT)hr)); \
|
2017-07-26 00:57:18 +03:00
|
|
|
if (FAILED((HRESULT)hr)) { \
|
2017-09-18 19:49:15 +03:00
|
|
|
return hr; \
|
|
|
|
}
|
|
|
|
|
2016-07-27 20:44:56 +03:00
|
|
|
namespace mozilla {
|
|
|
|
namespace mscom {
|
2017-06-08 20:52:53 +03:00
|
|
|
namespace detail {
|
2016-07-27 20:44:56 +03:00
|
|
|
|
2017-05-18 22:04:26 +03:00
|
|
|
class LiveSet final {
|
|
|
|
public:
|
|
|
|
LiveSet() : mMutex("mozilla::mscom::LiveSet::mMutex") {}
|
|
|
|
|
|
|
|
void Lock() { mMutex.Lock(); }
|
|
|
|
|
|
|
|
void Unlock() { mMutex.Unlock(); }
|
|
|
|
|
|
|
|
void Put(IUnknown* aKey, already_AddRefed<IWeakReference> aValue) {
|
|
|
|
mMutex.AssertCurrentThreadOwns();
|
2021-02-26 12:11:46 +03:00
|
|
|
mLiveSet.InsertOrUpdate(aKey, RefPtr<IWeakReference>{std::move(aValue)});
|
2017-05-18 22:04:26 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<IWeakReference> Get(IUnknown* aKey) {
|
|
|
|
mMutex.AssertCurrentThreadOwns();
|
|
|
|
RefPtr<IWeakReference> result;
|
|
|
|
mLiveSet.Get(aKey, getter_AddRefs(result));
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Remove(IUnknown* aKey) {
|
|
|
|
mMutex.AssertCurrentThreadOwns();
|
|
|
|
mLiveSet.Remove(aKey);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
Mutex mMutex;
|
|
|
|
nsRefPtrHashtable<nsPtrHashKey<IUnknown>, IWeakReference> mLiveSet;
|
|
|
|
};
|
|
|
|
|
2017-06-08 20:52:53 +03:00
|
|
|
/**
|
|
|
|
* We don't use the normal XPCOM BaseAutoLock because we need the ability
|
|
|
|
* to explicitly Unlock.
|
|
|
|
*/
|
|
|
|
class MOZ_RAII LiveSetAutoLock final {
|
|
|
|
public:
|
|
|
|
explicit LiveSetAutoLock(LiveSet& aLiveSet) : mLiveSet(&aLiveSet) {
|
|
|
|
aLiveSet.Lock();
|
|
|
|
}
|
|
|
|
|
|
|
|
~LiveSetAutoLock() {
|
|
|
|
if (mLiveSet) {
|
|
|
|
mLiveSet->Unlock();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Unlock() {
|
|
|
|
MOZ_ASSERT(mLiveSet);
|
2018-07-09 03:24:20 +03:00
|
|
|
if (mLiveSet) {
|
|
|
|
mLiveSet->Unlock();
|
|
|
|
mLiveSet = nullptr;
|
|
|
|
}
|
2017-06-08 20:52:53 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
LiveSetAutoLock(const LiveSetAutoLock& aOther) = delete;
|
|
|
|
LiveSetAutoLock(LiveSetAutoLock&& aOther) = delete;
|
|
|
|
LiveSetAutoLock& operator=(const LiveSetAutoLock& aOther) = delete;
|
|
|
|
LiveSetAutoLock& operator=(LiveSetAutoLock&& aOther) = delete;
|
|
|
|
|
|
|
|
private:
|
|
|
|
LiveSet* mLiveSet;
|
|
|
|
};
|
|
|
|
|
2017-10-31 23:37:00 +03:00
|
|
|
class MOZ_RAII ReentrySentinel final {
|
|
|
|
public:
|
|
|
|
explicit ReentrySentinel(Interceptor* aCurrent) : mCurInterceptor(aCurrent) {
|
|
|
|
static const bool kHasTls = tlsSentinelStackTop.init();
|
|
|
|
MOZ_RELEASE_ASSERT(kHasTls);
|
|
|
|
|
|
|
|
mPrevSentinel = tlsSentinelStackTop.get();
|
|
|
|
tlsSentinelStackTop.set(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
~ReentrySentinel() { tlsSentinelStackTop.set(mPrevSentinel); }
|
|
|
|
|
|
|
|
bool IsOutermost() const {
|
|
|
|
return !(mPrevSentinel && mPrevSentinel->IsMarshaling(mCurInterceptor));
|
|
|
|
}
|
|
|
|
|
|
|
|
ReentrySentinel(const ReentrySentinel&) = delete;
|
|
|
|
ReentrySentinel(ReentrySentinel&&) = delete;
|
|
|
|
ReentrySentinel& operator=(const ReentrySentinel&) = delete;
|
|
|
|
ReentrySentinel& operator=(ReentrySentinel&&) = delete;
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool IsMarshaling(Interceptor* aTopInterceptor) const {
|
|
|
|
return aTopInterceptor == mCurInterceptor ||
|
|
|
|
(mPrevSentinel && mPrevSentinel->IsMarshaling(aTopInterceptor));
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
Interceptor* mCurInterceptor;
|
|
|
|
ReentrySentinel* mPrevSentinel;
|
|
|
|
|
|
|
|
static MOZ_THREAD_LOCAL(ReentrySentinel*) tlsSentinelStackTop;
|
|
|
|
};
|
|
|
|
|
|
|
|
MOZ_THREAD_LOCAL(ReentrySentinel*) ReentrySentinel::tlsSentinelStackTop;
|
|
|
|
|
|
|
|
class MOZ_RAII LoggedQIResult final {
|
|
|
|
public:
|
|
|
|
explicit LoggedQIResult(REFIID aIid)
|
|
|
|
: mIid(aIid),
|
|
|
|
mHr(E_UNEXPECTED),
|
|
|
|
mTarget(nullptr),
|
|
|
|
mInterceptor(nullptr),
|
|
|
|
mBegin(TimeStamp::Now()) {}
|
|
|
|
|
|
|
|
~LoggedQIResult() {
|
|
|
|
if (!mTarget) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
TimeStamp end(TimeStamp::Now());
|
|
|
|
TimeDuration total(end - mBegin);
|
|
|
|
TimeDuration overhead(total - mNonOverheadDuration);
|
|
|
|
|
|
|
|
InterceptorLog::QI(mHr, mTarget, mIid, mInterceptor, &overhead,
|
|
|
|
&mNonOverheadDuration);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Log(IUnknown* aTarget, IUnknown* aInterceptor) {
|
|
|
|
mTarget = aTarget;
|
|
|
|
mInterceptor = aInterceptor;
|
|
|
|
}
|
|
|
|
|
|
|
|
void operator=(HRESULT aHr) { mHr = aHr; }
|
|
|
|
|
|
|
|
operator HRESULT() { return mHr; }
|
|
|
|
|
|
|
|
operator TimeDuration*() { return &mNonOverheadDuration; }
|
|
|
|
|
|
|
|
LoggedQIResult(const LoggedQIResult&) = delete;
|
|
|
|
LoggedQIResult(LoggedQIResult&&) = delete;
|
|
|
|
LoggedQIResult& operator=(const LoggedQIResult&) = delete;
|
|
|
|
LoggedQIResult& operator=(LoggedQIResult&&) = delete;
|
|
|
|
|
|
|
|
private:
|
|
|
|
REFIID mIid;
|
|
|
|
HRESULT mHr;
|
|
|
|
IUnknown* mTarget;
|
|
|
|
IUnknown* mInterceptor;
|
|
|
|
TimeDuration mNonOverheadDuration;
|
|
|
|
TimeStamp mBegin;
|
|
|
|
};
|
|
|
|
|
2017-06-08 20:52:53 +03:00
|
|
|
} // namespace detail
|
|
|
|
|
|
|
|
static detail::LiveSet& GetLiveSet() {
|
|
|
|
static detail::LiveSet sLiveSet;
|
2017-05-18 22:04:26 +03:00
|
|
|
return sLiveSet;
|
|
|
|
}
|
|
|
|
|
2018-03-06 10:08:15 +03:00
|
|
|
MOZ_THREAD_LOCAL(bool) Interceptor::tlsCreatingStdMarshal;
|
|
|
|
|
2019-02-26 01:08:36 +03:00
|
|
|
/* static */
|
|
|
|
HRESULT Interceptor::Create(STAUniquePtr<IUnknown> aTarget,
|
|
|
|
IInterceptorSink* aSink, REFIID aInitialIid,
|
|
|
|
void** aOutInterface) {
|
2017-06-07 03:30:19 +03:00
|
|
|
MOZ_ASSERT(aOutInterface && aTarget && aSink);
|
|
|
|
if (!aOutInterface) {
|
2016-07-27 20:44:56 +03:00
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
2017-02-18 03:35:01 +03:00
|
|
|
|
2017-06-08 20:52:53 +03:00
|
|
|
detail::LiveSetAutoLock lock(GetLiveSet());
|
2017-05-18 22:04:26 +03:00
|
|
|
|
2018-07-04 00:04:27 +03:00
|
|
|
RefPtr<IWeakReference> existingWeak(GetLiveSet().Get(aTarget.get()));
|
2017-06-08 20:52:53 +03:00
|
|
|
if (existingWeak) {
|
|
|
|
RefPtr<IWeakReferenceSource> existingStrong;
|
|
|
|
if (SUCCEEDED(existingWeak->ToStrongRef(getter_AddRefs(existingStrong)))) {
|
|
|
|
// QI on existingStrong may touch other threads. Since we now hold a
|
|
|
|
// strong ref on the interceptor, we may now release the lock.
|
|
|
|
lock.Unlock();
|
|
|
|
return existingStrong->QueryInterface(aInitialIid, aOutInterface);
|
|
|
|
}
|
2017-05-18 22:04:26 +03:00
|
|
|
}
|
|
|
|
|
2017-06-07 03:30:19 +03:00
|
|
|
*aOutInterface = nullptr;
|
2017-02-18 03:35:01 +03:00
|
|
|
|
2016-07-27 20:44:56 +03:00
|
|
|
if (!aTarget || !aSink) {
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
2017-02-18 03:35:01 +03:00
|
|
|
|
2017-06-07 03:30:19 +03:00
|
|
|
RefPtr<Interceptor> intcpt(new Interceptor(aSink));
|
2018-05-30 22:15:35 +03:00
|
|
|
return intcpt->GetInitialInterceptorForIID(lock, aInitialIid,
|
|
|
|
std::move(aTarget), aOutInterface);
|
2016-07-27 20:44:56 +03:00
|
|
|
}
|
|
|
|
|
2017-06-07 03:30:19 +03:00
|
|
|
Interceptor::Interceptor(IInterceptorSink* aSink)
|
2016-07-27 20:44:56 +03:00
|
|
|
: WeakReferenceSupport(WeakReferenceSupport::Flags::eDestroyOnMainThread),
|
|
|
|
mEventSink(aSink),
|
2018-01-13 00:17:18 +03:00
|
|
|
mInterceptorMapMutex("mozilla::mscom::Interceptor::mInterceptorMapMutex"),
|
|
|
|
mStdMarshalMutex("mozilla::mscom::Interceptor::mStdMarshalMutex"),
|
2017-02-18 03:30:03 +03:00
|
|
|
mStdMarshal(nullptr) {
|
2018-03-06 10:08:15 +03:00
|
|
|
static const bool kHasTls = tlsCreatingStdMarshal.init();
|
|
|
|
MOZ_ASSERT(kHasTls);
|
2018-10-10 07:31:35 +03:00
|
|
|
Unused << kHasTls;
|
2018-03-06 10:08:15 +03:00
|
|
|
|
2016-07-27 20:44:56 +03:00
|
|
|
MOZ_ASSERT(aSink);
|
|
|
|
RefPtr<IWeakReference> weakRef;
|
|
|
|
if (SUCCEEDED(GetWeakReference(getter_AddRefs(weakRef)))) {
|
|
|
|
aSink->SetInterceptor(weakRef);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Interceptor::~Interceptor() {
|
2017-05-18 22:04:26 +03:00
|
|
|
{ // Scope for lock
|
2017-06-08 20:52:53 +03:00
|
|
|
detail::LiveSetAutoLock lock(GetLiveSet());
|
2017-05-18 22:04:26 +03:00
|
|
|
GetLiveSet().Remove(mTarget.get());
|
|
|
|
}
|
|
|
|
|
2016-07-27 20:44:56 +03:00
|
|
|
// This needs to run on the main thread because it releases target interface
|
|
|
|
// reference counts which may not be thread-safe.
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
for (uint32_t index = 0, len = mInterceptorMap.Length(); index < len;
|
|
|
|
++index) {
|
|
|
|
MapEntry& entry = mInterceptorMap[index];
|
2016-12-14 09:34:26 +03:00
|
|
|
entry.mInterceptor = nullptr;
|
2016-07-27 20:44:56 +03:00
|
|
|
entry.mTargetInterface->Release();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-18 03:30:03 +03:00
|
|
|
HRESULT
|
|
|
|
Interceptor::GetClassForHandler(DWORD aDestContext, void* aDestContextPtr,
|
|
|
|
CLSID* aHandlerClsid) {
|
|
|
|
if (aDestContextPtr || !aHandlerClsid ||
|
|
|
|
aDestContext == MSHCTX_DIFFERENTMACHINE) {
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
2017-06-07 02:35:51 +03:00
|
|
|
|
2017-02-18 03:30:03 +03:00
|
|
|
MOZ_ASSERT(mEventSink);
|
Bug 1303060: Changes to a11y to enable the serving of a COM handler; r=tbsaunde
MozReview-Commit-ID: GTQF3x1pBtX
A general outline of the COM handler (a.k.a. the "smart proxy"):
COM handlers are pieces of code that are loaded by the COM runtime along with
a proxy and are layered above that proxy. This enables the COM handler to
interpose itself between the caller and the proxy, thus providing the
opportunity for the handler to manipulate an interface's method calls before
those calls reach the proxy.
Handlers are regular COM components that live in DLLs and are declared in the
Windows registry. In order to allow for the specifying of a handler (and an
optional payload to be sent with the proxy), the mscom library allows its
clients to specify an implementation of the IHandlerProvider interface.
IHandlerProvider consists of 5 functions:
* GetHandler returns the CLSID of the component that should be loaded into
the COM client's process. If GetHandler returns a failure code, then no
handler is loaded.
* GetHandlerPayloadSize and WriteHandlerPayload are for obtaining the payload
data. These calls are made on a background thread but need to do their work
on the main thread. We declare the payload struct in IDL. MIDL generates two
functions, IA2Payload_Encode and IA2Payload_Decode, which are used by
mscom::StructToStream to read and write that struct to and from buffers.
* The a11y payload struct also includes an interface, IGeckoBackChannel, that
allows the handler to communicate directly with Gecko. IGeckoBackChannel
currently provides two methods: one to allow the handler to request fresh
cache information, and the other to provide Gecko with its IHandlerControl
interface.
* MarshalAs accepts an IID that specifies the interface that is about to be
proxied. We may want to send a more sophisticated proxy than the one that
is requested. The desired IID is returned by this function. In the case of
a11y interfaces, we should always return IAccessible2_3 if we are asked for
one of its parent interfaces. This allows us to eliminate round trips to
resolve more sophisticated interfaces later on.
* NewInstance, which is needed to ensure that all descendent proxies are also
imbued with the same handler code.
The main focus of this patch is as follows:
1. Provide an implementation of the IHandlerProvider interface;
2. Populate the handler payload (ie, the cache) with data;
3. Modify CreateHolderFromAccessible to specify the HandlerPayload object;
4. Receive the IHandlerControl interface from the handler DLL and move it
into the chrome process.
Some more information about IHandlerControl:
There is one IHandlerControl per handler DLL instance. It is the interface that
we call in Gecko when we need to dispatch an event to the handler. In order to
ensure that events are dispatched in the correct order, we need to dispatch
those events from the chrome main thread so that they occur in sequential order
with calls to NotifyWinEvent.
--HG--
extra : rebase_source : acb44dead7cc5488424720e1bf58862b7b30374f
2017-04-05 00:23:55 +03:00
|
|
|
return mEventSink->GetHandler(WrapNotNull(aHandlerClsid));
|
2017-02-18 03:30:03 +03:00
|
|
|
}
|
|
|
|
|
2017-09-22 01:53:56 +03:00
|
|
|
REFIID
|
|
|
|
Interceptor::MarshalAs(REFIID aIid) const {
|
|
|
|
#if defined(MOZ_MSCOM_REMARSHAL_NO_HANDLER)
|
|
|
|
return IsCallerExternalProcess() ? aIid : mEventSink->MarshalAs(aIid);
|
|
|
|
#else
|
|
|
|
return mEventSink->MarshalAs(aIid);
|
|
|
|
#endif // defined(MOZ_MSCOM_REMARSHAL_NO_HANDLER)
|
|
|
|
}
|
|
|
|
|
2017-02-18 03:30:03 +03:00
|
|
|
HRESULT
|
|
|
|
Interceptor::GetUnmarshalClass(REFIID riid, void* pv, DWORD dwDestContext,
|
|
|
|
void* pvDestContext, DWORD mshlflags,
|
|
|
|
CLSID* pCid) {
|
2017-09-22 01:53:56 +03:00
|
|
|
return mStdMarshal->GetUnmarshalClass(MarshalAs(riid), pv, dwDestContext,
|
|
|
|
pvDestContext, mshlflags, pCid);
|
2017-02-18 03:30:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT
|
|
|
|
Interceptor::GetMarshalSizeMax(REFIID riid, void* pv, DWORD dwDestContext,
|
|
|
|
void* pvDestContext, DWORD mshlflags,
|
|
|
|
DWORD* pSize) {
|
2017-10-31 23:37:00 +03:00
|
|
|
detail::ReentrySentinel sentinel(this);
|
|
|
|
|
2017-09-22 01:53:56 +03:00
|
|
|
HRESULT hr = mStdMarshal->GetMarshalSizeMax(
|
|
|
|
MarshalAs(riid), pv, dwDestContext, pvDestContext, mshlflags, pSize);
|
2017-10-31 23:37:00 +03:00
|
|
|
if (FAILED(hr) || !sentinel.IsOutermost()) {
|
2017-02-18 03:30:03 +03:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2020-04-28 19:21:58 +03:00
|
|
|
#if defined(MOZ_MSCOM_REMARSHAL_NO_HANDLER)
|
|
|
|
if (XRE_IsContentProcess() && IsCallerExternalProcess()) {
|
|
|
|
// The caller isn't our chrome process, so we do not provide a handler
|
|
|
|
// payload. Even though we're only getting the size here, calculating the
|
|
|
|
// payload size might actually require building the payload.
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
#endif // defined(MOZ_MSCOM_REMARSHAL_NO_HANDLER)
|
|
|
|
|
2017-02-18 03:30:03 +03:00
|
|
|
DWORD payloadSize = 0;
|
2017-10-25 02:48:51 +03:00
|
|
|
hr = mEventSink->GetHandlerPayloadSize(WrapNotNull(this),
|
|
|
|
WrapNotNull(&payloadSize));
|
2017-08-02 00:11:34 +03:00
|
|
|
if (hr == E_NOTIMPL) {
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (SUCCEEDED(hr)) {
|
|
|
|
*pSize += payloadSize;
|
|
|
|
}
|
2017-02-18 03:30:03 +03:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT
|
|
|
|
Interceptor::MarshalInterface(IStream* pStm, REFIID riid, void* pv,
|
|
|
|
DWORD dwDestContext, void* pvDestContext,
|
|
|
|
DWORD mshlflags) {
|
2017-10-31 23:37:00 +03:00
|
|
|
detail::ReentrySentinel sentinel(this);
|
|
|
|
|
2017-06-07 02:35:51 +03:00
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
#if defined(MOZ_MSCOM_REMARSHAL_NO_HANDLER)
|
|
|
|
// Save the current stream position
|
|
|
|
LARGE_INTEGER seekTo;
|
|
|
|
seekTo.QuadPart = 0;
|
|
|
|
|
|
|
|
ULARGE_INTEGER objrefPos;
|
|
|
|
|
|
|
|
hr = pStm->Seek(seekTo, STREAM_SEEK_CUR, &objrefPos);
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif // defined(MOZ_MSCOM_REMARSHAL_NO_HANDLER)
|
|
|
|
|
2017-09-22 01:53:56 +03:00
|
|
|
hr = mStdMarshal->MarshalInterface(pStm, MarshalAs(riid), pv, dwDestContext,
|
2017-08-18 00:54:28 +03:00
|
|
|
pvDestContext, mshlflags);
|
2017-10-31 23:37:00 +03:00
|
|
|
if (FAILED(hr) || !sentinel.IsOutermost()) {
|
2017-02-18 03:30:03 +03:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2017-06-07 02:35:51 +03:00
|
|
|
#if defined(MOZ_MSCOM_REMARSHAL_NO_HANDLER)
|
2017-08-18 00:54:28 +03:00
|
|
|
if (XRE_IsContentProcess() && IsCallerExternalProcess()) {
|
|
|
|
// The caller isn't our chrome process, so do not provide a handler.
|
2017-06-07 02:35:51 +03:00
|
|
|
|
2017-08-18 00:54:28 +03:00
|
|
|
// First, save the current position that marks the current end of the
|
|
|
|
// OBJREF in the stream.
|
|
|
|
ULARGE_INTEGER endPos;
|
|
|
|
hr = pStm->Seek(seekTo, STREAM_SEEK_CUR, &endPos);
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
return hr;
|
|
|
|
}
|
2017-06-07 02:35:51 +03:00
|
|
|
|
2017-08-18 00:54:28 +03:00
|
|
|
// Now strip out the handler.
|
|
|
|
if (!StripHandlerFromOBJREF(WrapNotNull(pStm), objrefPos.QuadPart,
|
|
|
|
endPos.QuadPart)) {
|
|
|
|
return E_FAIL;
|
2017-06-07 02:35:51 +03:00
|
|
|
}
|
2017-08-18 00:54:28 +03:00
|
|
|
|
|
|
|
return S_OK;
|
2017-06-07 02:35:51 +03:00
|
|
|
}
|
|
|
|
#endif // defined(MOZ_MSCOM_REMARSHAL_NO_HANDLER)
|
|
|
|
|
2017-10-25 02:48:51 +03:00
|
|
|
hr = mEventSink->WriteHandlerPayload(WrapNotNull(this), WrapNotNull(pStm));
|
2017-08-02 00:11:34 +03:00
|
|
|
if (hr == E_NOTIMPL) {
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return hr;
|
2017-02-18 03:30:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT
|
|
|
|
Interceptor::UnmarshalInterface(IStream* pStm, REFIID riid, void** ppv) {
|
|
|
|
return mStdMarshal->UnmarshalInterface(pStm, riid, ppv);
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT
|
|
|
|
Interceptor::ReleaseMarshalData(IStream* pStm) {
|
|
|
|
return mStdMarshal->ReleaseMarshalData(pStm);
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT
|
|
|
|
Interceptor::DisconnectObject(DWORD dwReserved) {
|
2018-02-19 09:08:57 +03:00
|
|
|
mEventSink->DisconnectHandlerRemotes();
|
2017-02-18 03:30:03 +03:00
|
|
|
return mStdMarshal->DisconnectObject(dwReserved);
|
|
|
|
}
|
|
|
|
|
2016-07-27 20:44:56 +03:00
|
|
|
Interceptor::MapEntry* Interceptor::Lookup(REFIID aIid) {
|
2018-01-13 00:17:18 +03:00
|
|
|
mInterceptorMapMutex.AssertCurrentThreadOwns();
|
2017-08-31 01:34:43 +03:00
|
|
|
|
2016-07-27 20:44:56 +03:00
|
|
|
for (uint32_t index = 0, len = mInterceptorMap.Length(); index < len;
|
|
|
|
++index) {
|
|
|
|
if (mInterceptorMap[index].mIID == aIid) {
|
|
|
|
return &mInterceptorMap[index];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT
|
2017-03-07 03:22:43 +03:00
|
|
|
Interceptor::GetTargetForIID(REFIID aIid,
|
|
|
|
InterceptorTargetPtr<IUnknown>& aTarget) {
|
2018-01-13 00:17:18 +03:00
|
|
|
MutexAutoLock lock(mInterceptorMapMutex);
|
2016-07-27 20:44:56 +03:00
|
|
|
MapEntry* entry = Lookup(aIid);
|
|
|
|
if (entry) {
|
|
|
|
aTarget.reset(entry->mTargetInterface);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
2017-03-07 03:22:43 +03:00
|
|
|
// CoGetInterceptor requires type metadata to be able to generate its emulated
|
|
|
|
// vtable. If no registered metadata is available, CoGetInterceptor returns
|
|
|
|
// kFileNotFound.
|
|
|
|
static const HRESULT kFileNotFound = HRESULT_FROM_WIN32(ERROR_FILE_NOT_FOUND);
|
2016-07-27 20:44:56 +03:00
|
|
|
|
|
|
|
HRESULT
|
|
|
|
Interceptor::CreateInterceptor(REFIID aIid, IUnknown* aOuter,
|
|
|
|
IUnknown** aOutput) {
|
|
|
|
// In order to aggregate, we *must* request IID_IUnknown as the initial
|
|
|
|
// interface for the interceptor, as that IUnknown is non-delegating.
|
|
|
|
// This is a fundamental rule for creating aggregated objects in COM.
|
|
|
|
HRESULT hr = ::CoGetInterceptor(aIid, aOuter, IID_IUnknown, (void**)aOutput);
|
|
|
|
if (hr != kFileNotFound) {
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// In the case that CoGetInterceptor returns kFileNotFound, we can try to
|
|
|
|
// explicitly load typelib data from our runtime registration facility and
|
|
|
|
// pass that into CoGetInterceptorFromTypeInfo.
|
|
|
|
|
|
|
|
RefPtr<ITypeInfo> typeInfo;
|
|
|
|
bool found = RegisteredProxy::Find(aIid, getter_AddRefs(typeInfo));
|
|
|
|
// If this assert fires then we have omitted registering the typelib for a
|
|
|
|
// required interface. To fix this, review our calls to mscom::RegisterProxy
|
|
|
|
// and mscom::RegisterTypelib, and add the additional typelib as necessary.
|
|
|
|
MOZ_ASSERT(found);
|
|
|
|
if (!found) {
|
|
|
|
return kFileNotFound;
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = ::CoGetInterceptorFromTypeInfo(aIid, aOuter, typeInfo, IID_IUnknown,
|
|
|
|
(void**)aOutput);
|
|
|
|
// If this assert fires then the interceptor doesn't like something about
|
|
|
|
// the format of the typelib. One thing in particular that it doesn't like
|
|
|
|
// is complex types that contain unions.
|
|
|
|
MOZ_ASSERT(SUCCEEDED(hr));
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2017-06-07 03:30:19 +03:00
|
|
|
HRESULT
|
2017-08-31 01:34:43 +03:00
|
|
|
Interceptor::PublishTarget(detail::LiveSetAutoLock& aLiveSetLock,
|
|
|
|
RefPtr<IUnknown> aInterceptor, REFIID aTargetIid,
|
|
|
|
STAUniquePtr<IUnknown> aTarget) {
|
|
|
|
RefPtr<IWeakReference> weakRef;
|
|
|
|
HRESULT hr = GetWeakReference(getter_AddRefs(weakRef));
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// mTarget is a weak reference to aTarget. This is safe because we transfer
|
|
|
|
// ownership of aTarget into mInterceptorMap which remains live for the
|
|
|
|
// lifetime of this Interceptor.
|
|
|
|
mTarget = ToInterceptorTargetPtr(aTarget);
|
2020-02-24 20:35:46 +03:00
|
|
|
GetLiveSet().Put(mTarget.get(), weakRef.forget());
|
2017-08-31 01:34:43 +03:00
|
|
|
|
|
|
|
// Now we transfer aTarget's ownership into mInterceptorMap.
|
|
|
|
mInterceptorMap.AppendElement(
|
|
|
|
MapEntry(aTargetIid, aInterceptor, aTarget.release()));
|
|
|
|
|
|
|
|
// Release the live set lock because subsequent operations may post work to
|
|
|
|
// the main thread, creating potential for deadlocks.
|
|
|
|
aLiveSetLock.Unlock();
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT
|
|
|
|
Interceptor::GetInitialInterceptorForIID(detail::LiveSetAutoLock& aLiveSetLock,
|
2017-06-08 20:52:53 +03:00
|
|
|
REFIID aTargetIid,
|
2017-06-07 03:30:19 +03:00
|
|
|
STAUniquePtr<IUnknown> aTarget,
|
|
|
|
void** aOutInterceptor) {
|
|
|
|
MOZ_ASSERT(aOutInterceptor);
|
2017-08-31 01:34:43 +03:00
|
|
|
MOZ_ASSERT(aTargetIid != IID_IMarshal);
|
2017-06-07 03:30:19 +03:00
|
|
|
MOZ_ASSERT(!IsProxy(aTarget.get()));
|
|
|
|
|
2018-07-02 08:17:12 +03:00
|
|
|
HRESULT hr = E_UNEXPECTED;
|
|
|
|
|
|
|
|
auto hasFailed = [&hr]() -> bool { return FAILED(hr); };
|
|
|
|
|
|
|
|
auto cleanup = [&aLiveSetLock]() -> void { aLiveSetLock.Unlock(); };
|
|
|
|
|
|
|
|
ExecuteWhen<decltype(hasFailed), decltype(cleanup)> onFail(hasFailed,
|
|
|
|
cleanup);
|
|
|
|
|
2017-08-31 01:34:43 +03:00
|
|
|
if (aTargetIid == IID_IUnknown) {
|
2018-01-13 00:17:18 +03:00
|
|
|
// We must lock mInterceptorMapMutex so that nothing can race with us once
|
|
|
|
// we have been published to the live set.
|
|
|
|
MutexAutoLock lock(mInterceptorMapMutex);
|
2017-08-31 01:34:43 +03:00
|
|
|
|
2018-07-02 08:17:12 +03:00
|
|
|
hr = PublishTarget(aLiveSetLock, nullptr, aTargetIid, std::move(aTarget));
|
2017-09-18 19:49:15 +03:00
|
|
|
ENSURE_HR_SUCCEEDED(hr);
|
2017-08-31 01:34:43 +03:00
|
|
|
|
2017-09-18 19:49:15 +03:00
|
|
|
hr = QueryInterface(aTargetIid, aOutInterceptor);
|
|
|
|
ENSURE_HR_SUCCEEDED(hr);
|
|
|
|
return hr;
|
2017-08-31 01:34:43 +03:00
|
|
|
}
|
|
|
|
|
2017-06-07 03:30:19 +03:00
|
|
|
// Raise the refcount for stabilization purposes during aggregation
|
2018-01-25 23:45:21 +03:00
|
|
|
WeakReferenceSupport::StabilizeRefCount stabilizer(*this);
|
2017-06-07 03:30:19 +03:00
|
|
|
|
|
|
|
RefPtr<IUnknown> unkInterceptor;
|
2018-01-25 23:45:21 +03:00
|
|
|
hr = CreateInterceptor(aTargetIid, static_cast<WeakReferenceSupport*>(this),
|
2017-06-07 03:30:19 +03:00
|
|
|
getter_AddRefs(unkInterceptor));
|
2017-09-18 19:49:15 +03:00
|
|
|
ENSURE_HR_SUCCEEDED(hr);
|
2017-06-07 03:30:19 +03:00
|
|
|
|
|
|
|
RefPtr<ICallInterceptor> interceptor;
|
|
|
|
hr = unkInterceptor->QueryInterface(IID_ICallInterceptor,
|
|
|
|
getter_AddRefs(interceptor));
|
2017-09-18 19:49:15 +03:00
|
|
|
ENSURE_HR_SUCCEEDED(hr);
|
2017-06-07 03:30:19 +03:00
|
|
|
|
|
|
|
hr = interceptor->RegisterSink(mEventSink);
|
2017-09-18 19:49:15 +03:00
|
|
|
ENSURE_HR_SUCCEEDED(hr);
|
2017-06-07 03:30:19 +03:00
|
|
|
|
2018-01-13 00:17:18 +03:00
|
|
|
// We must lock mInterceptorMapMutex so that nothing can race with us once we
|
|
|
|
// have been published to the live set.
|
|
|
|
MutexAutoLock lock(mInterceptorMapMutex);
|
2017-08-31 01:34:43 +03:00
|
|
|
|
2018-05-30 22:15:35 +03:00
|
|
|
hr = PublishTarget(aLiveSetLock, unkInterceptor, aTargetIid,
|
|
|
|
std::move(aTarget));
|
2017-09-18 19:49:15 +03:00
|
|
|
ENSURE_HR_SUCCEEDED(hr);
|
2017-05-18 22:04:26 +03:00
|
|
|
|
2017-09-22 01:53:56 +03:00
|
|
|
if (MarshalAs(aTargetIid) == aTargetIid) {
|
2017-09-18 19:49:15 +03:00
|
|
|
hr = unkInterceptor->QueryInterface(aTargetIid, aOutInterceptor);
|
|
|
|
ENSURE_HR_SUCCEEDED(hr);
|
|
|
|
return hr;
|
2017-06-07 03:30:19 +03:00
|
|
|
}
|
|
|
|
|
2018-05-04 07:57:11 +03:00
|
|
|
hr = GetInterceptorForIID(aTargetIid, aOutInterceptor, &lock);
|
2017-09-18 19:49:15 +03:00
|
|
|
ENSURE_HR_SUCCEEDED(hr);
|
|
|
|
return hr;
|
2017-06-07 03:30:19 +03:00
|
|
|
}
|
|
|
|
|
2018-05-04 07:57:11 +03:00
|
|
|
HRESULT
|
|
|
|
Interceptor::GetInterceptorForIID(REFIID aIid, void** aOutInterceptor) {
|
|
|
|
return GetInterceptorForIID(aIid, aOutInterceptor, nullptr);
|
|
|
|
}
|
|
|
|
|
2016-07-27 20:44:56 +03:00
|
|
|
/**
|
|
|
|
* This method contains the core guts of the handling of QueryInterface calls
|
|
|
|
* that are delegated to us from the ICallInterceptor.
|
|
|
|
*
|
|
|
|
* @param aIid ID of the desired interface
|
|
|
|
* @param aOutInterceptor The resulting emulated vtable that corresponds to
|
|
|
|
* the interface specified by aIid.
|
2018-05-04 07:57:11 +03:00
|
|
|
* @param aAlreadyLocked Proof of an existing lock on |mInterceptorMapMutex|,
|
|
|
|
* if present.
|
2016-07-27 20:44:56 +03:00
|
|
|
*/
|
|
|
|
HRESULT
|
2018-05-04 07:57:11 +03:00
|
|
|
Interceptor::GetInterceptorForIID(REFIID aIid, void** aOutInterceptor,
|
|
|
|
MutexAutoLock* aAlreadyLocked) {
|
2017-10-31 23:37:00 +03:00
|
|
|
detail::LoggedQIResult result(aIid);
|
2017-07-26 00:57:18 +03:00
|
|
|
|
2016-07-27 20:44:56 +03:00
|
|
|
if (!aOutInterceptor) {
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
2016-08-18 18:48:48 +03:00
|
|
|
if (aIid == IID_IUnknown) {
|
|
|
|
// Special case: When we see IUnknown, we just provide a reference to this
|
2017-02-18 03:30:03 +03:00
|
|
|
RefPtr<IInterceptor> intcpt(this);
|
|
|
|
intcpt.forget(aOutInterceptor);
|
2016-08-18 18:48:48 +03:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2017-09-22 01:53:56 +03:00
|
|
|
REFIID interceptorIid = MarshalAs(aIid);
|
2017-02-18 03:30:03 +03:00
|
|
|
|
2016-07-27 20:44:56 +03:00
|
|
|
RefPtr<IUnknown> unkInterceptor;
|
|
|
|
IUnknown* interfaceForQILog = nullptr;
|
|
|
|
|
2017-02-18 03:30:03 +03:00
|
|
|
// (1) Check to see if we already have an existing interceptor for
|
|
|
|
// interceptorIid.
|
2018-05-04 07:57:11 +03:00
|
|
|
auto doLookup = [&]() -> void {
|
2017-02-18 03:30:03 +03:00
|
|
|
MapEntry* entry = Lookup(interceptorIid);
|
2016-07-27 20:44:56 +03:00
|
|
|
if (entry) {
|
|
|
|
unkInterceptor = entry->mInterceptor;
|
|
|
|
interfaceForQILog = entry->mTargetInterface;
|
|
|
|
}
|
2018-05-04 07:57:11 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
if (aAlreadyLocked) {
|
|
|
|
doLookup();
|
|
|
|
} else {
|
|
|
|
MutexAutoLock lock(mInterceptorMapMutex);
|
|
|
|
doLookup();
|
2016-07-27 20:44:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// (1a) A COM interceptor already exists for this interface, so all we need
|
|
|
|
// to do is run a QI on it.
|
|
|
|
if (unkInterceptor) {
|
|
|
|
// Technically we didn't actually execute a QI on the target interface, but
|
|
|
|
// for logging purposes we would like to record the fact that this interface
|
|
|
|
// was requested.
|
2017-07-26 00:57:18 +03:00
|
|
|
result.Log(mTarget.get(), interfaceForQILog);
|
|
|
|
result = unkInterceptor->QueryInterface(interceptorIid, aOutInterceptor);
|
|
|
|
ENSURE_HR_SUCCEEDED(result);
|
|
|
|
return result;
|
2016-07-27 20:44:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// (2) Obtain a new target interface.
|
|
|
|
|
|
|
|
// (2a) First, make sure that the target interface is available
|
|
|
|
// NB: We *MUST* query the correct interface! ICallEvents::Invoke casts its
|
|
|
|
// pvReceiver argument directly to the required interface! DO NOT assume
|
|
|
|
// that COM will use QI or upcast/downcast!
|
|
|
|
HRESULT hr;
|
|
|
|
|
|
|
|
STAUniquePtr<IUnknown> targetInterface;
|
|
|
|
IUnknown* rawTargetInterface = nullptr;
|
2017-07-26 00:57:18 +03:00
|
|
|
hr =
|
|
|
|
QueryInterfaceTarget(interceptorIid, (void**)&rawTargetInterface, result);
|
2016-07-27 20:44:56 +03:00
|
|
|
targetInterface.reset(rawTargetInterface);
|
2017-07-26 00:57:18 +03:00
|
|
|
result = hr;
|
|
|
|
result.Log(mTarget.get(), targetInterface.get());
|
2016-07-27 20:44:56 +03:00
|
|
|
MOZ_ASSERT(SUCCEEDED(hr) || hr == E_NOINTERFACE);
|
2017-09-20 23:40:41 +03:00
|
|
|
if (hr == E_NOINTERFACE) {
|
|
|
|
return hr;
|
|
|
|
}
|
2017-09-18 19:49:15 +03:00
|
|
|
ENSURE_HR_SUCCEEDED(hr);
|
2016-07-27 20:44:56 +03:00
|
|
|
|
|
|
|
// We *really* shouldn't be adding interceptors to proxies
|
|
|
|
MOZ_ASSERT(aIid != IID_IMarshal);
|
|
|
|
|
|
|
|
// (3) Create a new COM interceptor to that interface that delegates its
|
|
|
|
// IUnknown to |this|.
|
|
|
|
|
|
|
|
// Raise the refcount for stabilization purposes during aggregation
|
2018-01-25 23:45:21 +03:00
|
|
|
WeakReferenceSupport::StabilizeRefCount stabilizer(*this);
|
2016-07-27 20:44:56 +03:00
|
|
|
|
2018-01-25 23:45:21 +03:00
|
|
|
hr = CreateInterceptor(interceptorIid,
|
|
|
|
static_cast<WeakReferenceSupport*>(this),
|
2017-02-18 03:30:03 +03:00
|
|
|
getter_AddRefs(unkInterceptor));
|
2017-09-18 19:49:15 +03:00
|
|
|
ENSURE_HR_SUCCEEDED(hr);
|
2016-07-27 20:44:56 +03:00
|
|
|
|
|
|
|
// (4) Obtain the interceptor's ICallInterceptor interface and register our
|
|
|
|
// event sink.
|
|
|
|
RefPtr<ICallInterceptor> interceptor;
|
|
|
|
hr = unkInterceptor->QueryInterface(IID_ICallInterceptor,
|
|
|
|
(void**)getter_AddRefs(interceptor));
|
2017-09-18 19:49:15 +03:00
|
|
|
ENSURE_HR_SUCCEEDED(hr);
|
2016-07-27 20:44:56 +03:00
|
|
|
|
|
|
|
hr = interceptor->RegisterSink(mEventSink);
|
2017-09-18 19:49:15 +03:00
|
|
|
ENSURE_HR_SUCCEEDED(hr);
|
2016-07-27 20:44:56 +03:00
|
|
|
|
|
|
|
// (5) Now that we have this new COM interceptor, insert it into the map.
|
2018-05-04 07:57:11 +03:00
|
|
|
auto doInsertion = [&]() -> void {
|
2016-07-27 20:44:56 +03:00
|
|
|
// We might have raced with another thread, so first check that we don't
|
|
|
|
// already have an entry for this
|
2017-02-18 03:30:03 +03:00
|
|
|
MapEntry* entry = Lookup(interceptorIid);
|
2016-07-27 20:44:56 +03:00
|
|
|
if (entry && entry->mInterceptor) {
|
2018-02-08 08:53:20 +03:00
|
|
|
// Bug 1433046: Because of aggregation, the QI for |interceptor|
|
|
|
|
// AddRefed |this|, not |unkInterceptor|. Thus, releasing |unkInterceptor|
|
|
|
|
// will destroy the object. Before we do that, we must first release
|
|
|
|
// |interceptor|. Otherwise, |interceptor| would be invalidated when
|
|
|
|
// |unkInterceptor| is destroyed.
|
|
|
|
interceptor = nullptr;
|
2016-07-27 20:44:56 +03:00
|
|
|
unkInterceptor = entry->mInterceptor;
|
|
|
|
} else {
|
2016-12-14 09:34:26 +03:00
|
|
|
// MapEntry has a RefPtr to unkInterceptor, OTOH we must not touch the
|
|
|
|
// refcount for the target interface because we are just moving it into
|
|
|
|
// the map and its refcounting might not be thread-safe.
|
2016-07-27 20:44:56 +03:00
|
|
|
IUnknown* rawTargetInterface = targetInterface.release();
|
2017-02-18 03:30:03 +03:00
|
|
|
mInterceptorMap.AppendElement(
|
|
|
|
MapEntry(interceptorIid, unkInterceptor, rawTargetInterface));
|
2016-07-27 20:44:56 +03:00
|
|
|
}
|
2018-05-04 07:57:11 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
if (aAlreadyLocked) {
|
|
|
|
doInsertion();
|
|
|
|
} else {
|
|
|
|
MutexAutoLock lock(mInterceptorMapMutex);
|
|
|
|
doInsertion();
|
2016-07-27 20:44:56 +03:00
|
|
|
}
|
|
|
|
|
2017-09-18 19:49:15 +03:00
|
|
|
hr = unkInterceptor->QueryInterface(interceptorIid, aOutInterceptor);
|
|
|
|
ENSURE_HR_SUCCEEDED(hr);
|
|
|
|
return hr;
|
2016-07-27 20:44:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT
|
2017-07-26 00:57:18 +03:00
|
|
|
Interceptor::QueryInterfaceTarget(REFIID aIid, void** aOutput,
|
|
|
|
TimeDuration* aOutDuration) {
|
2016-07-27 20:44:56 +03:00
|
|
|
// NB: This QI needs to run on the main thread because the target object
|
|
|
|
// is probably Gecko code that is not thread-safe. Note that this main
|
|
|
|
// thread invocation is *synchronous*.
|
2018-03-06 10:08:15 +03:00
|
|
|
if (!NS_IsMainThread() && tlsCreatingStdMarshal.get()) {
|
|
|
|
mStdMarshalMutex.AssertCurrentThreadOwns();
|
|
|
|
// COM queries for special interfaces such as IFastRundown when creating a
|
|
|
|
// marshaler. We don't want these being dispatched to the main thread,
|
|
|
|
// since this would cause a deadlock on mStdMarshalMutex if the main
|
|
|
|
// thread is also querying for IMarshal. If we do need to respond to these
|
|
|
|
// special interfaces, this should be done before this point; e.g. in
|
|
|
|
// Interceptor::QueryInterface like we do for INoMarshal.
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
2020-04-02 02:30:21 +03:00
|
|
|
if (mEventSink->IsInterfaceMaybeSupported(aIid) == E_NOINTERFACE) {
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
2016-07-27 20:44:56 +03:00
|
|
|
MainThreadInvoker invoker;
|
|
|
|
HRESULT hr;
|
|
|
|
auto runOnMainThread = [&]() -> void {
|
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
|
|
|
hr = mTarget->QueryInterface(aIid, aOutput);
|
|
|
|
};
|
2017-06-12 22:34:10 +03:00
|
|
|
if (!invoker.Invoke(NS_NewRunnableFunction("Interceptor::QueryInterface",
|
|
|
|
runOnMainThread))) {
|
2016-07-27 20:44:56 +03:00
|
|
|
return E_FAIL;
|
|
|
|
}
|
2017-07-26 00:57:18 +03:00
|
|
|
if (aOutDuration) {
|
|
|
|
*aOutDuration = invoker.GetDuration();
|
|
|
|
}
|
2016-07-27 20:44:56 +03:00
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT
|
|
|
|
Interceptor::QueryInterface(REFIID riid, void** ppv) {
|
2017-10-31 23:37:00 +03:00
|
|
|
if (riid == IID_INoMarshal) {
|
|
|
|
// This entire library is designed around marshaling, so there's no point
|
|
|
|
// propagating this QI request all over the place!
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
2016-07-27 20:44:56 +03:00
|
|
|
return WeakReferenceSupport::QueryInterface(riid, ppv);
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT
|
2018-01-13 00:17:18 +03:00
|
|
|
Interceptor::WeakRefQueryInterface(REFIID aIid, IUnknown** aOutInterface) {
|
2017-02-18 03:30:03 +03:00
|
|
|
if (aIid == IID_IStdMarshalInfo) {
|
2017-10-31 23:37:00 +03:00
|
|
|
detail::ReentrySentinel sentinel(this);
|
|
|
|
|
|
|
|
if (!sentinel.IsOutermost()) {
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
2017-02-18 03:30:03 +03:00
|
|
|
// Do not indicate that this interface is available unless we actually
|
|
|
|
// support it. We'll check that by looking for a successful call to
|
|
|
|
// IInterceptorSink::GetHandler()
|
|
|
|
CLSID dummy;
|
Bug 1303060: Changes to a11y to enable the serving of a COM handler; r=tbsaunde
MozReview-Commit-ID: GTQF3x1pBtX
A general outline of the COM handler (a.k.a. the "smart proxy"):
COM handlers are pieces of code that are loaded by the COM runtime along with
a proxy and are layered above that proxy. This enables the COM handler to
interpose itself between the caller and the proxy, thus providing the
opportunity for the handler to manipulate an interface's method calls before
those calls reach the proxy.
Handlers are regular COM components that live in DLLs and are declared in the
Windows registry. In order to allow for the specifying of a handler (and an
optional payload to be sent with the proxy), the mscom library allows its
clients to specify an implementation of the IHandlerProvider interface.
IHandlerProvider consists of 5 functions:
* GetHandler returns the CLSID of the component that should be loaded into
the COM client's process. If GetHandler returns a failure code, then no
handler is loaded.
* GetHandlerPayloadSize and WriteHandlerPayload are for obtaining the payload
data. These calls are made on a background thread but need to do their work
on the main thread. We declare the payload struct in IDL. MIDL generates two
functions, IA2Payload_Encode and IA2Payload_Decode, which are used by
mscom::StructToStream to read and write that struct to and from buffers.
* The a11y payload struct also includes an interface, IGeckoBackChannel, that
allows the handler to communicate directly with Gecko. IGeckoBackChannel
currently provides two methods: one to allow the handler to request fresh
cache information, and the other to provide Gecko with its IHandlerControl
interface.
* MarshalAs accepts an IID that specifies the interface that is about to be
proxied. We may want to send a more sophisticated proxy than the one that
is requested. The desired IID is returned by this function. In the case of
a11y interfaces, we should always return IAccessible2_3 if we are asked for
one of its parent interfaces. This allows us to eliminate round trips to
resolve more sophisticated interfaces later on.
* NewInstance, which is needed to ensure that all descendent proxies are also
imbued with the same handler code.
The main focus of this patch is as follows:
1. Provide an implementation of the IHandlerProvider interface;
2. Populate the handler payload (ie, the cache) with data;
3. Modify CreateHolderFromAccessible to specify the HandlerPayload object;
4. Receive the IHandlerControl interface from the handler DLL and move it
into the chrome process.
Some more information about IHandlerControl:
There is one IHandlerControl per handler DLL instance. It is the interface that
we call in Gecko when we need to dispatch an event to the handler. In order to
ensure that events are dispatched in the correct order, we need to dispatch
those events from the chrome main thread so that they occur in sequential order
with calls to NotifyWinEvent.
--HG--
extra : rebase_source : acb44dead7cc5488424720e1bf58862b7b30374f
2017-04-05 00:23:55 +03:00
|
|
|
if (FAILED(mEventSink->GetHandler(WrapNotNull(&dummy)))) {
|
2017-02-18 03:30:03 +03:00
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<IStdMarshalInfo> std(this);
|
|
|
|
std.forget(aOutInterface);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aIid == IID_IMarshal) {
|
2018-01-13 00:17:18 +03:00
|
|
|
MutexAutoLock lock(mStdMarshalMutex);
|
|
|
|
|
2017-08-18 00:54:28 +03:00
|
|
|
HRESULT hr;
|
|
|
|
|
2017-02-18 03:30:03 +03:00
|
|
|
if (!mStdMarshalUnk) {
|
2018-03-06 10:08:15 +03:00
|
|
|
MOZ_ASSERT(!tlsCreatingStdMarshal.get());
|
|
|
|
tlsCreatingStdMarshal.set(true);
|
2017-08-18 00:54:28 +03:00
|
|
|
if (XRE_IsContentProcess()) {
|
|
|
|
hr = FastMarshaler::Create(static_cast<IWeakReferenceSource*>(this),
|
|
|
|
getter_AddRefs(mStdMarshalUnk));
|
|
|
|
} else {
|
|
|
|
hr = ::CoGetStdMarshalEx(static_cast<IWeakReferenceSource*>(this),
|
|
|
|
SMEXF_SERVER, getter_AddRefs(mStdMarshalUnk));
|
|
|
|
}
|
2018-03-06 10:08:15 +03:00
|
|
|
tlsCreatingStdMarshal.set(false);
|
2017-08-18 00:54:28 +03:00
|
|
|
|
2017-09-18 19:49:15 +03:00
|
|
|
ENSURE_HR_SUCCEEDED(hr);
|
2017-02-18 03:30:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (!mStdMarshal) {
|
2017-08-18 00:54:28 +03:00
|
|
|
hr = mStdMarshalUnk->QueryInterface(IID_IMarshal, (void**)&mStdMarshal);
|
2017-09-18 19:49:15 +03:00
|
|
|
ENSURE_HR_SUCCEEDED(hr);
|
2017-02-18 03:30:03 +03:00
|
|
|
|
|
|
|
// mStdMarshal is weak, so drop its refcount
|
|
|
|
mStdMarshal->Release();
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<IMarshal> marshal(this);
|
|
|
|
marshal.forget(aOutInterface);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2016-07-27 20:44:56 +03:00
|
|
|
if (aIid == IID_IInterceptor) {
|
2017-02-18 03:30:03 +03:00
|
|
|
RefPtr<IInterceptor> intcpt(this);
|
|
|
|
intcpt.forget(aOutInterface);
|
2016-07-27 20:44:56 +03:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2016-08-12 21:12:48 +03:00
|
|
|
if (aIid == IID_IDispatch) {
|
|
|
|
STAUniquePtr<IDispatch> disp;
|
|
|
|
IDispatch* rawDisp = nullptr;
|
|
|
|
HRESULT hr = QueryInterfaceTarget(aIid, (void**)&rawDisp);
|
2017-09-18 19:49:15 +03:00
|
|
|
ENSURE_HR_SUCCEEDED(hr);
|
|
|
|
|
2016-08-12 21:12:48 +03:00
|
|
|
disp.reset(rawDisp);
|
|
|
|
return DispatchForwarder::Create(this, disp, aOutInterface);
|
|
|
|
}
|
|
|
|
|
2018-05-04 07:57:11 +03:00
|
|
|
return GetInterceptorForIID(aIid, (void**)aOutInterface, nullptr);
|
2016-07-27 20:44:56 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
ULONG
|
|
|
|
Interceptor::AddRef() { return WeakReferenceSupport::AddRef(); }
|
|
|
|
|
|
|
|
ULONG
|
|
|
|
Interceptor::Release() { return WeakReferenceSupport::Release(); }
|
|
|
|
|
2019-02-26 01:08:36 +03:00
|
|
|
/* static */
|
|
|
|
HRESULT Interceptor::DisconnectRemotesForTarget(IUnknown* aTarget) {
|
2018-02-19 09:08:57 +03:00
|
|
|
MOZ_ASSERT(aTarget);
|
|
|
|
|
|
|
|
detail::LiveSetAutoLock lock(GetLiveSet());
|
|
|
|
|
|
|
|
// It is not an error if the interceptor doesn't exist, so we return
|
|
|
|
// S_FALSE instead of an error in that case.
|
2018-07-04 00:04:27 +03:00
|
|
|
RefPtr<IWeakReference> existingWeak(GetLiveSet().Get(aTarget));
|
2018-02-19 09:08:57 +03:00
|
|
|
if (!existingWeak) {
|
|
|
|
return S_FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<IWeakReferenceSource> existingStrong;
|
|
|
|
if (FAILED(existingWeak->ToStrongRef(getter_AddRefs(existingStrong)))) {
|
|
|
|
return S_FALSE;
|
|
|
|
}
|
|
|
|
// Since we now hold a strong ref on the interceptor, we may now release the
|
|
|
|
// lock.
|
|
|
|
lock.Unlock();
|
|
|
|
|
|
|
|
return ::CoDisconnectObject(existingStrong, 0);
|
|
|
|
}
|
|
|
|
|
2016-07-27 20:44:56 +03:00
|
|
|
} // namespace mscom
|
|
|
|
} // namespace mozilla
|