Bug 1812499 [wpt PR 38184] - Simplify handling of name-to-subdir mapping in canvas...
[gecko.git] / ipc / mscom / PassthruProxy.h
blobafdb5c648eec96c69059301a553750664c7758f8
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)
18 #include <objbase.h>
20 namespace mozilla {
21 namespace mscom {
22 namespace detail {
24 template <typename Iface>
25 struct VTableSizer;
27 template <>
28 struct VTableSizer<IDispatch> {
29 enum { Size = 7 };
32 } // namespace detail
34 class PassthruProxy final : public IMarshal, public IClientSecurity {
35 public:
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
43 return aIn.get();
46 typename detail::EnvironmentSelector<Iface>::Type env;
48 RefPtr<PassthruProxy> passthru(new PassthruProxy(
49 &env, __uuidof(Iface), detail::VTableSizer<Iface>::Size, aIn));
51 RefPtr<Iface> result;
52 if (FAILED(passthru->QueryProxyInterface(getter_AddRefs(result)))) {
53 return nullptr;
56 return result;
57 #else
58 // No wrapping required
59 return aIn.get();
60 #endif // defined(MOZ_SANDBOX)
63 static HRESULT Register();
65 PassthruProxy();
67 // IUnknown
68 STDMETHODIMP QueryInterface(REFIID riid, void** ppv) override;
69 STDMETHODIMP_(ULONG) AddRef() override;
70 STDMETHODIMP_(ULONG) Release() override;
72 // IMarshal
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,
83 void** ppv) override;
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 {
93 return E_NOTIMPL;
96 STDMETHODIMP SetBlanket(IUnknown* aProxy, DWORD aAuthnSvc, DWORD aAuthzSvc,
97 OLECHAR* aSrvPrincName, DWORD aAuthnLevel,
98 DWORD aImpLevel, void* aAuthInfo,
99 DWORD aCapabilities) override {
100 return E_NOTIMPL;
103 STDMETHODIMP CopyProxy(IUnknown* aProxy, IUnknown** aOutCopy) override {
104 return E_NOTIMPL;
107 private:
108 PassthruProxy(ProxyStream::Environment* aEnv, REFIID aIidToWrap,
109 uint32_t aVTableSize, NotNull<IUnknown*> aObjToWrap);
110 ~PassthruProxy();
112 bool IsInitialMarshal() const { return !mStream; }
113 HRESULT QueryProxyInterface(void** aOutInterface);
115 Atomic<ULONG> mRefCnt;
116 IID mWrappedIid;
117 PreservedStreamPtr mPreservedStream;
118 RefPtr<IStream> mStream;
119 uint32_t mVTableSize;
120 IUnknown* mVTable;
121 bool mForgetPreservedStream;
124 } // namespace mscom
125 } // namespace mozilla
127 #endif // mozilla_mscom_PassthruProxy_h