From 1710f23e2152ec53a9d90c9bff850c9f4f026053 Mon Sep 17 00:00:00 2001 From: Mike Kaganski Date: Fri, 26 Jan 2018 11:37:58 +0100 Subject: Make handled flags for Java interaction handler static In commit 5785e4f4ab9c0e30d709e6150bc7230098ed550b, initial work to only show Java error dialogs once had been done. Still, in some cases, multiple such dialogs can still be shown. JavaInteractionHandler instances can be created in at least two contexts: in JavaContext::getValueByName, and in DesktopContext::getValueByName. Additionally, in the latter, it is not kept for subsequent reuse, but re- created anew each time. So, it is possible that "Java Missing" (and friends) dialogs will be shown multiple times per session. E.g., specific installed extensions (not using Java, but rather Python) can trigger said behavior in Desktop::doShutdown inside BackupFileHelper::tryPushExtensionInfo. This patch makes the "already handled" flags static, thus sharing the status among different handler instances. Also, unchanged-after-const-initializing m_bShowErrorsOnce is removed. Change-Id: I79d40639caa9764a04af9201c7e1a6fa624f03e5 Reviewed-on: https://gerrit.libreoffice.org/48678 Reviewed-by: Noel Grandin Tested-by: Jenkins Reviewed-by: Mike Kaganski --- svtools/source/java/javainteractionhandler.cxx | 52 ++++++++++++++++---------- 1 file changed, 32 insertions(+), 20 deletions(-) (limited to 'svtools') diff --git a/svtools/source/java/javainteractionhandler.cxx b/svtools/source/java/javainteractionhandler.cxx index 6eb906a23005..311bbcb23d24 100644 --- a/svtools/source/java/javainteractionhandler.cxx +++ b/svtools/source/java/javainteractionhandler.cxx @@ -39,18 +39,30 @@ using namespace com::sun::star::uno; using namespace com::sun::star::task; +namespace +{ +static struct JavaEvents { + bool bDisabledHandled : 1; + bool bInvalidSettingsHandled : 1; + bool bNotFoundHandled : 1; + bool bVMCreationFailureHandled : 1; + bool bRestartRequiredHandled : 1; + sal_uInt16 nResult_JavaDisabled = RET_NO; + JavaEvents() + : bDisabledHandled(false) + , bInvalidSettingsHandled(false) + , bNotFoundHandled(false) + , bVMCreationFailureHandled(false) + , bRestartRequiredHandled(false) + {} +} g_JavaEvents; +} + namespace svt { JavaInteractionHandler::JavaInteractionHandler() : - m_aRefCount(0), - m_bShowErrorsOnce(true), - m_bJavaDisabled_Handled(false), - m_bInvalidSettings_Handled(false), - m_bJavaNotFound_Handled(false), - m_bVMCreationFailure_Handled(false), - m_bRestartRequired_Handled(false), - m_nResult_JavaDisabled(RET_NO) + m_aRefCount(0) { } @@ -113,11 +125,11 @@ void SAL_CALL JavaInteractionHandler::handle( const Reference< XInteractionReque if ( anyExc >>= e1 ) { - if( ! (m_bShowErrorsOnce && m_bJavaNotFound_Handled)) + if( !g_JavaEvents.bNotFoundHandled ) { // No suitable JRE found SolarMutexGuard aSolarGuard; - m_bJavaNotFound_Handled = true; + g_JavaEvents.bNotFoundHandled = true; #if defined( MACOSX ) ScopedVclPtrInstance< MessageDialog > aWarningBox(nullptr, SvtResId(STR_WARNING_JAVANOTFOUND_MAC), VclMessageType::Warning); #elif defined( _WIN32 ) @@ -141,11 +153,11 @@ void SAL_CALL JavaInteractionHandler::handle( const Reference< XInteractionReque } else if ( anyExc >>= e2 ) { - if( !(m_bShowErrorsOnce && m_bInvalidSettings_Handled)) + if( !g_JavaEvents.bInvalidSettingsHandled ) { // javavendors.xml was updated and Java has not been configured yet SolarMutexGuard aSolarGuard; - m_bInvalidSettings_Handled = true; + g_JavaEvents.bInvalidSettingsHandled = true; #ifdef MACOSX ScopedVclPtrInstance< MessageDialog > aWarningBox(nullptr, SvtResId(STR_WARNING_INVALIDJAVASETTINGS_MAC), VclMessageType::Warning); #else @@ -161,10 +173,10 @@ void SAL_CALL JavaInteractionHandler::handle( const Reference< XInteractionReque } else if ( anyExc >>= e3 ) { - if( !(m_bShowErrorsOnce && m_bJavaDisabled_Handled)) + if( !g_JavaEvents.bDisabledHandled ) { SolarMutexGuard aSolarGuard; - m_bJavaDisabled_Handled = true; + g_JavaEvents.bDisabledHandled = true; // Java disabled. Give user a chance to enable Java inside Office. ScopedVclPtrInstance aQueryBox(nullptr , "JavaDisabledDialog", "svt/ui/javadisableddialog.ui"); @@ -174,21 +186,21 @@ void SAL_CALL JavaInteractionHandler::handle( const Reference< XInteractionReque jfw_setEnabled(true); } - m_nResult_JavaDisabled = nResult; + g_JavaEvents.nResult_JavaDisabled = nResult; } else { - nResult = m_nResult_JavaDisabled; + nResult = g_JavaEvents.nResult_JavaDisabled; } } else if ( anyExc >>= e4 ) { - if( !(m_bShowErrorsOnce && m_bVMCreationFailure_Handled)) + if( !g_JavaEvents.bVMCreationFailureHandled ) { // Java not correctly installed, or damaged SolarMutexGuard aSolarGuard; - m_bVMCreationFailure_Handled = true; + g_JavaEvents.bVMCreationFailureHandled = true; #ifdef MACOSX ScopedVclPtrInstance< MessageDialog > aErrorBox(nullptr, SvtResId(STR_ERROR_JVMCREATIONFAILED_MAC)); #else @@ -204,12 +216,12 @@ void SAL_CALL JavaInteractionHandler::handle( const Reference< XInteractionReque } else if ( anyExc >>= e5 ) { - if( !(m_bShowErrorsOnce && m_bRestartRequired_Handled)) + if( !g_JavaEvents.bRestartRequiredHandled ) { // a new JRE was selected, but office needs to be restarted //before it can be used. SolarMutexGuard aSolarGuard; - m_bRestartRequired_Handled = true; + g_JavaEvents.bRestartRequiredHandled = true; svtools::executeRestartDialog( comphelper::getProcessComponentContext(), nullptr, svtools::RESTART_REASON_JAVA); -- cgit v1.2.3