Bug 1627084 part 2: mscom: Provide access to the HandlerProvider from the Interceptor. r=aklotz

Because MainThreadHandoff sits between the Interceptor and the HandlerProvider, the caller must:

1. Get the event sink (the IInterceptorSink) from the Interceptor using IInterceptor::GetEventSink.
2. QI to the new IMainThreadHandoff interface. (An IInterceptorSink might not necessarily be a MainThreadHandoff.)
3. Get the HandlerProvider from the MainThreadHandoff using IMainThreadHandoff::GetHandlerProvider.

Differential Revision: https://phabricator.services.mozilla.com/D69484
This commit is contained in:
James Teh 2020-04-24 20:25:21 +00:00
parent 7a5fb3252a
commit 2dcfeebd6f
3 changed files with 27 additions and 3 deletions

View File

@ -44,6 +44,7 @@ struct IInterceptor : public IUnknown {
REFIID aIid, InterceptorTargetPtr<IUnknown>& aTarget) = 0;
virtual STDMETHODIMP GetInterceptorForIID(REFIID aIid,
void** aOutInterceptor) = 0;
virtual STDMETHODIMP GetEventSink(IInterceptorSink** aSink) = 0;
};
/**
@ -121,6 +122,12 @@ class Interceptor final : public WeakReferenceSupport,
STDMETHODIMP GetInterceptorForIID(REFIID aIid,
void** aOutInterceptor) override;
STDMETHODIMP GetEventSink(IInterceptorSink** aSink) override {
RefPtr<IInterceptorSink> sink = mEventSink;
sink.forget(aSink);
return mEventSink ? S_OK : S_FALSE;
}
private:
struct MapEntry {
MapEntry(REFIID aIid, IUnknown* aInterceptor, IUnknown* aTargetInterface)

View File

@ -4,6 +4,8 @@
* 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
#include "mozilla/mscom/MainThreadHandoff.h"
#include <utility>
@ -251,8 +253,8 @@ MainThreadHandoff::QueryInterface(REFIID riid, void** ppv) {
}
if (riid == IID_IUnknown || riid == IID_ICallFrameEvents ||
riid == IID_IInterceptorSink) {
punk = static_cast<IInterceptorSink*>(this);
riid == IID_IInterceptorSink || riid == IID_IMainThreadHandoff) {
punk = static_cast<IMainThreadHandoff*>(this);
} else if (riid == IID_ICallFrameWalker) {
punk = static_cast<ICallFrameWalker*>(this);
}

View File

@ -19,9 +19,17 @@
namespace mozilla {
namespace mscom {
// {9a907000-7829-47f1-80eb-f67a26f47b34}
DEFINE_GUID(IID_IMainThreadHandoff, 0x9a907000, 0x7829, 0x47f1, 0x80, 0xeb,
0xf6, 0x7a, 0x26, 0xf4, 0x7b, 0x34);
struct IMainThreadHandoff : public IInterceptorSink {
virtual STDMETHODIMP GetHandlerProvider(IHandlerProvider** aProvider) = 0;
};
struct ArrayData;
class MainThreadHandoff final : public IInterceptorSink,
class MainThreadHandoff final : public IMainThreadHandoff,
public ICallFrameWalker {
public:
static HRESULT Create(IHandlerProvider* aHandlerProvider,
@ -68,6 +76,13 @@ class MainThreadHandoff final : public IInterceptorSink,
STDMETHODIMP DisconnectHandlerRemotes() override;
STDMETHODIMP IsInterfaceMaybeSupported(REFIID aIid) override;
// IMainThreadHandoff
STDMETHODIMP GetHandlerProvider(IHandlerProvider** aProvider) override {
RefPtr<IHandlerProvider> provider = mHandlerProvider;
provider.forget(aProvider);
return mHandlerProvider ? S_OK : S_FALSE;
}
// ICallFrameWalker
STDMETHODIMP OnWalkInterface(REFIID aIid, PVOID* aInterface, BOOL aIsInParam,
BOOL aIsOutParam) override;