sfx2/source/control/unoctitm.cxx | 38 ++++++++++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 10 deletions(-)
New commits: commit bc57a3e319bccb2d48549a3134d5dcd4336d4533 Author: Mike Kaganski <mike.kagan...@collabora.com> Date: Thu Nov 3 15:53:09 2016 +0300 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 <c...@libreoffice.org> Reviewed-by: Stephan Bergmann <sberg...@redhat.com> diff --git a/sfx2/source/control/unoctitm.cxx b/sfx2/source/control/unoctitm.cxx index de693a1..cb7590c 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 ); } _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits