summaryrefslogtreecommitdiff
path: root/sfx2
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2019-08-07 17:37:11 +0100
committerChristian Lohmaier <lohmaier+LibreOffice@googlemail.com>2019-08-28 22:25:40 +0200
commit35fe064a67b54b0680b4845477c9b8751edda160 (patch)
tree32f344c90c4cd7b8cc4b9fdd5135ddea88617eee /sfx2
parent4a4e0cb67eab422dffda6f3339031db5b62be77a (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/77387 Tested-by: Jenkins Reviewed-by: Christian Lohmaier <lohmaier+LibreOffice@googlemail.com>
Diffstat (limited to 'sfx2')
-rw-r--r--sfx2/source/doc/docmacromode.cxx2
-rw-r--r--sfx2/source/doc/objmisc.cxx13
-rw-r--r--sfx2/source/doc/objstor.cxx10
-rw-r--r--sfx2/source/doc/objxtor.cxx1
-rw-r--r--sfx2/source/doc/sfxbasemodel.cxx7
-rw-r--r--sfx2/source/inc/objshimp.hxx4
-rw-r--r--sfx2/source/notify/eventsupplier.cxx187
7 files changed, 137 insertions, 87 deletions
diff --git a/sfx2/source/doc/docmacromode.cxx b/sfx2/source/doc/docmacromode.cxx
index 4872fc90496b..570fc27ac43f 100644
--- a/sfx2/source/doc/docmacromode.cxx
+++ b/sfx2/source/doc/docmacromode.cxx
@@ -397,7 +397,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 dd01995bf18e..0aad46e02258 100644
--- a/sfx2/source/doc/objmisc.cxx
+++ b/sfx2/source/doc/objmisc.cxx
@@ -1384,13 +1384,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) )
@@ -1758,6 +1752,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 bc6eb96a94bf..c458028b9671 100644
--- a/sfx2/source/doc/objstor.cxx
+++ b/sfx2/source/doc/objstor.cxx
@@ -3566,6 +3566,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 8c0e1643a0fc..d3e83c67b6a2 100644
--- a/sfx2/source/doc/objxtor.cxx
+++ b/sfx2/source/doc/objxtor.cxx
@@ -231,6 +231,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 )
,pReloadTimer ( nullptr)
diff --git a/sfx2/source/doc/sfxbasemodel.cxx b/sfx2/source/doc/sfxbasemodel.cxx
index 27ba812a2449..41bd3494bdb6 100644
--- a/sfx2/source/doc/sfxbasemodel.cxx
+++ b/sfx2/source/doc/sfxbasemodel.cxx
@@ -879,8 +879,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 006b938664ea..848775ef2f47 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;
@@ -139,6 +140,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;
diff --git a/sfx2/source/notify/eventsupplier.cxx b/sfx2/source/notify/eventsupplier.cxx
index 8ce1d7b9bfa7..6740c8c0eb1e 100644
--- a/sfx2/source/notify/eventsupplier.cxx
+++ b/sfx2/source/notify/eventsupplier.cxx
@@ -19,11 +19,13 @@
#include <com/sun/star/beans/PropertyValue.hpp>
+#include <com/sun/star/document/XEmbeddedScripts.hpp>
+#include <com/sun/star/document/XScriptInvocationContext.hpp>
#include <com/sun/star/util/URL.hpp>
-
#include <com/sun/star/frame/Desktop.hpp>
#include <com/sun/star/util/URLTransformer.hpp>
#include <com/sun/star/util/XURLTransformer.hpp>
+#include <com/sun/star/uno/XInterface.hpp>
#include <tools/urlobj.hxx>
#include <tools/diagnose_ex.h>
#include <svl/macitem.hxx>
@@ -47,6 +49,8 @@
#include <macroloader.hxx>
using namespace css;
+using namespace ::com::sun::star;
+
// --- XNameReplace ---
@@ -168,102 +172,129 @@ sal_Bool SAL_CALL SfxEvents_Impl::hasElements()
return false;
}
+namespace
+{
+ bool lcl_isScriptAccessAllowed_nothrow(const uno::Reference<uno::XInterface>& rxScriptContext)
+ {
+ try
+ {
+ uno::Reference<document::XEmbeddedScripts> xScripts(rxScriptContext, uno::UNO_QUERY);
+ if (!xScripts.is())
+ {
+ uno::Reference<document::XScriptInvocationContext> xContext(rxScriptContext, uno::UNO_QUERY_THROW);
+ xScripts.set(xContext->getScriptContainer(), uno::UNO_SET_THROW);
+ }
+
+ return xScripts->getAllowMacroExecution();
+ }
+ catch( const uno::Exception& )
+ {
+ DBG_UNHANDLED_EXCEPTION("sfx.doc");
+ }
+ return false;
+ }
+}
+
void SfxEvents_Impl::Execute( uno::Any const & aEventData, const document::DocumentEvent& aTrigger, SfxObjectShell* pDoc )
{
uno::Sequence < beans::PropertyValue > aProperties;
- if ( aEventData >>= aProperties )
- {
- OUString aType;
- OUString aScript;
- OUString aLibrary;
- OUString aMacroName;
+ if ( !(aEventData >>= aProperties) )
+ return;
- sal_Int32 nCount = aProperties.getLength();
+ OUString aType;
+ OUString aScript;
+ OUString aLibrary;
+ OUString aMacroName;
- if ( !nCount )
- return;
+ sal_Int32 nCount = aProperties.getLength();
- sal_Int32 nIndex = 0;
- while ( nIndex < nCount )
- {
- if ( aProperties[ nIndex ].Name == PROP_EVENT_TYPE )
- aProperties[ nIndex ].Value >>= aType;
- else if ( aProperties[ nIndex ].Name == PROP_SCRIPT )
- aProperties[ nIndex ].Value >>= aScript;
- else if ( aProperties[ nIndex ].Name == PROP_LIBRARY )
- aProperties[ nIndex ].Value >>= aLibrary;
- else if ( aProperties[ nIndex ].Name == PROP_MACRO_NAME )
- aProperties[ nIndex ].Value >>= aMacroName;
- else {
- OSL_FAIL("Unknown property value!");
- }
- nIndex += 1;
- }
+ if ( !nCount )
+ return;
- if (aType == STAR_BASIC && !aScript.isEmpty())
- {
- uno::Any aAny;
- SfxMacroLoader::loadMacro( aScript, aAny, pDoc );
+ sal_Int32 nIndex = 0;
+ while ( nIndex < nCount )
+ {
+ if ( aProperties[ nIndex ].Name == PROP_EVENT_TYPE )
+ aProperties[ nIndex ].Value >>= aType;
+ else if ( aProperties[ nIndex ].Name == PROP_SCRIPT )
+ aProperties[ nIndex ].Value >>= aScript;
+ else if ( aProperties[ nIndex ].Name == PROP_LIBRARY )
+ aProperties[ nIndex ].Value >>= aLibrary;
+ else if ( aProperties[ nIndex ].Name == PROP_MACRO_NAME )
+ aProperties[ nIndex ].Value >>= aMacroName;
+ else {
+ OSL_FAIL("Unknown property value!");
}
- else if (aType == "Service" ||
- aType == "Script")
- {
- bool bAllowed = false;
- util::URL aURL;
- if (!aScript.isEmpty())
- {
- uno::Reference < util::XURLTransformer > xTrans( util::URLTransformer::create( ::comphelper::getProcessComponentContext() ) );
+ nIndex += 1;
+ }
- aURL.Complete = aScript;
- xTrans->parseStrict( aURL );
+ if (aType.isEmpty())
+ {
+ // Empty type means no active binding for the event. Just ignore do nothing.
+ return;
+ }
- bAllowed = !SfxObjectShell::UnTrustedScript(aURL.Complete);
- }
+ if (aScript.isEmpty())
+ return;
- if (bAllowed)
- {
- SfxViewFrame* pView = pDoc ?
- SfxViewFrame::GetFirst( pDoc ) :
- SfxViewFrame::Current();
+ if (!pDoc)
+ pDoc = SfxObjectShell::Current();
- uno::Reference
- < frame::XDispatchProvider > xProv;
+ if (pDoc && !lcl_isScriptAccessAllowed_nothrow(pDoc->GetModel()))
+ return;
- if ( pView != nullptr )
- {
- xProv = uno::Reference
- < frame::XDispatchProvider > (
- pView->GetFrame().GetFrameInterface(), uno::UNO_QUERY );
- }
- else
- {
- xProv.set( frame::Desktop::create( ::comphelper::getProcessComponentContext() ),
- uno::UNO_QUERY );
- }
+ if (aType == STAR_BASIC)
+ {
+ uno::Any aAny;
+ SfxMacroLoader::loadMacro( aScript, aAny, pDoc );
+ }
+ else if (aType == "Service" || aType == "Script")
+ {
+ util::URL aURL;
+ uno::Reference < util::XURLTransformer > xTrans( util::URLTransformer::create( ::comphelper::getProcessComponentContext() ) );
- uno::Reference < frame::XDispatch > xDisp;
- if ( xProv.is() )
- xDisp = xProv->queryDispatch( aURL, OUString(), 0 );
+ aURL.Complete = aScript;
+ xTrans->parseStrict( aURL );
- if ( xDisp.is() )
- {
+ bool bAllowed = !SfxObjectShell::UnTrustedScript(aURL.Complete);
- beans::PropertyValue aEventParam;
- aEventParam.Value <<= aTrigger;
- uno::Sequence< beans::PropertyValue > aDispatchArgs( &aEventParam, 1 );
- xDisp->dispatch( aURL, aDispatchArgs );
- }
- }
- }
- else if ( aType.isEmpty() )
- {
- // Empty type means no active binding for the event. Just ignore do nothing.
- }
- else
+ if (bAllowed)
{
- SAL_WARN( "sfx.notify", "notifyEvent(): Unsupported event type" );
+ SfxViewFrame* pView = SfxViewFrame::GetFirst(pDoc);
+
+ uno::Reference
+ < frame::XDispatchProvider > xProv;
+
+ if ( pView != nullptr )
+ {
+ xProv = uno::Reference
+ < frame::XDispatchProvider > (
+ pView->GetFrame().GetFrameInterface(), uno::UNO_QUERY );
+ }
+ else
+ {
+ xProv.set( frame::Desktop::create( ::comphelper::getProcessComponentContext() ),
+ uno::UNO_QUERY );
+ }
+
+ uno::Reference < frame::XDispatch > xDisp;
+ if ( xProv.is() )
+ xDisp = xProv->queryDispatch( aURL, OUString(), 0 );
+
+ if ( xDisp.is() )
+ {
+
+ beans::PropertyValue aEventParam;
+ aEventParam.Value <<= aTrigger;
+ uno::Sequence< beans::PropertyValue > aDispatchArgs( &aEventParam, 1 );
+ xDisp->dispatch( aURL, aDispatchArgs );
+ }
}
}
+ else
+ {
+ SAL_WARN( "sfx.notify", "notifyEvent(): Unsupported event type" );
+ }
}