1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/accessible/src/windows/msaa/IUnknownImpl.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,186 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* vim: set ts=2 et sw=2 tw=80: */ 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. * 1.9 + */ 1.10 + 1.11 +#ifndef mozilla_a11y_IUnknownImpl_h_ 1.12 +#define mozilla_a11y_IUnknownImpl_h_ 1.13 + 1.14 +#include <windows.h> 1.15 +#undef CreateEvent // thank you windows you're such a helper 1.16 +#include "nsError.h" 1.17 + 1.18 +// Avoid warning C4509 like "nonstandard extension used: 1.19 +// 'AccessibleWrap::[acc_getName]' uses SEH and 'name' has destructor. 1.20 +// At this point we're catching a crash which is of much greater 1.21 +// importance than the missing dereference for the nsCOMPtr<> 1.22 +#ifdef _MSC_VER 1.23 +#pragma warning( disable : 4509 ) 1.24 +#endif 1.25 + 1.26 +namespace mozilla { 1.27 +namespace a11y { 1.28 + 1.29 +class AutoRefCnt 1.30 +{ 1.31 +public: 1.32 + AutoRefCnt() : mValue(0) {} 1.33 + 1.34 + ULONG operator++() { return ++mValue; } 1.35 + ULONG operator--() { return --mValue; } 1.36 + ULONG operator++(int) { return ++mValue; } 1.37 + ULONG operator--(int) { return --mValue; } 1.38 + 1.39 + operator ULONG() const { return mValue; } 1.40 + 1.41 +private: 1.42 + ULONG mValue; 1.43 +}; 1.44 + 1.45 +} // namespace a11y 1.46 +} // namespace mozilla 1.47 + 1.48 +#define DECL_IUNKNOWN \ 1.49 +public: \ 1.50 + virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID, void**); \ 1.51 + virtual ULONG STDMETHODCALLTYPE AddRef() MOZ_FINAL \ 1.52 + { \ 1.53 + MOZ_ASSERT(int32_t(mRefCnt) >= 0, "illegal refcnt"); \ 1.54 + ++mRefCnt; \ 1.55 + return mRefCnt; \ 1.56 + } \ 1.57 + virtual ULONG STDMETHODCALLTYPE Release() MOZ_FINAL \ 1.58 + { \ 1.59 + MOZ_ASSERT(int32_t(mRefCnt) > 0, "dup release"); \ 1.60 + --mRefCnt; \ 1.61 + if (mRefCnt) \ 1.62 + return mRefCnt; \ 1.63 + \ 1.64 + delete this; \ 1.65 + return 0; \ 1.66 + } \ 1.67 +private: \ 1.68 + mozilla::a11y::AutoRefCnt mRefCnt; \ 1.69 +public: 1.70 + 1.71 +#define DECL_IUNKNOWN_INHERITED \ 1.72 +public: \ 1.73 +virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID, void**); \ 1.74 + 1.75 +#define IMPL_IUNKNOWN_QUERY_HEAD(Class) \ 1.76 +STDMETHODIMP \ 1.77 +Class::QueryInterface(REFIID aIID, void** aInstancePtr) \ 1.78 +{ \ 1.79 + A11Y_TRYBLOCK_BEGIN \ 1.80 + if (!aInstancePtr) \ 1.81 + return E_INVALIDARG; \ 1.82 + *aInstancePtr = nullptr; \ 1.83 + \ 1.84 + HRESULT hr = E_NOINTERFACE; 1.85 + 1.86 +#define IMPL_IUNKNOWN_QUERY_TAIL \ 1.87 + return hr; \ 1.88 + A11Y_TRYBLOCK_END \ 1.89 +} 1.90 + 1.91 +#define IMPL_IUNKNOWN_QUERY_TAIL_AGGREGATED(Member) \ 1.92 + return Member->QueryInterface(aIID, aInstancePtr); \ 1.93 + A11Y_TRYBLOCK_END \ 1.94 +} 1.95 + 1.96 +#define IMPL_IUNKNOWN_QUERY_TAIL_INHERITED(BaseClass) \ 1.97 + return BaseClass::QueryInterface(aIID, aInstancePtr); \ 1.98 + A11Y_TRYBLOCK_END \ 1.99 +} 1.100 + 1.101 +#define IMPL_IUNKNOWN_QUERY_IFACE(Iface) \ 1.102 + if (aIID == IID_##Iface) { \ 1.103 + *aInstancePtr = static_cast<Iface*>(this); \ 1.104 + AddRef(); \ 1.105 + return S_OK; \ 1.106 + } 1.107 + 1.108 +#define IMPL_IUNKNOWN_QUERY_IFACE_AMBIGIOUS(Iface, aResolveIface) \ 1.109 + if (aIID == IID_##Iface) { \ 1.110 + *aInstancePtr = static_cast<Iface*>(static_cast<aResolveIface*>(this)); \ 1.111 + AddRef(); \ 1.112 + return S_OK; \ 1.113 + } 1.114 + 1.115 +#define IMPL_IUNKNOWN_QUERY_CLASS(Class) \ 1.116 + hr = Class::QueryInterface(aIID, aInstancePtr); \ 1.117 + if (SUCCEEDED(hr)) \ 1.118 + return hr; 1.119 + 1.120 +#define IMPL_IUNKNOWN_QUERY_CLASS_COND(Class, Cond) \ 1.121 + if (Cond) { \ 1.122 + hr = Class::QueryInterface(aIID, aInstancePtr); \ 1.123 + if (SUCCEEDED(hr)) \ 1.124 + return hr; \ 1.125 + } 1.126 + 1.127 +#define IMPL_IUNKNOWN_QUERY_AGGR_COND(Member, Cond) \ 1.128 + if (Cond) { \ 1.129 + hr = Member->QueryInterface(aIID, aInstancePtr); \ 1.130 + if (SUCCEEDED(hr)) \ 1.131 + return hr; \ 1.132 + } 1.133 + 1.134 +#define IMPL_IUNKNOWN1(Class, I1) \ 1.135 + IMPL_IUNKNOWN_QUERY_HEAD(Class) \ 1.136 + IMPL_IUNKNOWN_QUERY_IFACE(I1); \ 1.137 + IMPL_IUNKNOWN_QUERY_IFACE(IUnknown); \ 1.138 + IMPL_IUNKNOWN_QUERY_TAIL \ 1.139 + 1.140 +#define IMPL_IUNKNOWN2(Class, I1, I2) \ 1.141 + IMPL_IUNKNOWN_QUERY_HEAD(Class) \ 1.142 + IMPL_IUNKNOWN_QUERY_IFACE(I1); \ 1.143 + IMPL_IUNKNOWN_QUERY_IFACE(I2); \ 1.144 + IMPL_IUNKNOWN_QUERY_IFACE_AMBIGIOUS(IUnknown, I1); \ 1.145 + IMPL_IUNKNOWN_QUERY_TAIL \ 1.146 + 1.147 +#define IMPL_IUNKNOWN_INHERITED1(Class, Super0, Super1) \ 1.148 + IMPL_IUNKNOWN_QUERY_HEAD(Class) \ 1.149 + IMPL_IUNKNOWN_QUERY_CLASS(Super1); \ 1.150 + IMPL_IUNKNOWN_QUERY_TAIL_INHERITED(Super0) 1.151 + 1.152 +#define IMPL_IUNKNOWN_INHERITED2(Class, Super0, Super1, Super2) \ 1.153 + IMPL_IUNKNOWN_QUERY_HEAD(Class) \ 1.154 + IMPL_IUNKNOWN_QUERY_CLASS(Super1); \ 1.155 + IMPL_IUNKNOWN_QUERY_CLASS(Super2); \ 1.156 + IMPL_IUNKNOWN_QUERY_TAIL_INHERITED(Super0) 1.157 + 1.158 + 1.159 +/** 1.160 + * Wrap every method body by these macroses to pass exception to the crash 1.161 + * reporter. 1.162 + */ 1.163 +#define A11Y_TRYBLOCK_BEGIN \ 1.164 + MOZ_SEH_TRY { 1.165 + 1.166 +#define A11Y_TRYBLOCK_END \ 1.167 + } MOZ_SEH_EXCEPT(mozilla::a11y::FilterExceptions(::GetExceptionCode(), \ 1.168 + GetExceptionInformation())) \ 1.169 + { } \ 1.170 + return E_FAIL; 1.171 + 1.172 + 1.173 +namespace mozilla { 1.174 +namespace a11y { 1.175 + 1.176 +/** 1.177 + * Converts nsresult to HRESULT. 1.178 + */ 1.179 +HRESULT GetHRESULT(nsresult aResult); 1.180 + 1.181 +/** 1.182 + * Used to pass an exception to the crash reporter. 1.183 + */ 1.184 +int FilterExceptions(unsigned int aCode, EXCEPTION_POINTERS* aExceptionInfo); 1.185 + 1.186 +} // namespace a11y; 1.187 +} //namespace mozilla; 1.188 + 1.189 +#endif