diff options
author | Caolán McNamara <caolanm@redhat.com> | 2019-08-07 17:37:11 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2019-08-13 13:26:15 +0200 |
commit | b3edf85e0fe6ca03dc26e1bf531be82193bc9627 (patch) | |
tree | 62887e38b2f0b06ca8e74fffd126560b5b0c8049 /sfx2 | |
parent | c78dd0a726b32d922a0d75a26a51d4c30612368c (diff) |
warn on load when a document binds an event to a macro
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/77131
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'sfx2')
-rw-r--r-- | sfx2/source/doc/docmacromode.cxx | 2 | ||||
-rw-r--r-- | sfx2/source/doc/objmisc.cxx | 13 | ||||
-rw-r--r-- | sfx2/source/doc/objstor.cxx | 10 | ||||
-rw-r--r-- | sfx2/source/doc/objxtor.cxx | 1 | ||||
-rw-r--r-- | sfx2/source/doc/sfxbasemodel.cxx | 7 | ||||
-rw-r--r-- | sfx2/source/inc/objshimp.hxx | 4 |
6 files changed, 28 insertions, 9 deletions
diff --git a/sfx2/source/doc/docmacromode.cxx b/sfx2/source/doc/docmacromode.cxx index cef89b0d0aa2..d43c1b1be065 100644 --- a/sfx2/source/doc/docmacromode.cxx +++ b/sfx2/source/doc/docmacromode.cxx @@ -394,7 +394,7 @@ namespace sfx2 } else { - if ( m_xData->m_rDocumentAccess.documentStorageHasMacros() || hasMacroLibrary() ) + if (m_xData->m_rDocumentAccess.documentStorageHasMacros() || hasMacroLibrary() || m_xData->m_rDocumentAccess.macroCallsSeenWhileLoading()) { bAllow = adjustMacroMode( rxInteraction ); } diff --git a/sfx2/source/doc/objmisc.cxx b/sfx2/source/doc/objmisc.cxx index d9ab5e4944ce..a61e1e8b42e1 100644 --- a/sfx2/source/doc/objmisc.cxx +++ b/sfx2/source/doc/objmisc.cxx @@ -1388,13 +1388,7 @@ ErrCode SfxObjectShell::CallXScript( const Reference< XInterface >& _rxScriptCon Any aException; try { - css::uno::Reference<css::uri::XUriReferenceFactory> urifac( - css::uri::UriReferenceFactory::create(comphelper::getProcessComponentContext())); - css::uno::Reference<css::uri::XVndSunStarScriptUrlReference> uri( - urifac->parse(_rScriptURL), css::uno::UNO_QUERY_THROW); - auto const loc = uri->getParameter("location"); - bool bIsDocumentScript = loc == "document"; - if ( bIsDocumentScript && !lcl_isScriptAccessAllowed_nothrow( _rxScriptContext ) ) + if ( !lcl_isScriptAccessAllowed_nothrow( _rxScriptContext ) ) return ERRCODE_IO_ACCESSDENIED; if ( UnTrustedScript(_rScriptURL) ) @@ -1756,6 +1750,11 @@ bool SfxObjectShell_Impl::documentStorageHasMacros() const return ::sfx2::DocumentMacroMode::storageHasMacros( m_xDocStorage ); } +bool SfxObjectShell_Impl::macroCallsSeenWhileLoading() const +{ + return rDocShell.GetMacroCallsSeenWhileLoading(); +} + Reference< XEmbeddedScripts > SfxObjectShell_Impl::getEmbeddedDocumentScripts() const { return Reference< XEmbeddedScripts >( rDocShell.GetModel(), UNO_QUERY ); diff --git a/sfx2/source/doc/objstor.cxx b/sfx2/source/doc/objstor.cxx index 45326e225a8f..82653292a818 100644 --- a/sfx2/source/doc/objstor.cxx +++ b/sfx2/source/doc/objstor.cxx @@ -3579,6 +3579,16 @@ void SfxObjectShell::SetConfigOptionsChecked( bool bChecked ) pImpl->m_bConfigOptionsChecked = bChecked; } +void SfxObjectShell::SetMacroCallsSeenWhileLoading() +{ + pImpl->m_bMacroCallsSeenWhileLoading = true; +} + +bool SfxObjectShell::GetMacroCallsSeenWhileLoading() const +{ + return pImpl->m_bMacroCallsSeenWhileLoading; +} + bool SfxObjectShell::QuerySaveSizeExceededModules_Impl( const uno::Reference< task::XInteractionHandler >& xHandler ) { #if !HAVE_FEATURE_SCRIPTING diff --git a/sfx2/source/doc/objxtor.cxx b/sfx2/source/doc/objxtor.cxx index c60af88c7f75..5e5cb854c775 100644 --- a/sfx2/source/doc/objxtor.cxx +++ b/sfx2/source/doc/objxtor.cxx @@ -235,6 +235,7 @@ SfxObjectShell_Impl::SfxObjectShell_Impl( SfxObjectShell& _rDocShell ) ,m_bSharedXMLFlag( false ) ,m_bAllowShareControlFileClean( true ) ,m_bConfigOptionsChecked( false ) + ,m_bMacroCallsSeenWhileLoading( false ) ,lErr(ERRCODE_NONE) ,nEventId ( SfxEventHintId::NONE ) ,nLoadedFlags ( SfxLoadedFlags::ALL ) diff --git a/sfx2/source/doc/sfxbasemodel.cxx b/sfx2/source/doc/sfxbasemodel.cxx index 3d0dc17836b6..7742d5edbc91 100644 --- a/sfx2/source/doc/sfxbasemodel.cxx +++ b/sfx2/source/doc/sfxbasemodel.cxx @@ -889,8 +889,15 @@ sal_Bool SAL_CALL SfxBaseModel::attachResource( const OUString& pObjectShell->BreakMacroSign_Impl( bBreakMacroSign ); } + bool bMacroEventRead = false; + if ((aArgs.get("MacroEventRead") >>= bMacroEventRead) && bMacroEventRead) + { + pObjectShell->SetMacroCallsSeenWhileLoading(); + } + aArgs.remove( "WinExtent" ); aArgs.remove( "BreakMacroSignature" ); + aArgs.remove( "MacroEventRead" ); aArgs.remove( "Stream" ); aArgs.remove( "InputStream" ); aArgs.remove( "URL" ); diff --git a/sfx2/source/inc/objshimp.hxx b/sfx2/source/inc/objshimp.hxx index d31414b8588f..d52ee83d9a3c 100644 --- a/sfx2/source/inc/objshimp.hxx +++ b/sfx2/source/inc/objshimp.hxx @@ -90,7 +90,8 @@ struct SfxObjectShell_Impl : public ::sfx2::IMacroDocumentAccess bSaveVersionOnClose:1, m_bSharedXMLFlag:1, // whether the document should be edited in shared mode m_bAllowShareControlFileClean:1, // whether the flag should be stored in xml file - m_bConfigOptionsChecked:1; // whether or not the user options are checked after the Options dialog is closed. + m_bConfigOptionsChecked:1, // whether or not the user options are checked after the Options dialog is closed. + m_bMacroCallsSeenWhileLoading:1; // whether or not the user options are checked after the Options dialog is closed. IndexBitSet aBitSet; ErrCode lErr; @@ -138,6 +139,7 @@ struct SfxObjectShell_Impl : public ::sfx2::IMacroDocumentAccess virtual void setCurrentMacroExecMode( sal_uInt16 nMacroMode ) override; virtual OUString getDocumentLocation() const override; virtual bool documentStorageHasMacros() const override; + virtual bool macroCallsSeenWhileLoading() const override; virtual css::uno::Reference< css::document::XEmbeddedScripts > getEmbeddedDocumentScripts() const override; virtual SignatureState getScriptingSignatureState() override; |