summaryrefslogtreecommitdiff
path: root/sfx2
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2019-08-07 17:37:11 +0100
committerMichael Stahl <Michael.Stahl@cib.de>2019-11-20 15:59:53 +0100
commit37381d11906b19e120862d09ca959e23fc6283d7 (patch)
tree0ea81239aff6520b1e24b33790cd8c315f203b5a /sfx2
parentd570791b290c7567a24620e76f9e6fa07d1efa82 (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 Reviewed-on: https://gerrit.libreoffice.org/77387 Tested-by: Jenkins Reviewed-by: Christian Lohmaier <lohmaier+LibreOffice@googlemail.com> (cherry picked from commit 35fe064a67b54b0680b4845477c9b8751edda160) Change-Id: Ic1203d8ec7dfc217aa217135033ae9db2888e19b
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 c62a5ab87d9a..6e01b925d514 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 0c9d1a8f7e42..248cabf92f69 100644
--- a/sfx2/source/doc/objmisc.cxx
+++ b/sfx2/source/doc/objmisc.cxx
@@ -1390,13 +1390,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) )
@@ -1773,6 +1767,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 d65a7e8666bb..9dda3e0c3f72 100644
--- a/sfx2/source/doc/objstor.cxx
+++ b/sfx2/source/doc/objstor.cxx
@@ -3584,6 +3584,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 88270d13f4a2..b3309bae2d8f 100644
--- a/sfx2/source/doc/objxtor.cxx
+++ b/sfx2/source/doc/objxtor.cxx
@@ -230,6 +230,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 72066d250740..33586d12763f 100644
--- a/sfx2/source/doc/sfxbasemodel.cxx
+++ b/sfx2/source/doc/sfxbasemodel.cxx
@@ -876,8 +876,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 67628d5dbdb0..0b403e071d5c 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 2656e9c213ec..3861149da731 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>
@@ -46,6 +48,8 @@
#include <macroloader.hxx>
using namespace css;
+using namespace ::com::sun::star;
+
// --- XNameReplace ---
@@ -167,102 +171,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" );
+ }
}