1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim:expandtab:shiftwidth=4:tabstop=4:
3 */
4 /* This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7
8 #include "ApplicationAccessibleWrap.h"
9
10 #include "AccessibleApplication_i.c"
11 #include "IUnknownImpl.h"
12
13 #include "nsIGfxInfo.h"
14 #include "nsPersistentProperties.h"
15 #include "nsServiceManagerUtils.h"
16 #include "mozilla/Services.h"
17
18 using namespace mozilla;
19 using namespace mozilla::a11y;
20
21 ////////////////////////////////////////////////////////////////////////////////
22 // nsISupports
NS_IMPL_ISUPPORTS_INHERITED0(ApplicationAccessibleWrap,ApplicationAccessible)23 NS_IMPL_ISUPPORTS_INHERITED0(ApplicationAccessibleWrap, ApplicationAccessible)
24
25 already_AddRefed<nsIPersistentProperties>
26 ApplicationAccessibleWrap::NativeAttributes() {
27 RefPtr<nsPersistentProperties> attributes = new nsPersistentProperties();
28
29 nsCOMPtr<nsIGfxInfo> gfxInfo = services::GetGfxInfo();
30 if (gfxInfo) {
31 bool isD2DEnabled = false;
32 gfxInfo->GetD2DEnabled(&isD2DEnabled);
33 nsAutoString unused;
34 attributes->SetStringProperty(
35 NS_LITERAL_CSTRING("D2D"),
36 isD2DEnabled ? NS_LITERAL_STRING("true") : NS_LITERAL_STRING("false"),
37 unused);
38 }
39
40 return attributes.forget();
41 }
42
43 ////////////////////////////////////////////////////////////////////////////////
44 // IUnknown
45
46 STDMETHODIMP
QueryInterface(REFIID iid,void ** ppv)47 ApplicationAccessibleWrap::QueryInterface(REFIID iid, void** ppv) {
48 if (!ppv) return E_INVALIDARG;
49
50 *ppv = nullptr;
51
52 if (IID_IAccessibleApplication == iid) {
53 *ppv = static_cast<IAccessibleApplication*>(this);
54 (reinterpret_cast<IUnknown*>(*ppv))->AddRef();
55 return S_OK;
56 }
57
58 return AccessibleWrap::QueryInterface(iid, ppv);
59 }
60
61 ////////////////////////////////////////////////////////////////////////////////
62 // IAccessibleApplication
63
64 STDMETHODIMP
get_appName(BSTR * aName)65 ApplicationAccessibleWrap::get_appName(BSTR* aName) {
66 if (!aName) return E_INVALIDARG;
67
68 *aName = nullptr;
69
70 if (IsDefunct()) return CO_E_OBJNOTCONNECTED;
71
72 nsAutoString name;
73 AppName(name);
74 if (name.IsEmpty()) return S_FALSE;
75
76 *aName = ::SysAllocStringLen(name.get(), name.Length());
77 return *aName ? S_OK : E_OUTOFMEMORY;
78 }
79
80 STDMETHODIMP
get_appVersion(BSTR * aVersion)81 ApplicationAccessibleWrap::get_appVersion(BSTR* aVersion) {
82 if (!aVersion) return E_INVALIDARG;
83
84 *aVersion = nullptr;
85
86 if (IsDefunct()) return CO_E_OBJNOTCONNECTED;
87
88 nsAutoString version;
89 AppVersion(version);
90 if (version.IsEmpty()) return S_FALSE;
91
92 *aVersion = ::SysAllocStringLen(version.get(), version.Length());
93 return *aVersion ? S_OK : E_OUTOFMEMORY;
94 }
95
96 STDMETHODIMP
get_toolkitName(BSTR * aName)97 ApplicationAccessibleWrap::get_toolkitName(BSTR* aName) {
98 if (!aName) return E_INVALIDARG;
99
100 if (IsDefunct()) return CO_E_OBJNOTCONNECTED;
101
102 nsAutoString name;
103 PlatformName(name);
104 if (name.IsEmpty()) return S_FALSE;
105
106 *aName = ::SysAllocStringLen(name.get(), name.Length());
107 return *aName ? S_OK : E_OUTOFMEMORY;
108 }
109
110 STDMETHODIMP
get_toolkitVersion(BSTR * aVersion)111 ApplicationAccessibleWrap::get_toolkitVersion(BSTR* aVersion) {
112 if (!aVersion) return E_INVALIDARG;
113
114 *aVersion = nullptr;
115
116 if (IsDefunct()) return CO_E_OBJNOTCONNECTED;
117
118 nsAutoString version;
119 PlatformVersion(version);
120 if (version.IsEmpty()) return S_FALSE;
121
122 *aVersion = ::SysAllocStringLen(version.get(), version.Length());
123 return *aVersion ? S_OK : E_OUTOFMEMORY;
124 }
125