include/sfx2/strings.hrc | 1 include/svtools/sfxecode.hxx | 4 --- sfx2/source/doc/docmacromode.cxx | 25 ------------------------ sfx2/source/view/viewfrm.cxx | 40 +++++++++++++++++++++++++-------------- svtools/inc/errtxt.hrc | 3 -- 5 files changed, 27 insertions(+), 46 deletions(-)
New commits: commit f41627ab60372345be646c53d967b65be43b562f Author: Samuel Mehrbrodt <samuel.mehrbr...@allotropia.de> AuthorDate: Fri Jan 27 10:34:29 2023 +0100 Commit: Samuel Mehrbrodt <samuel.mehrbr...@allotropia.de> CommitDate: Mon Jan 30 08:15:09 2023 +0000 Show infobar instead of blocking dialog when macros are not allowed Change-Id: I45f898aaf15cb3540abff32954881186015cc6e5 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/146250 Tested-by: Jenkins Reviewed-by: Samuel Mehrbrodt <samuel.mehrbr...@allotropia.de> diff --git a/include/sfx2/strings.hrc b/include/sfx2/strings.hrc index 46131484099b..e4133eb69203 100644 --- a/include/sfx2/strings.hrc +++ b/include/sfx2/strings.hrc @@ -293,6 +293,7 @@ #define STR_REFRESH_MASTER_PASSWORD NC_("STR_REFRESH_MASTER_PASSWORD", "The master password is stored in an outdated format, you should refresh it") #define STR_REFRESH_PASSWORD NC_("STR_REFRESH_PASSWORD", "Refresh Password") #define STR_CONTAINS_MACROS NC_("STR_CONTAINS_MACROS", "Macros in this document are disabled due to the Macro Security settings.") +#define STR_MACROS_DISABLED NC_("STR_MACROS_DISABLED", "Macros are disabled due to the Macro Security settings.") #define STR_MACROS NC_("STR_MACROS", "Show Macros") #define STR_EVENTS NC_("STR_EVENTS", "Show Events") diff --git a/include/svtools/sfxecode.hxx b/include/svtools/sfxecode.hxx index fe6f26dc3623..4464d4230a35 100644 --- a/include/svtools/sfxecode.hxx +++ b/include/svtools/sfxecode.hxx @@ -34,13 +34,9 @@ class ErrCode; #define ERRCODE_SFX_CANTGETPASSWD ErrCode(ErrCodeArea::Sfx, ErrCodeClass::Read, 42) #define ERRCODE_SFX_NOMOREDOCUMENTSALLOWED ErrCode(WarningFlag::Yes, ErrCodeArea::Sfx, ErrCodeClass::NONE, 44) #define ERRCODE_SFX_CANTCREATEBACKUP ErrCode(ErrCodeArea::Sfx, ErrCodeClass::Create, 50) -#define ERRCODE_SFX_MACROS_SUPPORT_DISABLED ErrCode(WarningFlag::Yes, ErrCodeArea::Sfx, ErrCodeClass::NONE, 51) -#define ERRCODE_SFX_DOCUMENT_MACRO_DISABLED ErrCode(WarningFlag::Yes, ErrCodeArea::Sfx, ErrCodeClass::NONE, 52) #define ERRCODE_SFX_DOCUMENT_MACRO_DISABLED_CONTENT_UNSIGNED ErrCode(WarningFlag::Yes, ErrCodeArea::Sfx, ErrCodeClass::NONE, 53) #define ERRCODE_SFX_SHARED_NOPASSWORDCHANGE ErrCode(WarningFlag::Yes, ErrCodeArea::Sfx, ErrCodeClass::NONE, 54) #define ERRCODE_SFX_INCOMPLETE_ENCRYPTION ErrCode(WarningFlag::Yes, ErrCodeArea::Sfx, ErrCodeClass::NONE, 55) -#define ERRCODE_SFX_DOCUMENT_MACRO_DISABLED_MAC \ - ErrCode(WarningFlag::Yes, ErrCodeArea::Sfx, ErrCodeClass::NONE, 56) #define ERRCODE_SFX_FORMAT_ROWCOL ErrCode(ErrCodeArea::Sfx, ErrCodeClass::NONE, 57) diff --git a/sfx2/source/doc/docmacromode.cxx b/sfx2/source/doc/docmacromode.cxx index ae70c6a8c056..bf17a0497a5d 100644 --- a/sfx2/source/doc/docmacromode.cxx +++ b/sfx2/source/doc/docmacromode.cxx @@ -101,22 +101,6 @@ namespace sfx2 rbAlreadyShown = true; } - - void lcl_showMacrosDisabledError( const Reference< XInteractionHandler >& rxHandler, bool& rbAlreadyShown ) - { - lcl_showGeneralSfxErrorOnce( rxHandler, ERRCODE_SFX_MACROS_SUPPORT_DISABLED, rbAlreadyShown ); - } - - - void lcl_showDocumentMacrosDisabledError( const Reference< XInteractionHandler >& rxHandler, bool& rbAlreadyShown ) - { -#ifdef MACOSX - lcl_showGeneralSfxErrorOnce( rxHandler, ERRCODE_SFX_DOCUMENT_MACRO_DISABLED_MAC, rbAlreadyShown ); -#else - lcl_showGeneralSfxErrorOnce( rxHandler, ERRCODE_SFX_DOCUMENT_MACRO_DISABLED, rbAlreadyShown ); -#endif - } - void lcl_showMacrosDisabledUnsignedContentError( const Reference< XInteractionHandler >& rxHandler, bool& rbAlreadyShown ) { lcl_showGeneralSfxErrorOnce( rxHandler, ERRCODE_SFX_DOCUMENT_MACRO_DISABLED_CONTENT_UNSIGNED, rbAlreadyShown ); @@ -156,7 +140,6 @@ namespace sfx2 if ( SvtSecurityOptions::IsMacroDisabled() ) { // no macro should be executed at all - lcl_showMacrosDisabledError( rxInteraction, m_xData->m_bMacroDisabledMessageShown ); return disallowMacroExecution(); } @@ -226,7 +209,6 @@ namespace sfx2 // at this point it is clear that the document is not in the secure location if ( nMacroExecutionMode == MacroExecMode::FROM_LIST_NO_WARN ) { - lcl_showDocumentMacrosDisabledError( rxInteraction, m_xData->m_bDocMacroDisabledMessageShown ); return disallowMacroExecution(); } @@ -242,8 +224,6 @@ namespace sfx2 SignatureState nSignatureState = m_xData->m_rDocumentAccess.getScriptingSignatureState(); if ( nSignatureState == SignatureState::BROKEN ) { - if (!bAllowUIToAddAuthor) - lcl_showDocumentMacrosDisabledError(rxInteraction, m_xData->m_bDocMacroDisabledMessageShown); return disallowMacroExecution(); } else if ( m_xData->m_rDocumentAccess.macroCallsSeenWhileLoading() && @@ -263,8 +243,6 @@ namespace sfx2 || nSignatureState == SignatureState::NOTVALIDATED ) { // there is valid signature, but it is not from the trusted author - if (!bAllowUIToAddAuthor) - lcl_showDocumentMacrosDisabledError(rxInteraction, m_xData->m_bDocMacroDisabledMessageShown); return disallowMacroExecution(); } } @@ -274,9 +252,6 @@ namespace sfx2 || ( nMacroExecutionMode == MacroExecMode::FROM_LIST_AND_SIGNED_WARN ) ) { - if ( nMacroExecutionMode == MacroExecMode::FROM_LIST_AND_SIGNED_WARN ) - lcl_showDocumentMacrosDisabledError( rxInteraction, m_xData->m_bDocMacroDisabledMessageShown ); - return disallowMacroExecution(); } } diff --git a/sfx2/source/view/viewfrm.cxx b/sfx2/source/view/viewfrm.cxx index 68ea4a3f8933..e8429ecf7721 100644 --- a/sfx2/source/view/viewfrm.cxx +++ b/sfx2/source/view/viewfrm.cxx @@ -53,6 +53,7 @@ #if !ENABLE_WASM_STRIP_PINGUSER #include <unotools/VersionConfig.hxx> #endif +#include <unotools/securityoptions.hxx> #include <svtools/miscopt.hxx> #include <comphelper/diagnose_ex.hxx> #include <com/sun/star/container/XIndexAccess.hpp> @@ -1285,19 +1286,10 @@ void SfxViewFrame::AppendReadOnlyInfobar() void SfxViewFrame::AppendContainsMacrosInfobar() { - auto pInfoBar = AppendInfoBar("macro", SfxResId(RID_SECURITY_WARNING_TITLE), SfxResId(STR_CONTAINS_MACROS), InfobarType::WARNING); - if (!pInfoBar) - return; - SfxObjectShell_Impl* pObjImpl = m_xObjSh->Get_Impl(); // what's the difference between pObjImpl->documentStorageHasMacros() and pObjImpl->aMacroMode.hasMacroLibrary() ? - if (pObjImpl->aMacroMode.hasMacroLibrary()) - { - weld::Button& rMacroButton = pInfoBar->addButton(); - rMacroButton.set_label(SfxResId(STR_MACROS)); - rMacroButton.connect_clicked(LINK(this, SfxViewFrame, MacroButtonHandler)); - } + bool bHasDocumentMacros = pObjImpl->aMacroMode.hasMacroLibrary(); Reference<XModel> xModel = m_xObjSh->GetModel(); uno::Reference<document::XEventsSupplier> xSupplier(xModel, uno::UNO_QUERY); @@ -1332,11 +1324,31 @@ void SfxViewFrame::AppendContainsMacrosInfobar() } } - if (bHasBoundConfigEvents) + if (bHasDocumentMacros || bHasBoundConfigEvents) { - weld::Button& rEventButton = pInfoBar->addButton(); - rEventButton.set_label(SfxResId(STR_EVENTS)); - rEventButton.connect_clicked(LINK(this, SfxViewFrame, EventButtonHandler)); + auto aResId = SvtSecurityOptions::IsMacroDisabled() ? STR_MACROS_DISABLED : STR_CONTAINS_MACROS; + auto pInfoBar = AppendInfoBar("macro", SfxResId(RID_SECURITY_WARNING_TITLE), + SfxResId(aResId), InfobarType::WARNING); + if (!pInfoBar) + return; + + // No access to macro dialog when macros are disabled globally. + if (SvtSecurityOptions::IsMacroDisabled()) + return; + + if (bHasDocumentMacros) + { + weld::Button& rMacroButton = pInfoBar->addButton(); + rMacroButton.set_label(SfxResId(STR_MACROS)); + rMacroButton.connect_clicked(LINK(this, SfxViewFrame, MacroButtonHandler)); + } + + if (bHasBoundConfigEvents) + { + weld::Button& rEventButton = pInfoBar->addButton(); + rEventButton.set_label(SfxResId(STR_EVENTS)); + rEventButton.connect_clicked(LINK(this, SfxViewFrame, EventButtonHandler)); + } } } diff --git a/svtools/inc/errtxt.hrc b/svtools/inc/errtxt.hrc index 639b7e49a7c4..ba403bc35559 100644 --- a/svtools/inc/errtxt.hrc +++ b/svtools/inc/errtxt.hrc @@ -118,10 +118,7 @@ const ErrMsgCode RID_ERRHDL[] = { NC_("RID_ERRHDL", "This document contains attributes that cannot be saved in the selected format.\nPlease save the document in a %PRODUCTNAME %PRODUCTVERSION file format."), ERRCODE_IO_NOTSTORABLEINBINARYFORMAT }, { NC_("RID_ERRHDL", "The maximum number of documents that can be opened at the same time has been reached. You need to close one or more documents before you can open a new document."), ERRCODE_SFX_NOMOREDOCUMENTSALLOWED }, { NC_("RID_ERRHDL", "Could not create backup copy.") , ERRCODE_SFX_CANTCREATEBACKUP }, - { NC_("RID_ERRHDL", "An attempt was made to execute a macro.\nFor security reasons, macro support is disabled."), ERRCODE_SFX_MACROS_SUPPORT_DISABLED }, { NC_("RID_ERRHDL", "Execution of macros is disabled. Macros are signed, but the document (containing document events) is not signed."), ERRCODE_SFX_DOCUMENT_MACRO_DISABLED_CONTENT_UNSIGNED }, - { NC_("RID_ERRHDL", "This document contains macros.\n\nMacros may contain viruses. Execution of macros is disabled due to the current macro security setting in %PRODUCTNAME - Preferences - %PRODUCTNAME - Security.\n\nTherefore, some functionality may not be available.") , ERRCODE_SFX_DOCUMENT_MACRO_DISABLED_MAC }, - { NC_("RID_ERRHDL", "This document contains macros.\n\nMacros may contain viruses. Execution of macros is disabled due to the current macro security setting in Tools - Options - %PRODUCTNAME - Security.\n\nTherefore, some functionality may not be available.") , ERRCODE_SFX_DOCUMENT_MACRO_DISABLED }, { NC_("RID_ERRHDL", "The encrypted document contains unexpected non-encrypted streams.\n\nThis could be the result of document manipulation.\n\nWe recommend that you do not trust the content of the current document.\nExecution of macros is disabled for this document.\n ") , ERRCODE_SFX_INCOMPLETE_ENCRYPTION }, { NC_("RID_ERRHDL", "Invalid data length.") , ERRCODE_IO_INVALIDLENGTH }, { NC_("RID_ERRHDL", "Function not possible: path contains current directory.") , ERRCODE_IO_CURRENTDIR },