include/sfx2/docmacromode.hxx | 2 ++ include/sfx2/strings.hrc | 1 + include/svtools/sfxecode.hxx | 1 - sfx2/source/doc/docmacromode.cxx | 30 ++++++++---------------------- sfx2/source/view/viewfrm.cxx | 6 +++++- svtools/inc/errtxt.hrc | 1 - 6 files changed, 16 insertions(+), 25 deletions(-)
New commits: commit 829f898f0076082c039494bc0fffe00e2dd4ac26 Author: Samuel Mehrbrodt <samuel.mehrbr...@allotropia.de> AuthorDate: Mon Jan 30 09:35:46 2023 +0100 Commit: Samuel Mehrbrodt <samuel.mehrbr...@allotropia.de> CommitDate: Mon Jan 30 12:26:07 2023 +0000 Show infobar instead of dialog when unsigned content is found Follow up to f41627ab60372345be646c53d967b65be43b562f Change-Id: I67dadad0fe69e29199c5bc160af1a46cc8aafac2 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/146338 Tested-by: Jenkins Reviewed-by: Samuel Mehrbrodt <samuel.mehrbr...@allotropia.de> diff --git a/include/sfx2/docmacromode.hxx b/include/sfx2/docmacromode.hxx index 7ed42f6a14dd..2a0421aa0c90 100644 --- a/include/sfx2/docmacromode.hxx +++ b/include/sfx2/docmacromode.hxx @@ -255,6 +255,8 @@ namespace sfx2 */ bool hasMacroLibrary() const; + bool hasUnsignedContentError() const; + /** determines whether the given document storage has sub storages containing scripts or macros. diff --git a/include/sfx2/strings.hrc b/include/sfx2/strings.hrc index e4133eb69203..bafda3df1a6c 100644 --- a/include/sfx2/strings.hrc +++ b/include/sfx2/strings.hrc @@ -294,6 +294,7 @@ #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_DISABLED_CONTENT_UNSIGNED NC_("STR_MACROS_DISABLED_CONTENT_UNSIGNED", "Macros are disabled. Macros are signed, but the document (containing document events) is not signed.") #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 4464d4230a35..8878b9d3f62f 100644 --- a/include/svtools/sfxecode.hxx +++ b/include/svtools/sfxecode.hxx @@ -34,7 +34,6 @@ 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_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_FORMAT_ROWCOL ErrCode(ErrCodeArea::Sfx, ErrCodeClass::NONE, 57) diff --git a/sfx2/source/doc/docmacromode.cxx b/sfx2/source/doc/docmacromode.cxx index bf17a0497a5d..db527ef3a036 100644 --- a/sfx2/source/doc/docmacromode.cxx +++ b/sfx2/source/doc/docmacromode.cxx @@ -74,38 +74,19 @@ namespace sfx2 IMacroDocumentAccess& m_rDocumentAccess; bool m_bMacroDisabledMessageShown; bool m_bDocMacroDisabledMessageShown; + bool m_bHasUnsignedContentError; explicit DocumentMacroMode_Data( IMacroDocumentAccess& rDocumentAccess ) :m_rDocumentAccess( rDocumentAccess ) ,m_bMacroDisabledMessageShown( false ) ,m_bDocMacroDisabledMessageShown( false ) + ,m_bHasUnsignedContentError( false ) { } }; - - //= helper - namespace { - - void lcl_showGeneralSfxErrorOnce( const Reference< XInteractionHandler >& rxHandler, ErrCode nSfxErrorCode, bool& rbAlreadyShown ) - { - if ( rbAlreadyShown ) - return; - - ErrorCodeRequest aErrorCodeRequest; - aErrorCodeRequest.ErrCode = sal_uInt32(nSfxErrorCode); - - SfxMedium::CallApproveHandler( rxHandler, Any( aErrorCodeRequest ), false ); - rbAlreadyShown = true; - } - - void lcl_showMacrosDisabledUnsignedContentError( const Reference< XInteractionHandler >& rxHandler, bool& rbAlreadyShown ) - { - lcl_showGeneralSfxErrorOnce( rxHandler, ERRCODE_SFX_DOCUMENT_MACRO_DISABLED_CONTENT_UNSIGNED, rbAlreadyShown ); - } - bool lcl_showMacroWarning( const Reference< XInteractionHandler >& rxHandler, const OUString& rDocumentLocation ) { @@ -231,7 +212,7 @@ namespace sfx2 !bHasValidContentSignature) { // When macros are signed, and the document has events which call macros, the document content needs to be signed too. - lcl_showMacrosDisabledUnsignedContentError(rxInteraction, m_xData->m_bDocMacroDisabledMessageShown); + m_xData->m_bHasUnsignedContentError = true; return disallowMacroExecution(); } else if ( bHasTrustedMacroSignature ) @@ -407,6 +388,11 @@ namespace sfx2 return bHasMacroLib; } + bool DocumentMacroMode::hasUnsignedContentError() const + { + return m_xData->m_bHasUnsignedContentError; + } + bool DocumentMacroMode::storageHasMacros( const Reference< XStorage >& rxStorage ) { diff --git a/sfx2/source/view/viewfrm.cxx b/sfx2/source/view/viewfrm.cxx index e8429ecf7721..1e4df24f60b9 100644 --- a/sfx2/source/view/viewfrm.cxx +++ b/sfx2/source/view/viewfrm.cxx @@ -1326,7 +1326,11 @@ void SfxViewFrame::AppendContainsMacrosInfobar() if (bHasDocumentMacros || bHasBoundConfigEvents) { - auto aResId = SvtSecurityOptions::IsMacroDisabled() ? STR_MACROS_DISABLED : STR_CONTAINS_MACROS; + auto aResId = STR_MACROS_DISABLED; + if (SvtSecurityOptions::IsMacroDisabled()) + aResId = STR_CONTAINS_MACROS; + else if (pObjImpl->aMacroMode.hasUnsignedContentError()) + aResId = STR_MACROS_DISABLED_CONTENT_UNSIGNED; auto pInfoBar = AppendInfoBar("macro", SfxResId(RID_SECURITY_WARNING_TITLE), SfxResId(aResId), InfobarType::WARNING); if (!pInfoBar) diff --git a/svtools/inc/errtxt.hrc b/svtools/inc/errtxt.hrc index ba403bc35559..83bcc18321bb 100644 --- a/svtools/inc/errtxt.hrc +++ b/svtools/inc/errtxt.hrc @@ -118,7 +118,6 @@ 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", "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", "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 },