From a661549b70d30d8925e9839ca97e832111f289b5 Mon Sep 17 00:00:00 2001 From: Caolán McNamara Date: Wed, 7 Aug 2019 17:37:11 +0100 Subject: warn on load when a document binds an event to a macro MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit a) treat shared/Scripts equivalently to document scripts This doesn't automatically warn/block running those scripts when used in a freshly loaded document on its own however because DocumentMacroMode::checkMacrosOnLoading will see at... if ( m_xData->m_rDocumentAccess.documentStorageHasMacros() || hasMacroLibrary() ) that the document contains no macros and flip the allow macros flag to true so that potentially new uses of macros added by the user during the edit are allowed to run b) so, add an additional flag to indicate existence of use of macros in a document c) for odf import, set it when a script:event-listener tag is encountered d) for html import when registerScriptEvents or SwFormatINetFormat::SetMacroTable is called e) for doc import when Read_F_Macro or StoreMacroCmds is called as well for good measure f) for xls import when registerScriptEvent or ScMacroInfo::SetMacro is called g) for oox import when VbaProject::attachMacros is called Change-Id: Ic1203d8ec7dfc217aa217135033ae9db2888e19b Reviewed-on: https://gerrit.libreoffice.org/77386 Tested-by: Jenkins Reviewed-by: Michael Stahl Reviewed-by: Caolán McNamara Tested-by: Caolán McNamara --- oox/source/ole/vbaproject.cxx | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'oox') diff --git a/oox/source/ole/vbaproject.cxx b/oox/source/ole/vbaproject.cxx index b1591a2fb7f5..b466bfc2ba6e 100644 --- a/oox/source/ole/vbaproject.cxx +++ b/oox/source/ole/vbaproject.cxx @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -515,6 +516,8 @@ void VbaProject::attachMacros() { if( !maMacroAttachers.empty() && mxContext.is() ) try { + comphelper::DocumentInfo::notifyMacroEventRead(mxDocModel); + Reference< XMultiComponentFactory > xFactory( mxContext->getServiceManager(), UNO_SET_THROW ); Sequence< Any > aArgs( 2 ); aArgs[ 0 ] <<= mxDocModel; @@ -522,6 +525,7 @@ void VbaProject::attachMacros() Reference< XVBAMacroResolver > xResolver( xFactory->createInstanceWithArgumentsAndContext( "com.sun.star.script.vba.VBAMacroResolver", aArgs, mxContext ), UNO_QUERY_THROW ); maMacroAttachers.forEachMem( &VbaMacroAttacherBase::resolveAndAttachMacro, ::std::cref( xResolver ) ); + } catch(const Exception& ) { -- cgit