Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* vim: set ts=2 et sw=2 tw=80: */ |
michael@0 | 3 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. * |
michael@0 | 6 | */ |
michael@0 | 7 | |
michael@0 | 8 | #ifndef mozilla_a11y_IUnknownImpl_h_ |
michael@0 | 9 | #define mozilla_a11y_IUnknownImpl_h_ |
michael@0 | 10 | |
michael@0 | 11 | #include <windows.h> |
michael@0 | 12 | #undef CreateEvent // thank you windows you're such a helper |
michael@0 | 13 | #include "nsError.h" |
michael@0 | 14 | |
michael@0 | 15 | // Avoid warning C4509 like "nonstandard extension used: |
michael@0 | 16 | // 'AccessibleWrap::[acc_getName]' uses SEH and 'name' has destructor. |
michael@0 | 17 | // At this point we're catching a crash which is of much greater |
michael@0 | 18 | // importance than the missing dereference for the nsCOMPtr<> |
michael@0 | 19 | #ifdef _MSC_VER |
michael@0 | 20 | #pragma warning( disable : 4509 ) |
michael@0 | 21 | #endif |
michael@0 | 22 | |
michael@0 | 23 | namespace mozilla { |
michael@0 | 24 | namespace a11y { |
michael@0 | 25 | |
michael@0 | 26 | class AutoRefCnt |
michael@0 | 27 | { |
michael@0 | 28 | public: |
michael@0 | 29 | AutoRefCnt() : mValue(0) {} |
michael@0 | 30 | |
michael@0 | 31 | ULONG operator++() { return ++mValue; } |
michael@0 | 32 | ULONG operator--() { return --mValue; } |
michael@0 | 33 | ULONG operator++(int) { return ++mValue; } |
michael@0 | 34 | ULONG operator--(int) { return --mValue; } |
michael@0 | 35 | |
michael@0 | 36 | operator ULONG() const { return mValue; } |
michael@0 | 37 | |
michael@0 | 38 | private: |
michael@0 | 39 | ULONG mValue; |
michael@0 | 40 | }; |
michael@0 | 41 | |
michael@0 | 42 | } // namespace a11y |
michael@0 | 43 | } // namespace mozilla |
michael@0 | 44 | |
michael@0 | 45 | #define DECL_IUNKNOWN \ |
michael@0 | 46 | public: \ |
michael@0 | 47 | virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID, void**); \ |
michael@0 | 48 | virtual ULONG STDMETHODCALLTYPE AddRef() MOZ_FINAL \ |
michael@0 | 49 | { \ |
michael@0 | 50 | MOZ_ASSERT(int32_t(mRefCnt) >= 0, "illegal refcnt"); \ |
michael@0 | 51 | ++mRefCnt; \ |
michael@0 | 52 | return mRefCnt; \ |
michael@0 | 53 | } \ |
michael@0 | 54 | virtual ULONG STDMETHODCALLTYPE Release() MOZ_FINAL \ |
michael@0 | 55 | { \ |
michael@0 | 56 | MOZ_ASSERT(int32_t(mRefCnt) > 0, "dup release"); \ |
michael@0 | 57 | --mRefCnt; \ |
michael@0 | 58 | if (mRefCnt) \ |
michael@0 | 59 | return mRefCnt; \ |
michael@0 | 60 | \ |
michael@0 | 61 | delete this; \ |
michael@0 | 62 | return 0; \ |
michael@0 | 63 | } \ |
michael@0 | 64 | private: \ |
michael@0 | 65 | mozilla::a11y::AutoRefCnt mRefCnt; \ |
michael@0 | 66 | public: |
michael@0 | 67 | |
michael@0 | 68 | #define DECL_IUNKNOWN_INHERITED \ |
michael@0 | 69 | public: \ |
michael@0 | 70 | virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID, void**); \ |
michael@0 | 71 | |
michael@0 | 72 | #define IMPL_IUNKNOWN_QUERY_HEAD(Class) \ |
michael@0 | 73 | STDMETHODIMP \ |
michael@0 | 74 | Class::QueryInterface(REFIID aIID, void** aInstancePtr) \ |
michael@0 | 75 | { \ |
michael@0 | 76 | A11Y_TRYBLOCK_BEGIN \ |
michael@0 | 77 | if (!aInstancePtr) \ |
michael@0 | 78 | return E_INVALIDARG; \ |
michael@0 | 79 | *aInstancePtr = nullptr; \ |
michael@0 | 80 | \ |
michael@0 | 81 | HRESULT hr = E_NOINTERFACE; |
michael@0 | 82 | |
michael@0 | 83 | #define IMPL_IUNKNOWN_QUERY_TAIL \ |
michael@0 | 84 | return hr; \ |
michael@0 | 85 | A11Y_TRYBLOCK_END \ |
michael@0 | 86 | } |
michael@0 | 87 | |
michael@0 | 88 | #define IMPL_IUNKNOWN_QUERY_TAIL_AGGREGATED(Member) \ |
michael@0 | 89 | return Member->QueryInterface(aIID, aInstancePtr); \ |
michael@0 | 90 | A11Y_TRYBLOCK_END \ |
michael@0 | 91 | } |
michael@0 | 92 | |
michael@0 | 93 | #define IMPL_IUNKNOWN_QUERY_TAIL_INHERITED(BaseClass) \ |
michael@0 | 94 | return BaseClass::QueryInterface(aIID, aInstancePtr); \ |
michael@0 | 95 | A11Y_TRYBLOCK_END \ |
michael@0 | 96 | } |
michael@0 | 97 | |
michael@0 | 98 | #define IMPL_IUNKNOWN_QUERY_IFACE(Iface) \ |
michael@0 | 99 | if (aIID == IID_##Iface) { \ |
michael@0 | 100 | *aInstancePtr = static_cast<Iface*>(this); \ |
michael@0 | 101 | AddRef(); \ |
michael@0 | 102 | return S_OK; \ |
michael@0 | 103 | } |
michael@0 | 104 | |
michael@0 | 105 | #define IMPL_IUNKNOWN_QUERY_IFACE_AMBIGIOUS(Iface, aResolveIface) \ |
michael@0 | 106 | if (aIID == IID_##Iface) { \ |
michael@0 | 107 | *aInstancePtr = static_cast<Iface*>(static_cast<aResolveIface*>(this)); \ |
michael@0 | 108 | AddRef(); \ |
michael@0 | 109 | return S_OK; \ |
michael@0 | 110 | } |
michael@0 | 111 | |
michael@0 | 112 | #define IMPL_IUNKNOWN_QUERY_CLASS(Class) \ |
michael@0 | 113 | hr = Class::QueryInterface(aIID, aInstancePtr); \ |
michael@0 | 114 | if (SUCCEEDED(hr)) \ |
michael@0 | 115 | return hr; |
michael@0 | 116 | |
michael@0 | 117 | #define IMPL_IUNKNOWN_QUERY_CLASS_COND(Class, Cond) \ |
michael@0 | 118 | if (Cond) { \ |
michael@0 | 119 | hr = Class::QueryInterface(aIID, aInstancePtr); \ |
michael@0 | 120 | if (SUCCEEDED(hr)) \ |
michael@0 | 121 | return hr; \ |
michael@0 | 122 | } |
michael@0 | 123 | |
michael@0 | 124 | #define IMPL_IUNKNOWN_QUERY_AGGR_COND(Member, Cond) \ |
michael@0 | 125 | if (Cond) { \ |
michael@0 | 126 | hr = Member->QueryInterface(aIID, aInstancePtr); \ |
michael@0 | 127 | if (SUCCEEDED(hr)) \ |
michael@0 | 128 | return hr; \ |
michael@0 | 129 | } |
michael@0 | 130 | |
michael@0 | 131 | #define IMPL_IUNKNOWN1(Class, I1) \ |
michael@0 | 132 | IMPL_IUNKNOWN_QUERY_HEAD(Class) \ |
michael@0 | 133 | IMPL_IUNKNOWN_QUERY_IFACE(I1); \ |
michael@0 | 134 | IMPL_IUNKNOWN_QUERY_IFACE(IUnknown); \ |
michael@0 | 135 | IMPL_IUNKNOWN_QUERY_TAIL \ |
michael@0 | 136 | |
michael@0 | 137 | #define IMPL_IUNKNOWN2(Class, I1, I2) \ |
michael@0 | 138 | IMPL_IUNKNOWN_QUERY_HEAD(Class) \ |
michael@0 | 139 | IMPL_IUNKNOWN_QUERY_IFACE(I1); \ |
michael@0 | 140 | IMPL_IUNKNOWN_QUERY_IFACE(I2); \ |
michael@0 | 141 | IMPL_IUNKNOWN_QUERY_IFACE_AMBIGIOUS(IUnknown, I1); \ |
michael@0 | 142 | IMPL_IUNKNOWN_QUERY_TAIL \ |
michael@0 | 143 | |
michael@0 | 144 | #define IMPL_IUNKNOWN_INHERITED1(Class, Super0, Super1) \ |
michael@0 | 145 | IMPL_IUNKNOWN_QUERY_HEAD(Class) \ |
michael@0 | 146 | IMPL_IUNKNOWN_QUERY_CLASS(Super1); \ |
michael@0 | 147 | IMPL_IUNKNOWN_QUERY_TAIL_INHERITED(Super0) |
michael@0 | 148 | |
michael@0 | 149 | #define IMPL_IUNKNOWN_INHERITED2(Class, Super0, Super1, Super2) \ |
michael@0 | 150 | IMPL_IUNKNOWN_QUERY_HEAD(Class) \ |
michael@0 | 151 | IMPL_IUNKNOWN_QUERY_CLASS(Super1); \ |
michael@0 | 152 | IMPL_IUNKNOWN_QUERY_CLASS(Super2); \ |
michael@0 | 153 | IMPL_IUNKNOWN_QUERY_TAIL_INHERITED(Super0) |
michael@0 | 154 | |
michael@0 | 155 | |
michael@0 | 156 | /** |
michael@0 | 157 | * Wrap every method body by these macroses to pass exception to the crash |
michael@0 | 158 | * reporter. |
michael@0 | 159 | */ |
michael@0 | 160 | #define A11Y_TRYBLOCK_BEGIN \ |
michael@0 | 161 | MOZ_SEH_TRY { |
michael@0 | 162 | |
michael@0 | 163 | #define A11Y_TRYBLOCK_END \ |
michael@0 | 164 | } MOZ_SEH_EXCEPT(mozilla::a11y::FilterExceptions(::GetExceptionCode(), \ |
michael@0 | 165 | GetExceptionInformation())) \ |
michael@0 | 166 | { } \ |
michael@0 | 167 | return E_FAIL; |
michael@0 | 168 | |
michael@0 | 169 | |
michael@0 | 170 | namespace mozilla { |
michael@0 | 171 | namespace a11y { |
michael@0 | 172 | |
michael@0 | 173 | /** |
michael@0 | 174 | * Converts nsresult to HRESULT. |
michael@0 | 175 | */ |
michael@0 | 176 | HRESULT GetHRESULT(nsresult aResult); |
michael@0 | 177 | |
michael@0 | 178 | /** |
michael@0 | 179 | * Used to pass an exception to the crash reporter. |
michael@0 | 180 | */ |
michael@0 | 181 | int FilterExceptions(unsigned int aCode, EXCEPTION_POINTERS* aExceptionInfo); |
michael@0 | 182 | |
michael@0 | 183 | } // namespace a11y; |
michael@0 | 184 | } //namespace mozilla; |
michael@0 | 185 | |
michael@0 | 186 | #endif |