1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #ifndef mozilla_mscom_PassthruProxy_h
8 #define mozilla_mscom_PassthruProxy_h
10 #include "mozilla/Atomics.h"
11 #include "mozilla/mscom/ProxyStream.h"
12 #include "mozilla/mscom/Ptr.h"
13 #include "mozilla/NotNull.h"
14 #if defined(MOZ_SANDBOX)
15 # include "mozilla/SandboxSettings.h"
16 #endif // defined(MOZ_SANDBOX)
24 template <typename Iface
>
28 struct VTableSizer
<IDispatch
> {
34 class PassthruProxy final
: public IMarshal
, public IClientSecurity
{
36 template <typename Iface
>
37 static RefPtr
<Iface
> Wrap(NotNull
<Iface
*> aIn
) {
38 static_assert(detail::VTableSizer
<Iface
>::Size
>= 3, "VTable too small");
40 #if defined(MOZ_SANDBOX)
41 if (mozilla::GetEffectiveContentSandboxLevel() < 3) {
42 // The sandbox isn't strong enough to be a problem; no wrapping required
46 typename
detail::EnvironmentSelector
<Iface
>::Type env
;
48 RefPtr
<PassthruProxy
> passthru(new PassthruProxy(
49 &env
, __uuidof(Iface
), detail::VTableSizer
<Iface
>::Size
, aIn
));
52 if (FAILED(passthru
->QueryProxyInterface(getter_AddRefs(result
)))) {
58 // No wrapping required
60 #endif // defined(MOZ_SANDBOX)
63 static HRESULT
Register();
68 STDMETHODIMP
QueryInterface(REFIID riid
, void** ppv
) override
;
69 STDMETHODIMP_(ULONG
) AddRef() override
;
70 STDMETHODIMP_(ULONG
) Release() override
;
73 STDMETHODIMP
GetUnmarshalClass(REFIID riid
, void* pv
, DWORD dwDestContext
,
74 void* pvDestContext
, DWORD mshlflags
,
75 CLSID
* pCid
) override
;
76 STDMETHODIMP
GetMarshalSizeMax(REFIID riid
, void* pv
, DWORD dwDestContext
,
77 void* pvDestContext
, DWORD mshlflags
,
78 DWORD
* pSize
) override
;
79 STDMETHODIMP
MarshalInterface(IStream
* pStm
, REFIID riid
, void* pv
,
80 DWORD dwDestContext
, void* pvDestContext
,
81 DWORD mshlflags
) override
;
82 STDMETHODIMP
UnmarshalInterface(IStream
* pStm
, REFIID riid
,
84 STDMETHODIMP
ReleaseMarshalData(IStream
* pStm
) override
;
85 STDMETHODIMP
DisconnectObject(DWORD dwReserved
) override
;
87 // IClientSecurity - we don't actually implement this interface, but its
88 // presence signals to mscom::IsProxy() that we are a proxy.
89 STDMETHODIMP
QueryBlanket(IUnknown
* aProxy
, DWORD
* aAuthnSvc
,
90 DWORD
* aAuthzSvc
, OLECHAR
** aSrvPrincName
,
91 DWORD
* aAuthnLevel
, DWORD
* aImpLevel
,
92 void** aAuthInfo
, DWORD
* aCapabilities
) override
{
96 STDMETHODIMP
SetBlanket(IUnknown
* aProxy
, DWORD aAuthnSvc
, DWORD aAuthzSvc
,
97 OLECHAR
* aSrvPrincName
, DWORD aAuthnLevel
,
98 DWORD aImpLevel
, void* aAuthInfo
,
99 DWORD aCapabilities
) override
{
103 STDMETHODIMP
CopyProxy(IUnknown
* aProxy
, IUnknown
** aOutCopy
) override
{
108 PassthruProxy(ProxyStream::Environment
* aEnv
, REFIID aIidToWrap
,
109 uint32_t aVTableSize
, NotNull
<IUnknown
*> aObjToWrap
);
112 bool IsInitialMarshal() const { return !mStream
; }
113 HRESULT
QueryProxyInterface(void** aOutInterface
);
115 Atomic
<ULONG
> mRefCnt
;
117 PreservedStreamPtr mPreservedStream
;
118 RefPtr
<IStream
> mStream
;
119 uint32_t mVTableSize
;
121 bool mForgetPreservedStream
;
125 } // namespace mozilla
127 #endif // mozilla_mscom_PassthruProxy_h