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/. */ 6 7 #ifndef mozilla_mscom_FastMarshaler_h 8 #define mozilla_mscom_FastMarshaler_h 9 10 #include "mozilla/Atomics.h" 11 #include "mozilla/mscom/Aggregation.h" 12 #include "mozilla/RefPtr.h" 13 14 #include <objidl.h> 15 16 namespace mozilla { 17 namespace mscom { 18 19 /** 20 * When we are marshaling to the parent process main thread, we want to turn 21 * off COM's ping functionality. That functionality is designed to free 22 * strong references held by defunct client processes. Since our content 23 * processes cannot outlive our parent process, we turn off pings when we know 24 * that the COM client is going to be our parent process. This provides a 25 * significant performance boost in a11y code due to large numbers of remote 26 * objects being created and destroyed within a short period of time. 27 */ 28 class FastMarshaler final : public IMarshal { 29 public: 30 static HRESULT Create(IUnknown* aOuter, IUnknown** aOutMarshalerUnk); 31 32 // IMarshal 33 STDMETHODIMP GetUnmarshalClass(REFIID riid, void* pv, DWORD dwDestContext, 34 void* pvDestContext, DWORD mshlflags, 35 CLSID* pCid) override; 36 STDMETHODIMP GetMarshalSizeMax(REFIID riid, void* pv, DWORD dwDestContext, 37 void* pvDestContext, DWORD mshlflags, 38 DWORD* pSize) override; 39 STDMETHODIMP MarshalInterface(IStream* pStm, REFIID riid, void* pv, 40 DWORD dwDestContext, void* pvDestContext, 41 DWORD mshlflags) override; 42 STDMETHODIMP UnmarshalInterface(IStream* pStm, REFIID riid, 43 void** ppv) override; 44 STDMETHODIMP ReleaseMarshalData(IStream* pStm) override; 45 STDMETHODIMP DisconnectObject(DWORD dwReserved) override; 46 47 private: 48 FastMarshaler(IUnknown* aOuter, HRESULT* aResult); 49 ~FastMarshaler() = default; 50 51 static DWORD GetMarshalFlags(DWORD aDestContext, DWORD aMshlFlags); 52 53 Atomic<ULONG> mRefCnt; 54 IUnknown* mOuter; 55 RefPtr<IUnknown> mStdMarshalUnk; 56 IMarshal* mStdMarshalWeak; 57 DECLARE_AGGREGATABLE(FastMarshaler); 58 }; 59 60 } // namespace mscom 61 } // namespace mozilla 62 63 #endif // mozilla_mscom_FastMarshaler_h 64