diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2016-11-03 15:53:09 +0300 |
---|---|---|
committer | Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de> | 2017-01-23 14:25:20 +0100 |
commit | 11cf1ca50d9bdee790d9082e51566864fbd23885 (patch) | |
tree | e6382f53e823cd63e36e7cb55b687ac3a9604a92 | |
parent | o3tl: add make_unique template till we can't use std::make_unique (diff) | |
download | core-11cf1ca50d9bdee790d9082e51566864fbd23885.tar.gz core-11cf1ca50d9bdee790d9082e51566864fbd23885.zip |
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>
-rw-r--r-- | sfx2/source/control/unoctitm.cxx | 40 |
1 files changed, 27 insertions, 13 deletions
diff --git a/sfx2/source/control/unoctitm.cxx b/sfx2/source/control/unoctitm.cxx index bba52c6f9722..a720f1873d98 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/util/URLTransformer.hpp> @@ -63,6 +64,7 @@ #include <sfx2/msgpool.hxx> #include <sfx2/objsh.hxx> +#include <o3tl/make_unique.hxx> #include <boost/scoped_ptr.hpp> #include <iostream> @@ -339,6 +341,29 @@ const ::com::sun::star::uno::Sequence< sal_Int8 >& SfxOfficeDispatch::impl_getSt 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 ::com::sun::star::util::URL& aURL, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aArgs ) throw ( ::com::sun::star::uno::RuntimeException, std::exception ) { @@ -346,15 +371,7 @@ void SAL_CALL SfxOfficeDispatch::dispatch( const ::com::sun::star::util::URL& aU if ( pControllerItem ) { #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. - com::sun::star::uno::ContextLayer layer( - new svt::JavaContext( com::sun::star::uno::getCurrentContext(), - true) ); + std::unique_ptr< css::uno::ContextLayer > layer(EnsureJavaContext()); #endif pControllerItem->dispatch( aURL, aArgs, ::com::sun::star::uno::Reference < ::com::sun::star::frame::XDispatchResultListener >() ); } @@ -368,10 +385,7 @@ void SAL_CALL SfxOfficeDispatch::dispatchWithNotification( const ::com::sun::sta if ( pControllerItem ) { #if HAVE_FEATURE_JAVA - // see comment for SfxOfficeDispatch::dispatch - com::sun::star::uno::ContextLayer layer( - new svt::JavaContext( com::sun::star::uno::getCurrentContext(), - true) ); + std::unique_ptr< css::uno::ContextLayer > layer(EnsureJavaContext()); #endif pControllerItem->dispatch( aURL, aArgs, rListener ); } |