Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
michael@0 | 2 | /* vim:expandtab:shiftwidth=4:tabstop=4: |
michael@0 | 3 | */ |
michael@0 | 4 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 7 | |
michael@0 | 8 | #include "ApplicationAccessibleWrap.h" |
michael@0 | 9 | |
michael@0 | 10 | #include "AccessibleApplication_i.c" |
michael@0 | 11 | #include "IUnknownImpl.h" |
michael@0 | 12 | |
michael@0 | 13 | #include "nsIGfxInfo.h" |
michael@0 | 14 | #include "nsIPersistentProperties2.h" |
michael@0 | 15 | #include "nsServiceManagerUtils.h" |
michael@0 | 16 | |
michael@0 | 17 | using namespace mozilla; |
michael@0 | 18 | using namespace mozilla::a11y; |
michael@0 | 19 | |
michael@0 | 20 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 21 | // nsISupports |
michael@0 | 22 | NS_IMPL_ISUPPORTS_INHERITED0(ApplicationAccessibleWrap, |
michael@0 | 23 | ApplicationAccessible) |
michael@0 | 24 | |
michael@0 | 25 | already_AddRefed<nsIPersistentProperties> |
michael@0 | 26 | ApplicationAccessibleWrap::NativeAttributes() |
michael@0 | 27 | { |
michael@0 | 28 | nsCOMPtr<nsIPersistentProperties> attributes = |
michael@0 | 29 | do_CreateInstance(NS_PERSISTENTPROPERTIES_CONTRACTID); |
michael@0 | 30 | |
michael@0 | 31 | nsCOMPtr<nsIGfxInfo> gfxInfo = do_GetService("@mozilla.org/gfx/info;1"); |
michael@0 | 32 | if (gfxInfo) { |
michael@0 | 33 | bool isD2DEnabled = false; |
michael@0 | 34 | gfxInfo->GetD2DEnabled(&isD2DEnabled); |
michael@0 | 35 | nsAutoString unused; |
michael@0 | 36 | attributes->SetStringProperty( |
michael@0 | 37 | NS_LITERAL_CSTRING("D2D"), |
michael@0 | 38 | isD2DEnabled ? NS_LITERAL_STRING("true") : NS_LITERAL_STRING("false"), |
michael@0 | 39 | unused); |
michael@0 | 40 | } |
michael@0 | 41 | |
michael@0 | 42 | return attributes.forget(); |
michael@0 | 43 | } |
michael@0 | 44 | |
michael@0 | 45 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 46 | // IUnknown |
michael@0 | 47 | |
michael@0 | 48 | STDMETHODIMP |
michael@0 | 49 | ApplicationAccessibleWrap::QueryInterface(REFIID iid, void** ppv) |
michael@0 | 50 | { |
michael@0 | 51 | if (!ppv) |
michael@0 | 52 | return E_INVALIDARG; |
michael@0 | 53 | |
michael@0 | 54 | *ppv = nullptr; |
michael@0 | 55 | |
michael@0 | 56 | if (IID_IAccessibleApplication == iid) { |
michael@0 | 57 | *ppv = static_cast<IAccessibleApplication*>(this); |
michael@0 | 58 | (reinterpret_cast<IUnknown*>(*ppv))->AddRef(); |
michael@0 | 59 | return S_OK; |
michael@0 | 60 | } |
michael@0 | 61 | |
michael@0 | 62 | return AccessibleWrap::QueryInterface(iid, ppv); |
michael@0 | 63 | } |
michael@0 | 64 | |
michael@0 | 65 | //////////////////////////////////////////////////////////////////////////////// |
michael@0 | 66 | // IAccessibleApplication |
michael@0 | 67 | |
michael@0 | 68 | STDMETHODIMP |
michael@0 | 69 | ApplicationAccessibleWrap::get_appName(BSTR* aName) |
michael@0 | 70 | { |
michael@0 | 71 | A11Y_TRYBLOCK_BEGIN |
michael@0 | 72 | |
michael@0 | 73 | if (!aName) |
michael@0 | 74 | return E_INVALIDARG; |
michael@0 | 75 | |
michael@0 | 76 | *aName = nullptr; |
michael@0 | 77 | |
michael@0 | 78 | if (IsDefunct()) |
michael@0 | 79 | return CO_E_OBJNOTCONNECTED; |
michael@0 | 80 | |
michael@0 | 81 | nsAutoString name; |
michael@0 | 82 | nsresult rv = GetAppName(name); |
michael@0 | 83 | if (NS_FAILED(rv)) |
michael@0 | 84 | return GetHRESULT(rv); |
michael@0 | 85 | |
michael@0 | 86 | if (name.IsEmpty()) |
michael@0 | 87 | return S_FALSE; |
michael@0 | 88 | |
michael@0 | 89 | *aName = ::SysAllocStringLen(name.get(), name.Length()); |
michael@0 | 90 | return *aName ? S_OK : E_OUTOFMEMORY; |
michael@0 | 91 | |
michael@0 | 92 | A11Y_TRYBLOCK_END |
michael@0 | 93 | } |
michael@0 | 94 | |
michael@0 | 95 | STDMETHODIMP |
michael@0 | 96 | ApplicationAccessibleWrap::get_appVersion(BSTR* aVersion) |
michael@0 | 97 | { |
michael@0 | 98 | A11Y_TRYBLOCK_BEGIN |
michael@0 | 99 | |
michael@0 | 100 | if (!aVersion) |
michael@0 | 101 | return E_INVALIDARG; |
michael@0 | 102 | |
michael@0 | 103 | *aVersion = nullptr; |
michael@0 | 104 | |
michael@0 | 105 | if (IsDefunct()) |
michael@0 | 106 | return CO_E_OBJNOTCONNECTED; |
michael@0 | 107 | |
michael@0 | 108 | nsAutoString version; |
michael@0 | 109 | nsresult rv = GetAppVersion(version); |
michael@0 | 110 | if (NS_FAILED(rv)) |
michael@0 | 111 | return GetHRESULT(rv); |
michael@0 | 112 | |
michael@0 | 113 | if (version.IsEmpty()) |
michael@0 | 114 | return S_FALSE; |
michael@0 | 115 | |
michael@0 | 116 | *aVersion = ::SysAllocStringLen(version.get(), version.Length()); |
michael@0 | 117 | return *aVersion ? S_OK : E_OUTOFMEMORY; |
michael@0 | 118 | |
michael@0 | 119 | A11Y_TRYBLOCK_END |
michael@0 | 120 | } |
michael@0 | 121 | |
michael@0 | 122 | STDMETHODIMP |
michael@0 | 123 | ApplicationAccessibleWrap::get_toolkitName(BSTR* aName) |
michael@0 | 124 | { |
michael@0 | 125 | A11Y_TRYBLOCK_BEGIN |
michael@0 | 126 | |
michael@0 | 127 | if (!aName) |
michael@0 | 128 | return E_INVALIDARG; |
michael@0 | 129 | |
michael@0 | 130 | if (IsDefunct()) |
michael@0 | 131 | return CO_E_OBJNOTCONNECTED; |
michael@0 | 132 | |
michael@0 | 133 | nsAutoString name; |
michael@0 | 134 | nsresult rv = GetPlatformName(name); |
michael@0 | 135 | if (NS_FAILED(rv)) |
michael@0 | 136 | return GetHRESULT(rv); |
michael@0 | 137 | |
michael@0 | 138 | if (name.IsEmpty()) |
michael@0 | 139 | return S_FALSE; |
michael@0 | 140 | |
michael@0 | 141 | *aName = ::SysAllocStringLen(name.get(), name.Length()); |
michael@0 | 142 | return *aName ? S_OK : E_OUTOFMEMORY; |
michael@0 | 143 | |
michael@0 | 144 | A11Y_TRYBLOCK_END |
michael@0 | 145 | } |
michael@0 | 146 | |
michael@0 | 147 | STDMETHODIMP |
michael@0 | 148 | ApplicationAccessibleWrap::get_toolkitVersion(BSTR* aVersion) |
michael@0 | 149 | { |
michael@0 | 150 | A11Y_TRYBLOCK_BEGIN |
michael@0 | 151 | |
michael@0 | 152 | if (!aVersion) |
michael@0 | 153 | return E_INVALIDARG; |
michael@0 | 154 | |
michael@0 | 155 | *aVersion = nullptr; |
michael@0 | 156 | |
michael@0 | 157 | if (IsDefunct()) |
michael@0 | 158 | return CO_E_OBJNOTCONNECTED; |
michael@0 | 159 | |
michael@0 | 160 | nsAutoString version; |
michael@0 | 161 | nsresult rv = GetPlatformVersion(version); |
michael@0 | 162 | if (NS_FAILED(rv)) |
michael@0 | 163 | return GetHRESULT(rv); |
michael@0 | 164 | |
michael@0 | 165 | if (version.IsEmpty()) |
michael@0 | 166 | return S_FALSE; |
michael@0 | 167 | |
michael@0 | 168 | *aVersion = ::SysAllocStringLen(version.get(), version.Length()); |
michael@0 | 169 | return *aVersion ? S_OK : E_OUTOFMEMORY; |
michael@0 | 170 | |
michael@0 | 171 | A11Y_TRYBLOCK_END |
michael@0 | 172 | } |
michael@0 | 173 |