summaryrefslogtreecommitdiff
path: root/sw/source
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2019-08-07 17:37:11 +0100
committerCaolán McNamara <caolanm@redhat.com>2019-08-13 13:26:15 +0200
commitb3edf85e0fe6ca03dc26e1bf531be82193bc9627 (patch)
tree62887e38b2f0b06ca8e74fffd126560b5b0c8049 /sw/source
parentc78dd0a726b32d922a0d75a26a51d4c30612368c (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 'sw/source')
-rw-r--r--sw/source/filter/html/htmlform.cxx16
-rw-r--r--sw/source/filter/html/htmlgrin.cxx19
-rw-r--r--sw/source/filter/html/swhtml.cxx1
-rw-r--r--sw/source/filter/html/swhtml.hxx3
-rw-r--r--sw/source/filter/ww8/ww8par.cxx13
-rw-r--r--sw/source/filter/ww8/ww8par.hxx2
-rw-r--r--sw/source/filter/ww8/ww8par5.cxx2
7 files changed, 52 insertions, 4 deletions
diff --git a/sw/source/filter/html/htmlform.cxx b/sw/source/filter/html/htmlform.cxx
index 78c8d820df34..74ae9f78b1a9 100644
--- a/sw/source/filter/html/htmlform.cxx
+++ b/sw/source/filter/html/htmlform.cxx
@@ -18,6 +18,7 @@
*/
#include <hintids.hxx>
+#include <comphelper/documentinfo.hxx>
#include <comphelper/string.hxx>
#include <vcl/svapp.hxx>
#include <vcl/wrkwin.hxx>
@@ -733,7 +734,7 @@ void SwHTMLParser::SetControlSize( const uno::Reference< drawing::XShape >& rSha
rShape->setSize( aSz );
}
-static void lcl_html_setEvents(
+static bool lcl_html_setEvents(
const uno::Reference< script::XEventAttacherManager > & rEvtMn,
sal_uInt32 nPos, const SvxMacroTableDtor& rMacroTable,
const std::vector<OUString>& rUnoMacroTable,
@@ -762,7 +763,7 @@ static void lcl_html_setEvents(
}
if( 0==nEvents )
- return;
+ return false;
Sequence<script::ScriptEventDescriptor> aDescs( nEvents );
script::ScriptEventDescriptor* pDescs = aDescs.getArray();
@@ -820,6 +821,7 @@ static void lcl_html_setEvents(
}
}
rEvtMn->registerScriptEvents( nPos, aDescs );
+ return true;
}
static void lcl_html_getEvents( const OUString& rOption, const OUString& rValue,
@@ -1188,10 +1190,12 @@ uno::Reference< drawing::XShape > SwHTMLParser::InsertControl(
// To prevent previous JavaScript-Events from being called, these events will only be set retroactively
if( !rMacroTable.empty() || !rUnoMacroTable.empty() )
{
- lcl_html_setEvents( m_pFormImpl->GetControlEventManager(),
+ bool bHasEvents = lcl_html_setEvents( m_pFormImpl->GetControlEventManager(),
rFormComps->getCount() - 1,
rMacroTable, rUnoMacroTable, rUnoMacroParamTable,
GetScriptTypeString(m_pFormImpl->GetHeaderAttrs()) );
+ if (bHasEvents)
+ NotifyMacroEventRead();
}
if( bSetFCompPropSet )
@@ -1353,10 +1357,14 @@ void SwHTMLParser::NewForm( bool bAppend )
Any aAny( &xForm, cppu::UnoType<XForm>::get());
rForms->insertByIndex( rForms->getCount(), aAny );
if( !aMacroTable.empty() )
- lcl_html_setEvents( m_pFormImpl->GetFormEventManager(),
+ {
+ bool bHasEvents = lcl_html_setEvents( m_pFormImpl->GetFormEventManager(),
rForms->getCount() - 1,
aMacroTable, aUnoMacroTable, aUnoMacroParamTable,
rDfltScriptType );
+ if (bHasEvents)
+ NotifyMacroEventRead();
+ }
}
void SwHTMLParser::EndForm( bool bAppend )
diff --git a/sw/source/filter/html/htmlgrin.cxx b/sw/source/filter/html/htmlgrin.cxx
index 9ca5a22dcc00..85991d6e0888 100644
--- a/sw/source/filter/html/htmlgrin.cxx
+++ b/sw/source/filter/html/htmlgrin.cxx
@@ -20,6 +20,7 @@
#include <memory>
#include <hintids.hxx>
#include <comphelper/string.hxx>
+#include <comphelper/documentinfo.hxx>
#include <vcl/svapp.hxx>
#include <vcl/wrkwin.hxx>
#include <svx/svxids.hrc>
@@ -871,7 +872,10 @@ IMAGE_SETEVENT:
}
if( !aMacroItem.GetMacroTable().empty() )
+ {
+ NotifyMacroEventRead();
pFlyFormat->SetFormatAttr( aMacroItem );
+ }
// tdf#87083 If the graphic has not been loaded yet, then load it now.
// Otherwise it may be loaded during the first paint of the object and it
@@ -1304,7 +1308,10 @@ ANCHOR_SETEVENT:
aINetFormat.SetName( aName );
if( !aMacroTable.empty() )
+ {
+ NotifyMacroEventRead();
aINetFormat.SetMacroTable( &aMacroTable );
+ }
// set the default attribute
InsertAttr(&m_xAttrTab->pINetFormat, aINetFormat, xCntxt.get());
@@ -1516,4 +1523,16 @@ void SwHTMLParser::StripTrailingPara()
}
}
+void SwHTMLParser::NotifyMacroEventRead()
+{
+ if (m_bNotifyMacroEventRead)
+ return;
+ SwDocShell *pDocSh = m_xDoc->GetDocShell();
+ if (!pDocSh)
+ return;
+ uno::Reference<frame::XModel> const xModel(pDocSh->GetBaseModel());
+ comphelper::DocumentInfo::notifyMacroEventRead(xModel);
+ m_bNotifyMacroEventRead = true;
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/filter/html/swhtml.cxx b/sw/source/filter/html/swhtml.cxx
index 0a9f87b2f5bb..546040c6dcb1 100644
--- a/sw/source/filter/html/swhtml.cxx
+++ b/sw/source/filter/html/swhtml.cxx
@@ -311,6 +311,7 @@ SwHTMLParser::SwHTMLParser( SwDoc* pD, SwPaM& rCursor, SvStream& rIn,
m_bRemoveHidden( false ),
m_bBodySeen( false ),
m_bReadingHeaderOrFooter( false ),
+ m_bNotifyMacroEventRead( false ),
m_isInTableStructure(false),
m_nTableDepth( 0 ),
m_pTempViewFrame(nullptr)
diff --git a/sw/source/filter/html/swhtml.hxx b/sw/source/filter/html/swhtml.hxx
index 6aa702995615..b931042a3fe7 100644
--- a/sw/source/filter/html/swhtml.hxx
+++ b/sw/source/filter/html/swhtml.hxx
@@ -452,6 +452,7 @@ class SwHTMLParser : public SfxHTMLParser, public SwClient
bool m_bBodySeen : 1;
bool m_bReadingHeaderOrFooter : 1;
+ bool m_bNotifyMacroEventRead : 1;
bool m_isInTableStructure;
sal_Int32 m_nTableDepth;
@@ -923,6 +924,8 @@ public:
bool IsReqIF() const;
+ void NotifyMacroEventRead();
+
/// Strips query and fragment from a URL path if base URL is a file:// one.
static OUString StripQueryFromPath(const OUString& rBase, const OUString& rPath);
};
diff --git a/sw/source/filter/ww8/ww8par.cxx b/sw/source/filter/ww8/ww8par.cxx
index 11712b8520d6..c1ac48f408fe 100644
--- a/sw/source/filter/ww8/ww8par.cxx
+++ b/sw/source/filter/ww8/ww8par.cxx
@@ -42,6 +42,7 @@
#include <unotools/tempfile.hxx>
#include <comphelper/docpasswordrequest.hxx>
+#include <comphelper/documentinfo.hxx>
#include <comphelper/propertysequence.hxx>
#include <editeng/outlobj.hxx>
@@ -4308,6 +4309,7 @@ SwWW8ImplReader::SwWW8ImplReader(sal_uInt8 nVersionPara, SotStorage* pStorage,
, m_aTOXEndCps()
, m_aCurrAttrCP(-1)
, m_bOnLoadingMain(false)
+ , m_bNotifyMacroEventRead(false)
{
m_pStrm->SetEndian( SvStreamEndian::LITTLE );
m_aApos.push_back(false);
@@ -4698,6 +4700,8 @@ void SwWW8ImplReader::StoreMacroCmds()
try
{
+ NotifyMacroEventRead();
+
uno::Reference < io::XStream > xStream =
xRoot->openStreamElement( SL::aMSMacroCmds, embed::ElementModes::READWRITE );
std::unique_ptr<SvStream> xOutStream(::utl::UcbStreamHelper::CreateStream(xStream));
@@ -6555,4 +6559,13 @@ std::unique_ptr<SfxItemSet> SwWW8ImplReader::SetCurrentItemSet(std::unique_ptr<S
return xRet;
}
+void SwWW8ImplReader::NotifyMacroEventRead()
+{
+ if (m_bNotifyMacroEventRead)
+ return;
+ uno::Reference<frame::XModel> const xModel(m_rDoc.GetDocShell()->GetBaseModel());
+ comphelper::DocumentInfo::notifyMacroEventRead(xModel);
+ m_bNotifyMacroEventRead = true;
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/filter/ww8/ww8par.hxx b/sw/source/filter/ww8/ww8par.hxx
index 097b330c0c74..f043d44b9a08 100644
--- a/sw/source/filter/ww8/ww8par.hxx
+++ b/sw/source/filter/ww8/ww8par.hxx
@@ -1376,6 +1376,7 @@ private:
cp_vector m_aEndParaPos;
WW8_CP m_aCurrAttrCP;
bool m_bOnLoadingMain:1;
+ bool m_bNotifyMacroEventRead:1;
const SprmReadInfo& GetSprmReadInfo(sal_uInt16 nId) const;
@@ -1911,6 +1912,7 @@ public: // really private, but can only be done public
void PostProcessAttrs();
void ReadEmbeddedData(SvStream& rStrm, SwDocShell const * pDocShell, struct HyperLinksTable& hlStr);
+ void NotifyMacroEventRead();
};
bool CanUseRemoteLink(const OUString &rGrfName);
diff --git a/sw/source/filter/ww8/ww8par5.cxx b/sw/source/filter/ww8/ww8par5.cxx
index 8b276eab3138..2d708ff1128e 100644
--- a/sw/source/filter/ww8/ww8par5.cxx
+++ b/sw/source/filter/ww8/ww8par5.cxx
@@ -2272,6 +2272,8 @@ eF_ResT SwWW8ImplReader::Read_F_Macro( WW8FieldDesc*, OUString& rStr)
if( aName.isEmpty() )
return eF_ResT::TAGIGN; // makes no sense without Macro-Name
+ NotifyMacroEventRead();
+
//try converting macro symbol according to macro name
bool bApplyWingdings = ConvertMacroSymbol( aName, aVText );
aName = "StarOffice.Standard.Modul1." + aName;