diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2016-11-03 15:53:09 +0300 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2016-11-08 07:52:14 +0000 |
commit | bc57a3e319bccb2d48549a3134d5dcd4336d4533 (patch) | |
tree | 35d39b2b355339d64df5a437a9107bed5713180e /sfx2 | |
parent | c123c528bf1550e544b29e5a22a94a0452d5f349 (diff) |
tdf#88023: Only warn about unavailable JRE once
The underlying design is that there's a single JavaInteractionHandler
instance owned by a JavaContext, and that JavaContext installed in
Desktop::Main (desktop/source/app/app.cxx).
This patch ensures that no additional JavaContext is created in
SfxOfficeDispatch::dispatch*() functions unless they are used without
preinstalled JavaContext.
Thanks to Stephan Bergmann for guidance!
Change-Id: I2569df221067a5b9bf1f6cd5d8f69b561316a170
Reviewed-on: https://gerrit.libreoffice.org/30529
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'sfx2')
-rw-r--r-- | sfx2/source/control/unoctitm.cxx | 38 |
1 files changed, 28 insertions, 10 deletions
diff --git a/sfx2/source/control/unoctitm.cxx b/sfx2/source/control/unoctitm.cxx index de693a1a65f6..cb7590c96c94 100644 --- a/sfx2/source/control/unoctitm.cxx +++ b/sfx2/source/control/unoctitm.cxx @@ -26,6 +26,7 @@ #include <svl/itemset.hxx> #include <svl/visitem.hxx> #include <svtools/javacontext.hxx> +#include <svtools/javainteractionhandler.hxx> #include <svl/itempool.hxx> #include <tools/urlobj.hxx> #include <com/sun/star/awt/FontDescriptor.hpp> @@ -75,6 +76,8 @@ #include <map> #include <memory> +#include <o3tl/make_unique.hxx> + #include <sal/log.hxx> #include <LibreOfficeKit/LibreOfficeKitEnums.h> #include <comphelper/lok.hxx> @@ -192,6 +195,29 @@ const css::uno::Sequence< sal_Int8 >& SfxOfficeDispatch::impl_getStaticIdentifie return seqID ; } +#if HAVE_FEATURE_JAVA +// The JavaContext contains an interaction handler which is used when +// the creation of a Java Virtual Machine fails. There shall only be one +// user notification (message box) even if the same error (interaction) +// reoccurs. The effect is, that if a user selects a menu entry than they +// may get only one notification that a JRE is not selected. +// This function checks if a JavaContext is already available (typically +// created by Desktop::Main() in app.cxx), and creates new one if not. +namespace { +std::unique_ptr< css::uno::ContextLayer > EnsureJavaContext() +{ + css::uno::Reference< css::uno::XCurrentContext > xContext(css::uno::getCurrentContext()); + if (xContext.is()) + { + css::uno::Reference< css::task::XInteractionHandler > xHandler; + xContext->getValueByName(JAVA_INTERACTION_HANDLER_NAME) >>= xHandler; + if (xHandler.is()) + return nullptr; // No need to add new layer: JavaContext already present + } + return o3tl::make_unique< css::uno::ContextLayer >(new svt::JavaContext(xContext)); +} +} +#endif void SAL_CALL SfxOfficeDispatch::dispatch( const css::util::URL& aURL, const css::uno::Sequence< css::beans::PropertyValue >& aArgs ) throw ( css::uno::RuntimeException, std::exception ) { @@ -199,14 +225,7 @@ void SAL_CALL SfxOfficeDispatch::dispatch( const css::util::URL& aURL, const css if ( pImpl ) { #if HAVE_FEATURE_JAVA - // The JavaContext contains an interaction handler which is used when - // the creation of a Java Virtual Machine fails. The second parameter - // indicates, that there shall only be one user notification (message box) - // even if the same error (interaction) reoccurs. The effect is, that if a - // user selects a menu entry than they may get only one notification that - // a JRE is not selected. - css::uno::ContextLayer layer( - new svt::JavaContext( css::uno::getCurrentContext() ) ); + std::unique_ptr< css::uno::ContextLayer > layer(EnsureJavaContext()); #endif pImpl->dispatch( aURL, aArgs, css::uno::Reference < css::frame::XDispatchResultListener >() ); } @@ -220,8 +239,7 @@ void SAL_CALL SfxOfficeDispatch::dispatchWithNotification( const css::util::URL& if ( pImpl ) { #if HAVE_FEATURE_JAVA - // see comment for SfxOfficeDispatch::dispatch - css::uno::ContextLayer layer( new svt::JavaContext( css::uno::getCurrentContext() ) ); + std::unique_ptr< css::uno::ContextLayer > layer(EnsureJavaContext()); #endif pImpl->dispatch( aURL, aArgs, rListener ); } |