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 "ia2AccessibleApplication.h"
9 
10 #include "AccessibleApplication_i.c"
11 #include "ApplicationAccessibleWrap.h"
12 
13 using namespace mozilla;
14 using namespace mozilla::a11y;
15 
AppAcc()16 ApplicationAccessible* ia2AccessibleApplication::AppAcc() {
17   return static_cast<ApplicationAccessible*>(LocalAcc());
18 }
19 
20 ////////////////////////////////////////////////////////////////////////////////
21 // IUnknown
22 
23 IMPL_IUNKNOWN_QUERY_HEAD(ia2AccessibleApplication)
IMPL_IUNKNOWN_QUERY_IFACE(IAccessibleApplication)24 IMPL_IUNKNOWN_QUERY_IFACE(IAccessibleApplication)
25 IMPL_IUNKNOWN_QUERY_TAIL_INHERITED(MsaaAccessible)
26 
27 ////////////////////////////////////////////////////////////////////////////////
28 // IAccessibleApplication
29 
30 STDMETHODIMP
31 ia2AccessibleApplication::get_appName(BSTR* aName) {
32   if (!aName) return E_INVALIDARG;
33 
34   *aName = nullptr;
35 
36   ApplicationAccessible* appAcc = AppAcc();
37   if (!appAcc) return CO_E_OBJNOTCONNECTED;
38 
39   nsAutoString name;
40   appAcc->AppName(name);
41   if (name.IsEmpty()) return S_FALSE;
42 
43   *aName = ::SysAllocStringLen(name.get(), name.Length());
44   return *aName ? S_OK : E_OUTOFMEMORY;
45 }
46 
47 STDMETHODIMP
get_appVersion(BSTR * aVersion)48 ia2AccessibleApplication::get_appVersion(BSTR* aVersion) {
49   if (!aVersion) return E_INVALIDARG;
50 
51   *aVersion = nullptr;
52 
53   ApplicationAccessible* appAcc = AppAcc();
54   if (!appAcc) return CO_E_OBJNOTCONNECTED;
55 
56   nsAutoString version;
57   appAcc->AppVersion(version);
58   if (version.IsEmpty()) return S_FALSE;
59 
60   *aVersion = ::SysAllocStringLen(version.get(), version.Length());
61   return *aVersion ? S_OK : E_OUTOFMEMORY;
62 }
63 
64 STDMETHODIMP
get_toolkitName(BSTR * aName)65 ia2AccessibleApplication::get_toolkitName(BSTR* aName) {
66   if (!aName) return E_INVALIDARG;
67 
68   ApplicationAccessible* appAcc = AppAcc();
69   if (!appAcc) return CO_E_OBJNOTCONNECTED;
70 
71   nsAutoString name;
72   appAcc->PlatformName(name);
73   if (name.IsEmpty()) return S_FALSE;
74 
75   *aName = ::SysAllocStringLen(name.get(), name.Length());
76   return *aName ? S_OK : E_OUTOFMEMORY;
77 }
78 
79 STDMETHODIMP
get_toolkitVersion(BSTR * aVersion)80 ia2AccessibleApplication::get_toolkitVersion(BSTR* aVersion) {
81   if (!aVersion) return E_INVALIDARG;
82 
83   *aVersion = nullptr;
84 
85   ApplicationAccessible* appAcc = AppAcc();
86   if (!appAcc) return CO_E_OBJNOTCONNECTED;
87 
88   nsAutoString version;
89   appAcc->PlatformVersion(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