2016-07-19 22:31:25 +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/. */
|
|
|
|
|
|
|
|
#include "mozilla/mscom/MainThreadHandoff.h"
|
|
|
|
|
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 <utility>
|
|
|
|
|
2017-07-26 00:57:18 +03:00
|
|
|
#include "mozilla/Assertions.h"
|
2017-02-18 03:30:03 +03:00
|
|
|
#include "mozilla/Attributes.h"
|
2017-07-26 00:57:18 +03:00
|
|
|
#include "mozilla/DebugOnly.h"
|
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/ThreadLocal.h"
|
|
|
|
#include "mozilla/TimeStamp.h"
|
|
|
|
#include "mozilla/Unused.h"
|
2017-02-18 03:30:03 +03:00
|
|
|
#include "mozilla/mscom/AgileReference.h"
|
2016-07-19 22:31:25 +03:00
|
|
|
#include "mozilla/mscom/InterceptorLog.h"
|
|
|
|
#include "mozilla/mscom/Registration.h"
|
2016-08-30 04:55:37 +03:00
|
|
|
#include "mozilla/mscom/Utils.h"
|
2017-02-16 22:38:09 +03:00
|
|
|
#include "nsProxyRelease.h"
|
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 "nsThreadUtils.h"
|
2016-07-19 22:31:25 +03:00
|
|
|
|
|
|
|
using mozilla::DebugOnly;
|
2017-02-18 03:30:03 +03:00
|
|
|
using mozilla::mscom::AgileReference;
|
2016-07-19 22:31:25 +03:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
2017-03-01 21:05:35 +03:00
|
|
|
class MOZ_NON_TEMPORARY_CLASS InParamWalker : private ICallFrameWalker {
|
2017-02-18 03:30:03 +03:00
|
|
|
public:
|
|
|
|
InParamWalker() : mPreHandoff(true) {}
|
|
|
|
|
|
|
|
void SetHandoffDone() {
|
|
|
|
mPreHandoff = false;
|
|
|
|
mAgileRefsItr = mAgileRefs.begin();
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT Walk(ICallFrame* aFrame) {
|
|
|
|
MOZ_ASSERT(aFrame);
|
|
|
|
if (!aFrame) {
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
return aFrame->WalkFrame(CALLFRAME_WALK_IN, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
// IUnknown
|
|
|
|
STDMETHODIMP QueryInterface(REFIID aIid, void** aOutInterface) override {
|
|
|
|
if (!aOutInterface) {
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
*aOutInterface = nullptr;
|
|
|
|
|
|
|
|
if (aIid == IID_IUnknown || aIid == IID_ICallFrameWalker) {
|
|
|
|
*aOutInterface = static_cast<ICallFrameWalker*>(this);
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
STDMETHODIMP_(ULONG) AddRef() override { return 2; }
|
|
|
|
|
|
|
|
STDMETHODIMP_(ULONG) Release() override { return 1; }
|
|
|
|
|
|
|
|
// ICallFrameWalker
|
|
|
|
STDMETHODIMP OnWalkInterface(REFIID aIid, PVOID* aInterface, BOOL aIn,
|
|
|
|
BOOL aOut) override {
|
|
|
|
MOZ_ASSERT(aIn);
|
|
|
|
if (!aIn) {
|
|
|
|
return E_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
IUnknown* origInterface = static_cast<IUnknown*>(*aInterface);
|
|
|
|
if (!origInterface) {
|
|
|
|
// Nothing to do
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mPreHandoff) {
|
|
|
|
mAgileRefs.AppendElement(AgileReference(aIid, origInterface));
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(mAgileRefsItr != mAgileRefs.end());
|
|
|
|
if (mAgileRefsItr == mAgileRefs.end()) {
|
|
|
|
return E_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT hr = mAgileRefsItr->Resolve(aIid, aInterface);
|
|
|
|
MOZ_ASSERT(SUCCEEDED(hr));
|
|
|
|
if (SUCCEEDED(hr)) {
|
|
|
|
++mAgileRefsItr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
InParamWalker(const InParamWalker&) = delete;
|
|
|
|
InParamWalker(InParamWalker&&) = delete;
|
|
|
|
InParamWalker& operator=(const InParamWalker&) = delete;
|
|
|
|
InParamWalker& operator=(InParamWalker&&) = delete;
|
|
|
|
|
|
|
|
private:
|
|
|
|
bool mPreHandoff;
|
|
|
|
AutoTArray<AgileReference, 1> mAgileRefs;
|
|
|
|
nsTArray<AgileReference>::iterator mAgileRefsItr;
|
|
|
|
};
|
|
|
|
|
2016-07-19 22:31:25 +03:00
|
|
|
class HandoffRunnable : public mozilla::Runnable {
|
|
|
|
public:
|
|
|
|
explicit HandoffRunnable(ICallFrame* aCallFrame, IUnknown* aTargetInterface)
|
2017-06-12 22:34:10 +03:00
|
|
|
: Runnable("HandoffRunnable"),
|
|
|
|
mCallFrame(aCallFrame),
|
2016-07-19 22:31:25 +03:00
|
|
|
mTargetInterface(aTargetInterface),
|
|
|
|
mResult(E_UNEXPECTED) {
|
2017-02-18 03:30:03 +03:00
|
|
|
DebugOnly<HRESULT> hr = mInParamWalker.Walk(aCallFrame);
|
|
|
|
MOZ_ASSERT(SUCCEEDED(hr));
|
2016-07-19 22:31:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHOD Run() override {
|
2017-02-18 03:30:03 +03:00
|
|
|
mInParamWalker.SetHandoffDone();
|
|
|
|
// We declare hr a DebugOnly because if mInParamWalker.Walk() fails, then
|
|
|
|
// mCallFrame->Invoke will fail anyway.
|
|
|
|
DebugOnly<HRESULT> hr = mInParamWalker.Walk(mCallFrame);
|
|
|
|
MOZ_ASSERT(SUCCEEDED(hr));
|
2016-07-19 22:31:25 +03:00
|
|
|
mResult = mCallFrame->Invoke(mTargetInterface);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT GetResult() const { return mResult; }
|
|
|
|
|
|
|
|
private:
|
2017-02-18 03:30:03 +03:00
|
|
|
ICallFrame* mCallFrame;
|
|
|
|
InParamWalker mInParamWalker;
|
|
|
|
IUnknown* mTargetInterface;
|
|
|
|
HRESULT mResult;
|
2016-07-19 22:31:25 +03:00
|
|
|
};
|
|
|
|
|
2017-10-17 01:15:02 +03:00
|
|
|
class MOZ_RAII SavedCallFrame final {
|
|
|
|
public:
|
|
|
|
explicit SavedCallFrame(mozilla::NotNull<ICallFrame*> aFrame)
|
|
|
|
: mCallFrame(aFrame) {
|
|
|
|
static const bool sIsInit = tlsFrame.init();
|
|
|
|
MOZ_ASSERT(sIsInit);
|
|
|
|
MOZ_ASSERT(!tlsFrame.get());
|
|
|
|
tlsFrame.set(this);
|
2018-10-10 07:31:35 +03:00
|
|
|
Unused << sIsInit;
|
2017-10-17 01:15:02 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
~SavedCallFrame() {
|
|
|
|
MOZ_ASSERT(tlsFrame.get());
|
|
|
|
tlsFrame.set(nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT GetIidAndMethod(mozilla::NotNull<IID*> aIid,
|
|
|
|
mozilla::NotNull<ULONG*> aMethod) const {
|
|
|
|
return mCallFrame->GetIIDAndMethod(aIid, aMethod);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const SavedCallFrame& Get() {
|
|
|
|
SavedCallFrame* saved = tlsFrame.get();
|
|
|
|
MOZ_ASSERT(saved);
|
|
|
|
|
|
|
|
return *saved;
|
|
|
|
}
|
|
|
|
|
|
|
|
SavedCallFrame(const SavedCallFrame&) = delete;
|
|
|
|
SavedCallFrame(SavedCallFrame&&) = delete;
|
|
|
|
SavedCallFrame& operator=(const SavedCallFrame&) = delete;
|
|
|
|
SavedCallFrame& operator=(SavedCallFrame&&) = delete;
|
|
|
|
|
|
|
|
private:
|
|
|
|
ICallFrame* mCallFrame;
|
|
|
|
|
|
|
|
private:
|
|
|
|
static MOZ_THREAD_LOCAL(SavedCallFrame*) tlsFrame;
|
|
|
|
};
|
|
|
|
|
|
|
|
MOZ_THREAD_LOCAL(SavedCallFrame*) SavedCallFrame::tlsFrame;
|
|
|
|
|
2017-10-24 01:55:26 +03:00
|
|
|
class MOZ_RAII LogEvent final {
|
|
|
|
public:
|
|
|
|
LogEvent() : mCallStart(mozilla::TimeStamp::Now()) {}
|
|
|
|
|
|
|
|
~LogEvent() {
|
|
|
|
if (mCapturedFrame.IsEmpty()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mozilla::TimeStamp callEnd(TimeStamp::Now());
|
|
|
|
mozilla::TimeDuration totalTime(callEnd - mCallStart);
|
|
|
|
mozilla::TimeDuration overhead(totalTime - mGeckoDuration -
|
|
|
|
mCaptureDuration);
|
|
|
|
|
|
|
|
mozilla::mscom::InterceptorLog::Event(mCapturedFrame, overhead,
|
|
|
|
mGeckoDuration);
|
|
|
|
}
|
|
|
|
|
|
|
|
void CaptureFrame(ICallFrame* aFrame, IUnknown* aTarget,
|
|
|
|
const mozilla::TimeDuration& aGeckoDuration) {
|
|
|
|
mozilla::TimeStamp captureStart(TimeStamp::Now());
|
|
|
|
|
|
|
|
mozilla::mscom::InterceptorLog::CaptureFrame(aFrame, aTarget,
|
|
|
|
mCapturedFrame);
|
|
|
|
mGeckoDuration = aGeckoDuration;
|
|
|
|
|
|
|
|
mozilla::TimeStamp captureEnd(TimeStamp::Now());
|
|
|
|
|
|
|
|
// Make sure that the time we spent in CaptureFrame isn't charged against
|
|
|
|
// overall overhead
|
|
|
|
mCaptureDuration = captureEnd - captureStart;
|
|
|
|
}
|
|
|
|
|
|
|
|
LogEvent(const LogEvent&) = delete;
|
|
|
|
LogEvent(LogEvent&&) = delete;
|
|
|
|
LogEvent& operator=(const LogEvent&) = delete;
|
|
|
|
LogEvent& operator=(LogEvent&&) = delete;
|
|
|
|
|
|
|
|
private:
|
|
|
|
mozilla::TimeStamp mCallStart;
|
|
|
|
mozilla::TimeDuration mGeckoDuration;
|
|
|
|
mozilla::TimeDuration mCaptureDuration;
|
|
|
|
nsAutoCString mCapturedFrame;
|
|
|
|
};
|
|
|
|
|
2016-07-19 22:31:25 +03:00
|
|
|
} // anonymous namespace
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace mscom {
|
|
|
|
|
2019-02-26 01:08:36 +03:00
|
|
|
/* static */
|
|
|
|
HRESULT MainThreadHandoff::Create(IHandlerProvider* aHandlerProvider,
|
|
|
|
IInterceptorSink** aOutput) {
|
2017-03-28 03:41:06 +03:00
|
|
|
RefPtr<MainThreadHandoff> handoff(new MainThreadHandoff(aHandlerProvider));
|
2017-02-18 03:35:01 +03:00
|
|
|
return handoff->QueryInterface(IID_IInterceptorSink, (void**)aOutput);
|
2016-07-19 22:31:25 +03:00
|
|
|
}
|
|
|
|
|
2017-03-28 03:41:06 +03:00
|
|
|
MainThreadHandoff::MainThreadHandoff(IHandlerProvider* aHandlerProvider)
|
|
|
|
: mRefCnt(0), mHandlerProvider(aHandlerProvider) {}
|
2016-07-19 22:31:25 +03:00
|
|
|
|
|
|
|
MainThreadHandoff::~MainThreadHandoff() { MOZ_ASSERT(NS_IsMainThread()); }
|
|
|
|
|
|
|
|
HRESULT
|
|
|
|
MainThreadHandoff::QueryInterface(REFIID riid, void** ppv) {
|
|
|
|
IUnknown* punk = nullptr;
|
|
|
|
if (!ppv) {
|
|
|
|
return E_INVALIDARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (riid == IID_IUnknown || riid == IID_ICallFrameEvents ||
|
|
|
|
riid == IID_IInterceptorSink) {
|
|
|
|
punk = static_cast<IInterceptorSink*>(this);
|
|
|
|
} else if (riid == IID_ICallFrameWalker) {
|
|
|
|
punk = static_cast<ICallFrameWalker*>(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
*ppv = punk;
|
|
|
|
if (!punk) {
|
|
|
|
return E_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
punk->AddRef();
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
ULONG
|
|
|
|
MainThreadHandoff::AddRef() {
|
|
|
|
return (ULONG)InterlockedIncrement((LONG*)&mRefCnt);
|
|
|
|
}
|
|
|
|
|
|
|
|
ULONG
|
|
|
|
MainThreadHandoff::Release() {
|
|
|
|
ULONG newRefCnt = (ULONG)InterlockedDecrement((LONG*)&mRefCnt);
|
|
|
|
if (newRefCnt == 0) {
|
|
|
|
// It is possible for the last Release() call to happen off-main-thread.
|
|
|
|
// If so, we need to dispatch an event to delete ourselves.
|
|
|
|
if (NS_IsMainThread()) {
|
|
|
|
delete this;
|
|
|
|
} else {
|
2017-02-16 22:38:09 +03:00
|
|
|
// We need to delete this object on the main thread, but we aren't on the
|
|
|
|
// main thread right now, so we send a reference to ourselves to the main
|
|
|
|
// thread to be re-released there.
|
|
|
|
RefPtr<MainThreadHandoff> self = this;
|
2017-06-14 04:27:17 +03:00
|
|
|
NS_ReleaseOnMainThreadSystemGroup("MainThreadHandoff", self.forget());
|
2016-07-19 22:31:25 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return newRefCnt;
|
|
|
|
}
|
|
|
|
|
2017-03-14 20:04:46 +03:00
|
|
|
HRESULT
|
|
|
|
MainThreadHandoff::FixIServiceProvider(ICallFrame* aFrame) {
|
|
|
|
MOZ_ASSERT(aFrame);
|
|
|
|
|
|
|
|
CALLFRAMEPARAMINFO iidOutParamInfo;
|
|
|
|
HRESULT hr = aFrame->GetParamInfo(1, &iidOutParamInfo);
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
VARIANT varIfaceOut;
|
|
|
|
hr = aFrame->GetParam(2, &varIfaceOut);
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(varIfaceOut.vt == (VT_UNKNOWN | VT_BYREF));
|
|
|
|
if (varIfaceOut.vt != (VT_UNKNOWN | VT_BYREF)) {
|
|
|
|
return DISP_E_BADVARTYPE;
|
|
|
|
}
|
|
|
|
|
|
|
|
IID** iidOutParam =
|
|
|
|
reinterpret_cast<IID**>(static_cast<BYTE*>(aFrame->GetStackLocation()) +
|
|
|
|
iidOutParamInfo.stackOffset);
|
|
|
|
|
|
|
|
return OnWalkInterface(**iidOutParam,
|
|
|
|
reinterpret_cast<void**>(varIfaceOut.ppunkVal), FALSE,
|
|
|
|
TRUE);
|
|
|
|
}
|
|
|
|
|
2016-07-19 22:31:25 +03:00
|
|
|
HRESULT
|
|
|
|
MainThreadHandoff::OnCall(ICallFrame* aFrame) {
|
2017-10-24 01:55:26 +03:00
|
|
|
LogEvent logEvent;
|
2017-07-26 00:57:18 +03:00
|
|
|
|
2016-07-19 22:31:25 +03:00
|
|
|
// (1) Get info about the method call
|
|
|
|
HRESULT hr;
|
|
|
|
IID iid;
|
|
|
|
ULONG method;
|
|
|
|
hr = aFrame->GetIIDAndMethod(&iid, &method);
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<IInterceptor> interceptor;
|
|
|
|
hr = mInterceptor->Resolve(IID_IInterceptor,
|
|
|
|
(void**)getter_AddRefs(interceptor));
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2017-03-07 03:22:43 +03:00
|
|
|
InterceptorTargetPtr<IUnknown> targetInterface;
|
2016-07-19 22:31:25 +03:00
|
|
|
hr = interceptor->GetTargetForIID(iid, targetInterface);
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2017-02-18 03:30:03 +03:00
|
|
|
// (2) Execute the method call synchronously on the main thread
|
2016-07-19 22:31:25 +03:00
|
|
|
RefPtr<HandoffRunnable> handoffInfo(
|
|
|
|
new HandoffRunnable(aFrame, targetInterface.get()));
|
2016-08-09 03:06:51 +03:00
|
|
|
MainThreadInvoker invoker;
|
|
|
|
if (!invoker.Invoke(do_AddRef(handoffInfo))) {
|
2016-07-19 22:31:25 +03:00
|
|
|
MOZ_ASSERT(false);
|
|
|
|
return E_UNEXPECTED;
|
|
|
|
}
|
|
|
|
hr = handoffInfo->GetResult();
|
|
|
|
MOZ_ASSERT(SUCCEEDED(hr));
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2017-10-24 01:55:26 +03:00
|
|
|
// (3) Capture *before* wrapping outputs so that the log will contain pointers
|
|
|
|
// to the true target interface, not the wrapped ones.
|
|
|
|
logEvent.CaptureFrame(aFrame, targetInterface.get(), invoker.GetDuration());
|
2016-07-19 22:31:25 +03:00
|
|
|
|
|
|
|
// (4) Scan the function call for outparams that contain interface pointers.
|
|
|
|
// Those will need to be wrapped with MainThreadHandoff so that they too will
|
|
|
|
// be exeuted on the main thread.
|
|
|
|
|
|
|
|
hr = aFrame->GetReturnValue();
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
// If the call resulted in an error then there's not going to be anything
|
|
|
|
// that needs to be wrapped.
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2017-03-14 20:04:46 +03:00
|
|
|
if (iid == IID_IServiceProvider) {
|
|
|
|
// The only possible method index for IID_IServiceProvider is for
|
|
|
|
// QueryService at index 3; its other methods are inherited from IUnknown
|
|
|
|
// and are not processed here.
|
|
|
|
MOZ_ASSERT(method == 3);
|
|
|
|
// (5) If our interface is IServiceProvider, we need to manually ensure
|
|
|
|
// that the correct IID is provided for the interface outparam in
|
|
|
|
// IServiceProvider::QueryService.
|
|
|
|
hr = FixIServiceProvider(aFrame);
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
} else if (const ArrayData* arrayData = FindArrayData(iid, method)) {
|
|
|
|
// (6) Unfortunately ICallFrame::WalkFrame does not correctly handle array
|
|
|
|
// outparams. Instead, we find out whether anybody has called
|
|
|
|
// mscom::RegisterArrayData to supply array parameter information and use it
|
|
|
|
// if available. This is a terrible hack, but it works for the short term.
|
|
|
|
// In the longer term we want to be able to use COM proxy/stub metadata to
|
|
|
|
// resolve array information for us.
|
2016-07-19 22:31:25 +03:00
|
|
|
hr = FixArrayElements(aFrame, *arrayData);
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
return hr;
|
|
|
|
}
|
2016-08-09 03:06:51 +03:00
|
|
|
} else {
|
2017-10-17 01:15:02 +03:00
|
|
|
SavedCallFrame savedFrame(WrapNotNull(aFrame));
|
|
|
|
|
2017-03-14 20:04:46 +03:00
|
|
|
// (7) Scan the outputs looking for any outparam interfaces that need
|
2016-08-09 03:06:51 +03:00
|
|
|
// wrapping. NB: WalkFrame does not correctly handle array outparams. It
|
|
|
|
// processes the first element of an array but not the remaining elements
|
|
|
|
// (if any).
|
|
|
|
hr = aFrame->WalkFrame(CALLFRAME_WALK_OUT, this);
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
return hr;
|
|
|
|
}
|
2016-07-19 22:31:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static PVOID ResolveArrayPtr(VARIANT& aVariant) {
|
|
|
|
if (!(aVariant.vt & VT_BYREF)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return aVariant.byref;
|
|
|
|
}
|
|
|
|
|
|
|
|
static PVOID* ResolveInterfacePtr(PVOID aArrayPtr, VARTYPE aVartype,
|
|
|
|
LONG aIndex) {
|
|
|
|
if (aVartype != (VT_VARIANT | VT_BYREF)) {
|
|
|
|
IUnknown** ifaceArray = reinterpret_cast<IUnknown**>(aArrayPtr);
|
|
|
|
return reinterpret_cast<PVOID*>(&ifaceArray[aIndex]);
|
|
|
|
}
|
|
|
|
VARIANT* variantArray = reinterpret_cast<VARIANT*>(aArrayPtr);
|
|
|
|
VARIANT& element = variantArray[aIndex];
|
|
|
|
return &element.byref;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT
|
|
|
|
MainThreadHandoff::FixArrayElements(ICallFrame* aFrame,
|
|
|
|
const ArrayData& aArrayData) {
|
|
|
|
// Extract the array length
|
|
|
|
VARIANT paramVal;
|
2016-08-09 03:06:51 +03:00
|
|
|
VariantInit(¶mVal);
|
2016-07-19 22:31:25 +03:00
|
|
|
HRESULT hr = aFrame->GetParam(aArrayData.mLengthParamIndex, ¶mVal);
|
2016-08-09 03:06:51 +03:00
|
|
|
MOZ_ASSERT(SUCCEEDED(hr) && (paramVal.vt == (VT_I4 | VT_BYREF) ||
|
|
|
|
paramVal.vt == (VT_UI4 | VT_BYREF)));
|
2016-07-19 22:31:25 +03:00
|
|
|
if (FAILED(hr) || (paramVal.vt != (VT_I4 | VT_BYREF) &&
|
|
|
|
paramVal.vt != (VT_UI4 | VT_BYREF))) {
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
const LONG arrayLength = *(paramVal.plVal);
|
2016-08-09 03:06:51 +03:00
|
|
|
if (!arrayLength) {
|
|
|
|
// Nothing to do
|
2016-07-19 22:31:25 +03:00
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Extract the array parameter
|
2016-08-09 03:06:51 +03:00
|
|
|
VariantInit(¶mVal);
|
|
|
|
PVOID arrayPtr = nullptr;
|
2016-07-19 22:31:25 +03:00
|
|
|
hr = aFrame->GetParam(aArrayData.mArrayParamIndex, ¶mVal);
|
2016-08-09 03:06:51 +03:00
|
|
|
if (hr == DISP_E_BADVARTYPE) {
|
|
|
|
// ICallFrame::GetParam is not able to coerce the param into a VARIANT.
|
|
|
|
// That's ok, we can try to do it ourselves.
|
|
|
|
CALLFRAMEPARAMINFO paramInfo;
|
|
|
|
hr = aFrame->GetParamInfo(aArrayData.mArrayParamIndex, ¶mInfo);
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
PVOID stackBase = aFrame->GetStackLocation();
|
2016-11-08 02:04:06 +03:00
|
|
|
if (aArrayData.mFlag == ArrayData::Flag::eAllocatedByServer) {
|
|
|
|
// In order for the server to allocate the array's buffer and store it in
|
|
|
|
// an outparam, the parameter must be typed as Type***. Since the base
|
|
|
|
// of the array is Type*, we must dereference twice.
|
|
|
|
arrayPtr = **reinterpret_cast<PVOID**>(
|
|
|
|
reinterpret_cast<PBYTE>(stackBase) + paramInfo.stackOffset);
|
|
|
|
} else {
|
|
|
|
// We dereference because we need to obtain the value of a parameter
|
|
|
|
// from a stack offset. This pointer is the base of the array.
|
|
|
|
arrayPtr = *reinterpret_cast<PVOID*>(reinterpret_cast<PBYTE>(stackBase) +
|
|
|
|
paramInfo.stackOffset);
|
|
|
|
}
|
2016-08-09 03:06:51 +03:00
|
|
|
} else if (FAILED(hr)) {
|
2016-07-19 22:31:25 +03:00
|
|
|
return hr;
|
2016-08-09 03:06:51 +03:00
|
|
|
} else {
|
|
|
|
arrayPtr = ResolveArrayPtr(paramVal);
|
2016-07-19 22:31:25 +03:00
|
|
|
}
|
2016-08-09 03:06:51 +03:00
|
|
|
|
2016-07-19 22:31:25 +03:00
|
|
|
MOZ_ASSERT(arrayPtr);
|
|
|
|
if (!arrayPtr) {
|
|
|
|
return DISP_E_BADVARTYPE;
|
|
|
|
}
|
|
|
|
|
2016-08-09 03:06:51 +03:00
|
|
|
// We walk the elements of the array and invoke OnWalkInterface to wrap each
|
|
|
|
// one, just as ICallFrame::WalkFrame would do.
|
|
|
|
for (LONG index = 0; index < arrayLength; ++index) {
|
2016-07-19 22:31:25 +03:00
|
|
|
hr = OnWalkInterface(aArrayData.mArrayParamIid,
|
|
|
|
ResolveInterfacePtr(arrayPtr, paramVal.vt, index),
|
|
|
|
FALSE, TRUE);
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT
|
|
|
|
MainThreadHandoff::SetInterceptor(IWeakReference* aInterceptor) {
|
|
|
|
mInterceptor = aInterceptor;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2017-02-18 03:30:03 +03:00
|
|
|
HRESULT
|
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
|
|
|
MainThreadHandoff::GetHandler(NotNull<CLSID*> aHandlerClsid) {
|
2017-03-28 03:41:06 +03:00
|
|
|
if (!mHandlerProvider) {
|
2017-02-18 03:30:03 +03:00
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
2017-06-07 02:35:51 +03:00
|
|
|
|
2017-03-28 03:41:06 +03:00
|
|
|
return mHandlerProvider->GetHandler(aHandlerClsid);
|
2017-02-18 03:30:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT
|
2017-10-25 02:48:51 +03:00
|
|
|
MainThreadHandoff::GetHandlerPayloadSize(NotNull<IInterceptor*> aInterceptor,
|
|
|
|
NotNull<DWORD*> aOutPayloadSize) {
|
2017-03-28 03:41:06 +03:00
|
|
|
if (!mHandlerProvider) {
|
2017-02-18 03:30:03 +03:00
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
2017-10-25 02:48:51 +03:00
|
|
|
return mHandlerProvider->GetHandlerPayloadSize(aInterceptor, aOutPayloadSize);
|
2017-02-18 03:30:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
HRESULT
|
2017-10-25 02:48:51 +03:00
|
|
|
MainThreadHandoff::WriteHandlerPayload(NotNull<IInterceptor*> aInterceptor,
|
|
|
|
NotNull<IStream*> aStream) {
|
2017-03-28 03:41:06 +03:00
|
|
|
if (!mHandlerProvider) {
|
2017-02-18 03:30:03 +03:00
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
2017-10-25 02:48:51 +03:00
|
|
|
return mHandlerProvider->WriteHandlerPayload(aInterceptor, aStream);
|
2017-02-18 03:30:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
REFIID
|
|
|
|
MainThreadHandoff::MarshalAs(REFIID aIid) {
|
2017-03-28 03:41:06 +03:00
|
|
|
if (!mHandlerProvider) {
|
2017-02-18 03:30:03 +03:00
|
|
|
return aIid;
|
|
|
|
}
|
2017-03-28 03:41:06 +03:00
|
|
|
return mHandlerProvider->MarshalAs(aIid);
|
2017-02-18 03:30:03 +03:00
|
|
|
}
|
|
|
|
|
2018-02-19 09:08:57 +03:00
|
|
|
HRESULT
|
|
|
|
MainThreadHandoff::DisconnectHandlerRemotes() {
|
|
|
|
if (!mHandlerProvider) {
|
|
|
|
return E_NOTIMPL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return mHandlerProvider->DisconnectHandlerRemotes();
|
|
|
|
}
|
|
|
|
|
2016-07-19 22:31:25 +03:00
|
|
|
HRESULT
|
|
|
|
MainThreadHandoff::OnWalkInterface(REFIID aIid, PVOID* aInterface,
|
|
|
|
BOOL aIsInParam, BOOL aIsOutParam) {
|
|
|
|
MOZ_ASSERT(aInterface && aIsOutParam);
|
|
|
|
if (!aInterface || !aIsOutParam) {
|
|
|
|
return E_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Adopt aInterface for the time being. We can't touch its refcount off
|
|
|
|
// the main thread, so we'll use STAUniquePtr so that we can safely
|
|
|
|
// Release() it if necessary.
|
|
|
|
STAUniquePtr<IUnknown> origInterface(static_cast<IUnknown*>(*aInterface));
|
|
|
|
*aInterface = nullptr;
|
|
|
|
|
2016-08-18 18:48:48 +03:00
|
|
|
if (!origInterface) {
|
|
|
|
// Nothing to wrap.
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
2016-07-19 22:31:25 +03:00
|
|
|
// First make sure that aInterface isn't a proxy - we don't want to wrap
|
|
|
|
// those.
|
2017-06-07 03:17:42 +03:00
|
|
|
if (IsProxy(origInterface.get())) {
|
|
|
|
*aInterface = origInterface.release();
|
|
|
|
return S_OK;
|
|
|
|
}
|
2016-07-19 22:31:25 +03:00
|
|
|
|
|
|
|
RefPtr<IInterceptor> interceptor;
|
|
|
|
HRESULT hr = mInterceptor->Resolve(IID_IInterceptor,
|
|
|
|
(void**)getter_AddRefs(interceptor));
|
2016-08-18 18:48:48 +03:00
|
|
|
MOZ_ASSERT(SUCCEEDED(hr));
|
2016-07-19 22:31:25 +03:00
|
|
|
if (FAILED(hr)) {
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Now make sure that origInterface isn't referring to the same IUnknown
|
|
|
|
// as an interface that we are already managing. We can determine this by
|
|
|
|
// querying (NOT casting!) both objects for IUnknown and then comparing the
|
|
|
|
// resulting pointers.
|
2017-03-07 03:22:43 +03:00
|
|
|
InterceptorTargetPtr<IUnknown> existingTarget;
|
2016-07-19 22:31:25 +03:00
|
|
|
hr = interceptor->GetTargetForIID(aIid, existingTarget);
|
|
|
|
if (SUCCEEDED(hr)) {
|
2017-03-28 03:41:06 +03:00
|
|
|
// We'll start by checking the raw pointers. If they are equal, then the
|
|
|
|
// objects are equal. OTOH, if they differ, we must compare their
|
|
|
|
// IUnknown pointers to know for sure.
|
|
|
|
bool areTargetsEqual = existingTarget.get() == origInterface.get();
|
|
|
|
|
|
|
|
if (!areTargetsEqual) {
|
|
|
|
// This check must be done on the main thread
|
|
|
|
auto checkFn = [&existingTarget, &origInterface,
|
|
|
|
&areTargetsEqual]() -> void {
|
|
|
|
RefPtr<IUnknown> unkExisting;
|
|
|
|
HRESULT hrExisting = existingTarget->QueryInterface(
|
|
|
|
IID_IUnknown, (void**)getter_AddRefs(unkExisting));
|
|
|
|
RefPtr<IUnknown> unkNew;
|
|
|
|
HRESULT hrNew = origInterface->QueryInterface(
|
|
|
|
IID_IUnknown, (void**)getter_AddRefs(unkNew));
|
|
|
|
areTargetsEqual =
|
|
|
|
SUCCEEDED(hrExisting) && SUCCEEDED(hrNew) && unkExisting == unkNew;
|
|
|
|
};
|
2016-07-19 22:31:25 +03:00
|
|
|
|
2017-03-28 03:41:06 +03:00
|
|
|
MainThreadInvoker invoker;
|
2017-06-12 22:34:10 +03:00
|
|
|
invoker.Invoke(NS_NewRunnableFunction(
|
|
|
|
"MainThreadHandoff::OnWalkInterface", checkFn));
|
2017-03-28 03:41:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (areTargetsEqual) {
|
2016-07-19 22:31:25 +03:00
|
|
|
// The existing interface and the new interface both belong to the same
|
|
|
|
// target object. Let's just use the existing one.
|
|
|
|
void* intercepted = nullptr;
|
|
|
|
hr = interceptor->GetInterceptorForIID(aIid, &intercepted);
|
2016-08-18 18:48:48 +03:00
|
|
|
MOZ_ASSERT(SUCCEEDED(hr));
|
2016-07-19 22:31:25 +03:00
|
|
|
if (FAILED(hr)) {
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
*aInterface = intercepted;
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-17 01:15:02 +03:00
|
|
|
IID effectiveIid = aIid;
|
|
|
|
|
2017-03-28 03:41:06 +03:00
|
|
|
RefPtr<IHandlerProvider> payload;
|
|
|
|
if (mHandlerProvider) {
|
2017-10-17 01:15:02 +03:00
|
|
|
if (aIid == IID_IUnknown) {
|
|
|
|
const SavedCallFrame& curFrame = SavedCallFrame::Get();
|
|
|
|
|
|
|
|
IID callIid;
|
|
|
|
ULONG callMethod;
|
|
|
|
hr = curFrame.GetIidAndMethod(WrapNotNull(&callIid),
|
|
|
|
WrapNotNull(&callMethod));
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
effectiveIid =
|
|
|
|
mHandlerProvider->GetEffectiveOutParamIid(callIid, callMethod);
|
|
|
|
}
|
|
|
|
|
|
|
|
hr = mHandlerProvider->NewInstance(
|
2017-03-28 03:41:06 +03:00
|
|
|
effectiveIid, ToInterceptorTargetPtr(origInterface),
|
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
|
|
|
WrapNotNull((IHandlerProvider**)getter_AddRefs(payload)));
|
2017-02-18 03:30:03 +03:00
|
|
|
MOZ_ASSERT(SUCCEEDED(hr));
|
|
|
|
if (FAILED(hr)) {
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-07-19 22:31:25 +03:00
|
|
|
// Now create a new MainThreadHandoff wrapper...
|
|
|
|
RefPtr<IInterceptorSink> handoff;
|
2017-02-18 03:30:03 +03:00
|
|
|
hr = MainThreadHandoff::Create(payload, getter_AddRefs(handoff));
|
2016-08-18 18:48:48 +03:00
|
|
|
MOZ_ASSERT(SUCCEEDED(hr));
|
2016-07-19 22:31:25 +03:00
|
|
|
if (FAILED(hr)) {
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
2017-10-17 01:15:02 +03:00
|
|
|
REFIID interceptorIid =
|
|
|
|
payload ? payload->MarshalAs(effectiveIid) : effectiveIid;
|
2017-02-18 03:30:03 +03:00
|
|
|
|
2016-07-19 22:31:25 +03:00
|
|
|
RefPtr<IUnknown> wrapped;
|
2018-05-30 22:15:35 +03:00
|
|
|
hr = Interceptor::Create(std::move(origInterface), handoff, interceptorIid,
|
2016-08-26 19:03:17 +03:00
|
|
|
getter_AddRefs(wrapped));
|
2016-08-18 18:48:48 +03:00
|
|
|
MOZ_ASSERT(SUCCEEDED(hr));
|
2016-07-19 22:31:25 +03:00
|
|
|
if (FAILED(hr)) {
|
|
|
|
return hr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// And replace the original interface pointer with the wrapped one.
|
|
|
|
wrapped.forget(reinterpret_cast<IUnknown**>(aInterface));
|
|
|
|
|
|
|
|
return S_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace mscom
|
|
|
|
} // namespace mozilla
|