1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 "nsIPersistentProperties2.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,
24                              ApplicationAccessible)
25 
26 already_AddRefed<nsIPersistentProperties>
27 ApplicationAccessibleWrap::NativeAttributes()
28 {
29   nsCOMPtr<nsIPersistentProperties> attributes =
30     do_CreateInstance(NS_PERSISTENTPROPERTIES_CONTRACTID);
31 
32   nsCOMPtr<nsIGfxInfo> gfxInfo = services::GetGfxInfo();
33   if (gfxInfo) {
34     bool isD2DEnabled = false;
35     gfxInfo->GetD2DEnabled(&isD2DEnabled);
36     nsAutoString unused;
37     attributes->SetStringProperty(
38       NS_LITERAL_CSTRING("D2D"),
39       isD2DEnabled ? NS_LITERAL_STRING("true") : NS_LITERAL_STRING("false"),
40         unused);
41   }
42 
43   return attributes.forget();
44 }
45 
46 ////////////////////////////////////////////////////////////////////////////////
47 // IUnknown
48 
49 STDMETHODIMP
QueryInterface(REFIID iid,void ** ppv)50 ApplicationAccessibleWrap::QueryInterface(REFIID iid, void** ppv)
51 {
52   if (!ppv)
53     return E_INVALIDARG;
54 
55   *ppv = nullptr;
56 
57   if (IID_IAccessibleApplication == iid) {
58     *ppv = static_cast<IAccessibleApplication*>(this);
59     (reinterpret_cast<IUnknown*>(*ppv))->AddRef();
60     return S_OK;
61   }
62 
63   return AccessibleWrap::QueryInterface(iid, ppv);
64 }
65 
66 ////////////////////////////////////////////////////////////////////////////////
67 // IAccessibleApplication
68 
69 STDMETHODIMP
get_appName(BSTR * aName)70 ApplicationAccessibleWrap::get_appName(BSTR* aName)
71 {
72   A11Y_TRYBLOCK_BEGIN
73 
74   if (!aName)
75     return E_INVALIDARG;
76 
77   *aName = nullptr;
78 
79   if (IsDefunct())
80     return CO_E_OBJNOTCONNECTED;
81 
82   nsAutoString name;
83   AppName(name);
84   if (name.IsEmpty())
85     return S_FALSE;
86 
87   *aName = ::SysAllocStringLen(name.get(), name.Length());
88   return *aName ? S_OK : E_OUTOFMEMORY;
89 
90   A11Y_TRYBLOCK_END
91 }
92 
93 STDMETHODIMP
get_appVersion(BSTR * aVersion)94 ApplicationAccessibleWrap::get_appVersion(BSTR* aVersion)
95 {
96   A11Y_TRYBLOCK_BEGIN
97 
98   if (!aVersion)
99     return E_INVALIDARG;
100 
101   *aVersion = nullptr;
102 
103   if (IsDefunct())
104     return CO_E_OBJNOTCONNECTED;
105 
106   nsAutoString version;
107   AppVersion(version);
108   if (version.IsEmpty())
109     return S_FALSE;
110 
111   *aVersion = ::SysAllocStringLen(version.get(), version.Length());
112   return *aVersion ? S_OK : E_OUTOFMEMORY;
113 
114   A11Y_TRYBLOCK_END
115 }
116 
117 STDMETHODIMP
get_toolkitName(BSTR * aName)118 ApplicationAccessibleWrap::get_toolkitName(BSTR* aName)
119 {
120   A11Y_TRYBLOCK_BEGIN
121 
122   if (!aName)
123     return E_INVALIDARG;
124 
125   if (IsDefunct())
126     return CO_E_OBJNOTCONNECTED;
127 
128   nsAutoString name;
129   PlatformName(name);
130   if (name.IsEmpty())
131     return S_FALSE;
132 
133   *aName = ::SysAllocStringLen(name.get(), name.Length());
134   return *aName ? S_OK : E_OUTOFMEMORY;
135 
136   A11Y_TRYBLOCK_END
137 }
138 
139 STDMETHODIMP
get_toolkitVersion(BSTR * aVersion)140 ApplicationAccessibleWrap::get_toolkitVersion(BSTR* aVersion)
141 {
142   A11Y_TRYBLOCK_BEGIN
143 
144   if (!aVersion)
145     return E_INVALIDARG;
146 
147   *aVersion = nullptr;
148 
149   if (IsDefunct())
150     return CO_E_OBJNOTCONNECTED;
151 
152   nsAutoString version;
153   PlatformVersion(version);
154   if (version.IsEmpty())
155     return S_FALSE;
156 
157   *aVersion = ::SysAllocStringLen(version.get(), version.Length());
158   return *aVersion ? S_OK : E_OUTOFMEMORY;
159 
160   A11Y_TRYBLOCK_END
161 }
162 
163