From a1140054b4031fe64e073bb4a5c443018c8532c2 Mon Sep 17 00:00:00 2001 From: Caolán McNamara Date: Wed, 14 Aug 2019 15:24:05 +0100 Subject: revert part of '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 i.e. commit b3edf85e0fe6ca03dc26e1bf531be82193bc9627 Author: Caolán McNamara Date: Wed Aug 7 17:37:11 2019 +0100 because then extensions that add a entry to menus results in menu entries that cannot run in the start center where there is no document. If allowed when there is no document, it would still result in the odd behaviour that such menu entries would not work in a document which contained macros or macro-calls if permission was denied to run them Add a similar check instead to SfxEvents_Impl::Execute Change-Id: I8084ab2dc66bb95e2562a3dba188c721d44a5676 Reviewed-on: https://gerrit.libreoffice.org/77465 Tested-by: Jenkins Reviewed-by: Caolán McNamara Tested-by: Caolán McNamara --- sfx2/source/notify/eventsupplier.cxx | 39 ++++++++++++++++++++++++++++++++---- 1 file changed, 35 insertions(+), 4 deletions(-) (limited to 'sfx2') diff --git a/sfx2/source/notify/eventsupplier.cxx b/sfx2/source/notify/eventsupplier.cxx index 356d28c1430a..fffe1fe39de0 100644 --- a/sfx2/source/notify/eventsupplier.cxx +++ b/sfx2/source/notify/eventsupplier.cxx @@ -19,11 +19,13 @@ #include +#include +#include #include - #include #include #include +#include #include #include #include @@ -48,6 +50,8 @@ #include using namespace css; +using namespace ::com::sun::star; + // --- XNameReplace --- @@ -151,6 +155,29 @@ sal_Bool SAL_CALL SfxEvents_Impl::hasElements() return maEventNames.hasElements(); } +namespace +{ + bool lcl_isScriptAccessAllowed_nothrow(const uno::Reference& rxScriptContext) + { + try + { + uno::Reference xScripts(rxScriptContext, uno::UNO_QUERY); + if (!xScripts.is()) + { + uno::Reference 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; @@ -189,6 +216,12 @@ void SfxEvents_Impl::Execute( uno::Any const & aEventData, const document::Docum if (aScript.isEmpty()) return; + if (!pDoc) + pDoc = SfxObjectShell::Current(); + + if (pDoc && !lcl_isScriptAccessAllowed_nothrow(pDoc->GetModel())) + return; + if (aType == STAR_BASIC) { uno::Any aAny; @@ -206,9 +239,7 @@ void SfxEvents_Impl::Execute( uno::Any const & aEventData, const document::Docum if (bAllowed) { - SfxViewFrame* pView = pDoc ? - SfxViewFrame::GetFirst( pDoc ) : - SfxViewFrame::Current(); + SfxViewFrame* pView = SfxViewFrame::GetFirst(pDoc); uno::Reference < frame::XDispatchProvider > xProv; -- cgit