comphelper/source/misc/configuration.cxx | 15 ++++---- cui/source/options/optfltr.cxx | 19 ++++++---- include/comphelper/configuration.hxx | 56 ++++++++++++++++++++----------- pyuno/source/loader/pyuno_loader.cxx | 15 -------- 4 files changed, 58 insertions(+), 47 deletions(-)
New commits: commit 208a63779652789371f782b8e856f762baee2af1 Author: Stephan Bergmann <stephan.bergm...@allotropia.de> AuthorDate: Wed Jan 17 18:22:55 2024 +0100 Commit: Stephan Bergmann <stephan.bergm...@allotropia.de> CommitDate: Wed Jan 17 21:33:02 2024 +0100 Add back XComponentContext to officecfg::...::get() calls 4256c764aee0777770466115a97420d9b55c23ac "do not pass XComponentContext to officecfg::...::get() calls" had removed it, for performance reasons, but 8a695046cfcc8f9ec835b208b0d56ca821a3ff84 "tdf#158375 Hack to make sure process service factory is set" is a case where it should be passed in. To hopefully avoid performance regressions, don't default to comphelper::getProcessComponentContext() for what gets passed in, but default to an empty Reference and only call comphelper::getProcessComponentContext() when actually needed in the implementation. Change-Id: I5b75ac2c28f36e21d1c8bc368b0b972c33c61a51 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/162205 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <stephan.bergm...@allotropia.de> diff --git a/comphelper/source/misc/configuration.cxx b/comphelper/source/misc/configuration.cxx index 00179ea010da..ef89867dd50b 100644 --- a/comphelper/source/misc/configuration.cxx +++ b/comphelper/source/misc/configuration.cxx @@ -62,9 +62,10 @@ OUString extendLocalizedPath(std::u16string_view path, OUString const & locale) } std::shared_ptr< comphelper::ConfigurationChanges > -comphelper::ConfigurationChanges::create() +comphelper::ConfigurationChanges::create( + css::uno::Reference<css::uno::XComponentContext> const & context) { - return detail::ConfigurationWrapper::get().createChanges(); + return detail::ConfigurationWrapper::get(context).createChanges(); } comphelper::ConfigurationChanges::~ConfigurationChanges() {} @@ -101,9 +102,10 @@ comphelper::ConfigurationChanges::getSet(OUString const & path) const } comphelper::detail::ConfigurationWrapper const & -comphelper::detail::ConfigurationWrapper::get() +comphelper::detail::ConfigurationWrapper::get( + css::uno::Reference<css::uno::XComponentContext> const & context) { - static comphelper::detail::ConfigurationWrapper WRAPPER; + static comphelper::detail::ConfigurationWrapper WRAPPER(context); return WRAPPER; } @@ -131,8 +133,9 @@ public: } }; -comphelper::detail::ConfigurationWrapper::ConfigurationWrapper(): - context_(comphelper::getProcessComponentContext()), +comphelper::detail::ConfigurationWrapper::ConfigurationWrapper( + css::uno::Reference<css::uno::XComponentContext> const & context): + context_(context.is() ? context : comphelper::getProcessComponentContext()), access_(css::configuration::ReadWriteAccess::create(context_, "*")), mbDisposed(false) { diff --git a/cui/source/options/optfltr.cxx b/cui/source/options/optfltr.cxx index 0c1c2b54306a..0ecd2215716d 100644 --- a/cui/source/options/optfltr.cxx +++ b/cui/source/options/optfltr.cxx @@ -237,8 +237,8 @@ namespace { struct Functions { - bool (*FnIs)(); - bool (*FnIsReadOnly)(); + bool (*FnIs)(css::uno::Reference<css::uno::XComponentContext> const &); + bool (*FnIsReadOnly)(css::uno::Reference<css::uno::XComponentContext> const &); void (*FnSet)(const bool& bFlag, const std::shared_ptr<comphelper::ConfigurationChanges>&); template <class reg> static constexpr Functions fromReg() { @@ -294,13 +294,14 @@ bool OfaMSFilterTabPage2::FillItemSet( SfxItemSet* ) if (nEntry != -1) { bool bCheck = m_xCheckLB->get_toggle(nEntry, 0); - if (bCheck != (rEntry.load.FnIs)()) + if (bCheck != (rEntry.load.FnIs)(css::uno::Reference<css::uno::XComponentContext>())) (rEntry.load.FnSet)(bCheck, pBatch); if (rEntry.save.FnIs) { bCheck = m_xCheckLB->get_toggle(nEntry, 1); - if (bCheck != (rEntry.save.FnIs)()) + if (bCheck != (rEntry.save.FnIs)( + css::uno::Reference<css::uno::XComponentContext>())) (rEntry.save.FnSet)(bCheck, pBatch); } } @@ -353,15 +354,17 @@ void OfaMSFilterTabPage2::Reset( const SfxItemSet* ) int nEntry = GetEntry4Type( rArr.eType ); if (nEntry != -1) { - bool bCheck = (rArr.load.FnIs)(); - bool bReadOnly = (rArr.load.FnIsReadOnly)(); + bool bCheck = (rArr.load.FnIs)(css::uno::Reference<css::uno::XComponentContext>()); + bool bReadOnly = (rArr.load.FnIsReadOnly)( + css::uno::Reference<css::uno::XComponentContext>()); m_xCheckLB->set_toggle(nEntry, bCheck ? TRISTATE_TRUE : TRISTATE_FALSE, 0); m_xCheckLB->set_sensitive(nEntry, !bReadOnly, 0); if (rArr.save.FnIs) { - bCheck = (rArr.save.FnIs)(); - bReadOnly = (rArr.save.FnIsReadOnly)(); + bCheck = (rArr.save.FnIs)(css::uno::Reference<css::uno::XComponentContext>()); + bReadOnly = (rArr.save.FnIsReadOnly)( + css::uno::Reference<css::uno::XComponentContext>()); m_xCheckLB->set_toggle(nEntry, bCheck ? TRISTATE_TRUE : TRISTATE_FALSE, 1); m_xCheckLB->set_sensitive(nEntry, !bReadOnly, 1); } diff --git a/include/comphelper/configuration.hxx b/include/comphelper/configuration.hxx index 16cf19c0109c..f248decad3a5 100644 --- a/include/comphelper/configuration.hxx +++ b/include/comphelper/configuration.hxx @@ -51,7 +51,9 @@ namespace detail { class ConfigurationWrapper; } /// directly. class COMPHELPER_DLLPUBLIC ConfigurationChanges { public: - static std::shared_ptr<ConfigurationChanges> create(); + static std::shared_ptr<ConfigurationChanges> create( + css::uno::Reference<css::uno::XComponentContext> const & context + = css::uno::Reference<css::uno::XComponentContext>()); ~ConfigurationChanges(); @@ -91,7 +93,8 @@ class ConfigurationChangesListener; class COMPHELPER_DLLPUBLIC ConfigurationWrapper { friend class ConfigurationChangesListener; public: - static ConfigurationWrapper const & get(); + static ConfigurationWrapper const & get( + css::uno::Reference<css::uno::XComponentContext> const & context); bool isReadOnly(OUString const & path) const; @@ -129,7 +132,8 @@ public: std::shared_ptr< ConfigurationChanges > createChanges() const; private: - SAL_DLLPRIVATE explicit ConfigurationWrapper(); + SAL_DLLPRIVATE explicit ConfigurationWrapper( + css::uno::Reference<css::uno::XComponentContext> const & context); SAL_DLLPRIVATE ~ConfigurationWrapper(); @@ -211,22 +215,26 @@ template< typename T, typename U > struct ConfigurationProperty { /// Get the read-only status of the given (non-localized) configuration /// property. - static bool isReadOnly() + static bool isReadOnly( + css::uno::Reference<css::uno::XComponentContext> const & context + = css::uno::Reference<css::uno::XComponentContext>()) { - return detail::ConfigurationWrapper::get().isReadOnly(T::path()); + return detail::ConfigurationWrapper::get(context).isReadOnly(T::path()); } /// Get the value of the given (non-localized) configuration property. /// /// For nillable properties, U is of type std::optional<U'>. - static U get() + static U get( + css::uno::Reference<css::uno::XComponentContext> const & context + = css::uno::Reference<css::uno::XComponentContext>()) { if (comphelper::IsFuzzing()) return U(); // Folding this into one statement causes a bogus error at least with // Red Hat GCC 4.6.2-1: css::uno::Any a( - detail::ConfigurationWrapper::get().getPropertyValue( + detail::ConfigurationWrapper::get(context).getPropertyValue( T::path())); return detail::Convert< U >::fromAny(a); } @@ -260,9 +268,11 @@ template< typename T, typename U > struct ConfigurationLocalizedProperty { /// Get the read-only status of the given (localized) configuration /// property. - static bool isReadOnly() + static bool isReadOnly( + css::uno::Reference<css::uno::XComponentContext> const & context + = css::uno::Reference<css::uno::XComponentContext>()) { - return detail::ConfigurationWrapper::get().isReadOnly(T::path()); + return detail::ConfigurationWrapper::get(context).isReadOnly(T::path()); } /// Get the value of the given localized configuration property, for the @@ -270,12 +280,14 @@ template< typename T, typename U > struct ConfigurationLocalizedProperty /// com.sun.star.configuration.theDefaultProvider. /// /// For nillable properties, U is of type std::optional<U'>. - static U get() + static U get( + css::uno::Reference<css::uno::XComponentContext> const & context + = css::uno::Reference<css::uno::XComponentContext>()) { // Folding this into one statement causes a bogus error at least with // Red Hat GCC 4.6.2-1: css::uno::Any a( - detail::ConfigurationWrapper::get(). + detail::ConfigurationWrapper::get(context). getLocalizedPropertyValue(T::path())); return detail::Convert< U >::fromAny(a); } @@ -309,17 +321,20 @@ private: /// given configuration group. template< typename T > struct ConfigurationGroup { /// Get the read-only status of the given configuration group. - static bool isReadOnly() + static bool isReadOnly( + css::uno::Reference<css::uno::XComponentContext> const & context + = css::uno::Reference<css::uno::XComponentContext>()) { - return detail::ConfigurationWrapper::get().isReadOnly(T::path()); + return detail::ConfigurationWrapper::get(context).isReadOnly(T::path()); } /// Get read-only access to the given configuration group. static css::uno::Reference< css::container::XHierarchicalNameAccess > - get() + get(css::uno::Reference<css::uno::XComponentContext> const & context + = css::uno::Reference<css::uno::XComponentContext>()) { - return detail::ConfigurationWrapper::get().getGroupReadOnly( + return detail::ConfigurationWrapper::get(context).getGroupReadOnly( T::path()); } @@ -348,17 +363,20 @@ private: /// given configuration set. template< typename T > struct ConfigurationSet { /// Get the read-only status of the given configuration set. - static bool isReadOnly() + static bool isReadOnly( + css::uno::Reference<css::uno::XComponentContext> const & context + = css::uno::Reference<css::uno::XComponentContext>()) { - return detail::ConfigurationWrapper::get().isReadOnly(T::path()); + return detail::ConfigurationWrapper::get(context).isReadOnly(T::path()); } /// Get read-only access to the given configuration set. static css::uno::Reference< css::container::XNameAccess > - get() + get(css::uno::Reference<css::uno::XComponentContext> const & context + = css::uno::Reference<css::uno::XComponentContext>()) { - return detail::ConfigurationWrapper::get().getSetReadOnly( + return detail::ConfigurationWrapper::get(context).getSetReadOnly( T::path()); } diff --git a/pyuno/source/loader/pyuno_loader.cxx b/pyuno/source/loader/pyuno_loader.cxx index b02ad302fa80..0828e9497f51 100644 --- a/pyuno/source/loader/pyuno_loader.cxx +++ b/pyuno/source/loader/pyuno_loader.cxx @@ -34,8 +34,6 @@ #include <cppuhelper/factory.hxx> -#include <com/sun/star/lang/XMultiServiceFactory.hpp> -#include <com/sun/star/uno/DeploymentException.hpp> #include <com/sun/star/uno/XComponentContext.hpp> #include <comphelper/processfactory.hxx> @@ -247,18 +245,7 @@ extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface* pyuno_Loader_get_implementation( css::uno::XComponentContext* ctx , css::uno::Sequence<css::uno::Any> const&) { - //HACK: Reading the configuration via officecfg::... below internally needs the - // comphelper::getProcessServiceFactory(), which might not be set if this code is e.g. executed - // in a uno.bin process when installing a LibreOffice extension written in Python, so make sure - // the process service factory is set: - try { - comphelper::getProcessServiceFactory(); - } catch (css::uno::DeploymentException const &) { - comphelper::setProcessServiceFactory( - css::uno::Reference<css::lang::XMultiServiceFactory>( - ctx->getServiceManager(), css::uno::UNO_QUERY_THROW)); - } - if (officecfg::Office::Common::Security::Scripting::DisablePythonRuntime::get()) + if (officecfg::Office::Common::Security::Scripting::DisablePythonRuntime::get(ctx)) return nullptr; // tdf#114815 init python only once, via single-instace="true" in pythonloader.component