Avoid potential negative array index access to cached text.
[LibreOffice.git] / toolkit / source / helper / accessibilityclient.cxx
blobcad81b3a915eb313580b00e6e71c67d9aa4a6ac5
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <config_feature_desktop.h>
21 #include <config_wasm_strip.h>
23 #include <sal/config.h>
25 #include <toolkit/helper/accessiblefactory.hxx>
26 #include <osl/module.h>
27 #include <osl/diagnose.h>
28 #include <osl/mutex.hxx>
29 #include <rtl/ref.hxx>
30 #include <tools/svlibrary.h>
32 #include <helper/accessibilityclient.hxx>
34 namespace toolkit
36 using namespace ::com::sun::star::uno;
37 using namespace ::com::sun::star::accessibility;
39 namespace
41 #ifndef DISABLE_DYNLOADING
42 oslModule s_hAccessibleImplementationModule = nullptr;
43 #endif
44 #if HAVE_FEATURE_DESKTOP
45 #if !ENABLE_WASM_STRIP_ACCESSIBILITY
46 GetStandardAccComponentFactory s_pAccessibleFactoryFunc = nullptr;
47 #endif
48 #endif
49 ::rtl::Reference< IAccessibleFactory > s_pFactory;
53 //= AccessibleDummyFactory
55 namespace {
57 class AccessibleDummyFactory:
58 public IAccessibleFactory
60 public:
61 AccessibleDummyFactory();
62 AccessibleDummyFactory(const AccessibleDummyFactory&) = delete;
63 AccessibleDummyFactory& operator=(const AccessibleDummyFactory&) = delete;
65 protected:
66 virtual ~AccessibleDummyFactory() override;
68 public:
69 // IAccessibleFactory
70 css::uno::Reference< css::accessibility::XAccessibleContext >
71 createAccessibleContext( VCLXButton* /*_pXWindow*/ ) override
73 return nullptr;
75 css::uno::Reference< css::accessibility::XAccessibleContext >
76 createAccessibleContext( VCLXCheckBox* /*_pXWindow*/ ) override
78 return nullptr;
80 css::uno::Reference< css::accessibility::XAccessibleContext >
81 createAccessibleContext( VCLXRadioButton* /*_pXWindow*/ ) override
83 return nullptr;
85 css::uno::Reference< css::accessibility::XAccessibleContext >
86 createAccessibleContext( VCLXListBox* /*_pXWindow*/ ) override
88 return nullptr;
90 css::uno::Reference< css::accessibility::XAccessibleContext >
91 createAccessibleContext( VCLXFixedHyperlink* /*_pXWindow*/ ) override
93 return nullptr;
95 css::uno::Reference< css::accessibility::XAccessibleContext >
96 createAccessibleContext( VCLXFixedText* /*_pXWindow*/ ) override
98 return nullptr;
100 css::uno::Reference< css::accessibility::XAccessibleContext >
101 createAccessibleContext( VCLXScrollBar* /*_pXWindow*/ ) override
103 return nullptr;
105 css::uno::Reference< css::accessibility::XAccessibleContext >
106 createAccessibleContext( VCLXEdit* /*_pXWindow*/ ) override
108 return nullptr;
110 css::uno::Reference< css::accessibility::XAccessibleContext >
111 createAccessibleContext( VCLXMultiLineEdit* /*_pXWindow*/ ) override
113 return nullptr;
115 css::uno::Reference< css::accessibility::XAccessibleContext >
116 createAccessibleContext( VCLXComboBox* /*_pXWindow*/ ) override
118 return nullptr;
120 css::uno::Reference< css::accessibility::XAccessibleContext >
121 createAccessibleContext( VCLXToolBox* /*_pXWindow*/ ) override
123 return nullptr;
125 css::uno::Reference< css::accessibility::XAccessibleContext >
126 createAccessibleContext( VCLXHeaderBar* /*_pXWindow*/ ) override
128 return nullptr;
130 css::uno::Reference< css::accessibility::XAccessibleContext >
131 createAccessibleContext( SVTXNumericField* /*_pXWindow*/ ) override
133 return nullptr;
135 css::uno::Reference< css::accessibility::XAccessibleContext >
136 createAccessibleContext( VCLXWindow* /*_pXWindow*/ ) override
138 return nullptr;
140 css::uno::Reference< css::accessibility::XAccessible >
141 createAccessible( Menu* /*_pMenu*/, bool /*_bIsMenuBar*/ ) override
143 return nullptr;
149 AccessibleDummyFactory::AccessibleDummyFactory()
154 AccessibleDummyFactory::~AccessibleDummyFactory()
159 //= AccessibilityClient
162 AccessibilityClient::AccessibilityClient()
163 :m_bInitialized( false )
167 #if !ENABLE_WASM_STRIP_ACCESSIBILITY
168 #if HAVE_FEATURE_DESKTOP
169 #ifndef DISABLE_DYNLOADING
170 extern "C" { static void thisModule() {} }
171 #else
172 extern "C" void *getStandardAccessibleFactory();
173 #endif
174 #endif // HAVE_FEATURE_DESKTOP
175 #endif // ENABLE_WASM_STRIP_ACCESSIBILITY
177 void AccessibilityClient::ensureInitialized()
179 if ( m_bInitialized )
180 return;
182 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
184 #if !ENABLE_WASM_STRIP_ACCESSIBILITY
185 #if HAVE_FEATURE_DESKTOP
186 // load the library implementing the factory
187 if (!s_pFactory)
189 #ifndef DISABLE_DYNLOADING
190 s_hAccessibleImplementationModule = osl_loadModuleRelative( &thisModule, u"" SVLIBRARY( "acc" ) ""_ustr.pData, 0 );
191 if ( s_hAccessibleImplementationModule != nullptr )
193 s_pAccessibleFactoryFunc = reinterpret_cast<GetStandardAccComponentFactory>(
194 osl_getFunctionSymbol( s_hAccessibleImplementationModule, u"getStandardAccessibleFactory"_ustr.pData ));
197 OSL_ENSURE( s_pAccessibleFactoryFunc, "AccessibilityClient::ensureInitialized: could not load the library, or not retrieve the needed symbol!" );
198 #else
199 s_pAccessibleFactoryFunc = getStandardAccessibleFactory;
200 #endif // DISABLE_DYNLOADING
202 // get a factory instance
203 if ( s_pAccessibleFactoryFunc )
205 IAccessibleFactory* pFactory = static_cast< IAccessibleFactory* >( (*s_pAccessibleFactoryFunc)() );
206 OSL_ENSURE( pFactory, "AccessibilityClient::ensureInitialized: no factory provided by the A11Y lib!" );
207 if ( pFactory )
209 s_pFactory = pFactory;
210 pFactory->release();
214 #endif // HAVE_FEATURE_DESKTOP
215 #endif // ENABLE_WASM_STRIP_ACCESSIBILITY
217 if (!s_pFactory)
218 // the attempt to load the lib, or to create the factory, failed
219 // -> fall back to a dummy factory
220 s_pFactory = new AccessibleDummyFactory;
222 m_bInitialized = true;
225 IAccessibleFactory& AccessibilityClient::getFactory()
227 ensureInitialized();
228 OSL_ENSURE( s_pFactory.is(), "AccessibilityClient::getFactory: at least a dummy factory should have been created!" );
229 return *s_pFactory;
233 } // namespace toolkit
235 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */