diff options
author | Caolán McNamara <caolanm@redhat.com> | 2019-08-07 17:37:11 +0100 |
---|---|---|
committer | Christian Lohmaier <lohmaier+LibreOffice@googlemail.com> | 2019-08-28 22:25:40 +0200 |
commit | 35fe064a67b54b0680b4845477c9b8751edda160 (patch) | |
tree | 32f344c90c4cd7b8cc4b9fdd5135ddea88617eee /dbaccess | |
parent | 4a4e0cb67eab422dffda6f3339031db5b62be77a (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 'dbaccess')
-rw-r--r-- | dbaccess/source/core/dataaccess/ModelImpl.cxx | 7 | ||||
-rw-r--r-- | dbaccess/source/core/dataaccess/databasedocument.cxx | 25 | ||||
-rw-r--r-- | dbaccess/source/core/inc/ModelImpl.hxx | 2 |
3 files changed, 26 insertions, 8 deletions
diff --git a/dbaccess/source/core/dataaccess/ModelImpl.cxx b/dbaccess/source/core/dataaccess/ModelImpl.cxx index 4f360bfc1ee9..7c175ab5eeb5 100644 --- a/dbaccess/source/core/dataaccess/ModelImpl.cxx +++ b/dbaccess/source/core/dataaccess/ModelImpl.cxx @@ -374,6 +374,7 @@ ODatabaseModelImpl::ODatabaseModelImpl( const Reference< XComponentContext >& _r ,m_bSuppressVersionColumns(true) ,m_bModified(false) ,m_bDocumentReadOnly(false) + ,m_bMacroCallsSeenWhileLoading(false) ,m_pSharedConnectionManager(nullptr) ,m_nControllerLockCount(0) { @@ -407,6 +408,7 @@ ODatabaseModelImpl::ODatabaseModelImpl( ,m_bSuppressVersionColumns(true) ,m_bModified(false) ,m_bDocumentReadOnly(false) + ,m_bMacroCallsSeenWhileLoading(false) ,m_pSharedConnectionManager(nullptr) ,m_nControllerLockCount(0) { @@ -1271,6 +1273,11 @@ bool ODatabaseModelImpl::documentStorageHasMacros() const return ( *m_aEmbeddedMacros != eNoMacros ); } +bool ODatabaseModelImpl::macroCallsSeenWhileLoading() const +{ + return m_bMacroCallsSeenWhileLoading; +} + Reference< XEmbeddedScripts > ODatabaseModelImpl::getEmbeddedDocumentScripts() const { return Reference< XEmbeddedScripts >( getModel_noCreate(), UNO_QUERY ); diff --git a/dbaccess/source/core/dataaccess/databasedocument.cxx b/dbaccess/source/core/dataaccess/databasedocument.cxx index e84af4dfe653..cf133627ef37 100644 --- a/dbaccess/source/core/dataaccess/databasedocument.cxx +++ b/dbaccess/source/core/dataaccess/databasedocument.cxx @@ -747,15 +747,24 @@ sal_Bool SAL_CALL ODatabaseDocument::attachResource( const OUString& _rURL, cons bool ODatabaseDocument::impl_attachResource( const OUString& i_rLogicalDocumentURL, const Sequence< PropertyValue >& i_rMediaDescriptor, DocumentGuard& _rDocGuard ) { - if ( ( i_rLogicalDocumentURL == getURL() ) - && ( i_rMediaDescriptor.getLength() == 1 ) - && ( i_rMediaDescriptor[0].Name == "BreakMacroSignature" ) - ) + if (i_rLogicalDocumentURL == getURL()) { - // this is a BAD hack of the Basic importer code ... there should be a dedicated API for this, - // not this bad mis-using of existing interfaces - return false; - // (we do not support macro signatures, so we can ignore this call) + ::comphelper::NamedValueCollection aArgs(i_rMediaDescriptor); + + // this misuse of attachresource is a hack of the Basic importer code + // repurposing existing interfaces for uses it probably wasn't intended + // for + + // we do not support macro signatures, so we can ignore that request + aArgs.remove("BreakMacroSignature"); + + bool bMacroEventRead = false; + if ((aArgs.get( "MacroEventRead" ) >>= bMacroEventRead) && bMacroEventRead) + m_pImpl->m_bMacroCallsSeenWhileLoading = true; + aArgs.remove( "MacroEventRead" ); + + if (aArgs.empty()) + return false; } // if no URL has been provided, the caller was lazy enough to not call our getURL - which is not allowed anymore, diff --git a/dbaccess/source/core/inc/ModelImpl.hxx b/dbaccess/source/core/inc/ModelImpl.hxx index ab4276c4e5cf..bc97f4be969f 100644 --- a/dbaccess/source/core/inc/ModelImpl.hxx +++ b/dbaccess/source/core/inc/ModelImpl.hxx @@ -206,6 +206,7 @@ public: bool m_bSuppressVersionColumns : 1; bool m_bModified : 1; bool m_bDocumentReadOnly : 1; + bool m_bMacroCallsSeenWhileLoading : 1; css::uno::Reference< css::beans::XPropertyBag > m_xSettings; css::uno::Sequence< OUString > m_aTableFilter; @@ -434,6 +435,7 @@ public: virtual void setCurrentMacroExecMode( sal_uInt16 ) 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; virtual bool hasTrustedScriptingSignature( bool bAllowUIToAddAuthor ) override; |