20#include <com/sun/star/beans/PropertyValue.hpp>
22#include <com/sun/star/util/URL.hpp>
23#include <com/sun/star/frame/Desktop.hpp>
24#include <com/sun/star/uno/Sequence.hxx>
25#include <com/sun/star/util/URLTransformer.hpp>
26#include <com/sun/star/util/XURLTransformer.hpp>
37#include <officecfg/Office/Common.hxx>
46#include <unicode/errorcode.h>
47#include <unicode/regex.h>
48#include <unicode/unistr.h>
59 std::unique_lock aGuard(
maMutex );
64 throw container::NoSuchElementException();
68 throw lang::IllegalArgumentException();
85 if ( ( aNormalizedDescriptor.
size() == 1 )
88 && (
sType.isEmpty() )
95 OSL_ENSURE(
false,
"legacy event assignment format detected" );
96 aNormalizedDescriptor.
clear();
99 if ( !aNormalizedDescriptor.
empty() )
114 std::unique_lock aGuard(
maMutex );
122 throw container::NoSuchElementException();
134 std::unique_lock aGuard(
maMutex );
153 std::unique_lock aGuard(
maMutex );
160 std::optional<css::uno::Sequence<OUString>> allowedEvents(
161 officecfg::Office::Common::Security::Scripting::AllowedDocumentEventURLs::get());
166 icu::ErrorCode status;
167 const uint32_t rMatcherFlags = UREGEX_CASE_INSENSITIVE;
168 icu::UnicodeString usInput(aScriptURL.getStr());
169 const css::uno::Sequence<OUString>& rAllowedEvents = *allowedEvents;
170 for (
auto const& allowedEvent : rAllowedEvents)
172 icu::UnicodeString usRegex(allowedEvent.getStr());
173 icu::RegexMatcher rmatch1(usRegex, usInput, rMatcherFlags, status);
174 if (aScriptURL.startsWith(allowedEvent) || rmatch1.matches(status))
193 for (
const auto& rProp : std::as_const(
aProperties) )
196 rProp.Value >>= aType;
198 rProp.Value >>= aScript;
200 rProp.Value >>= aLibrary;
202 rProp.Value >>= aMacroName;
204 OSL_FAIL(
"Unknown property value!");
214 if (aScript.isEmpty())
231 else if (aType ==
"Service" || aType ==
"Script")
234 uno::Reference < util::XURLTransformer > xTrans( util::URLTransformer::create( ::comphelper::getProcessComponentContext() ) );
236 aURL.Complete = aScript;
237 xTrans->parseStrict(
aURL );
246 < frame::XDispatchProvider > xProv;
248 if ( pView !=
nullptr )
250 xProv = uno::Reference
251 < frame::XDispatchProvider > (
256 xProv = frame::Desktop::create( ::comphelper::getProcessComponentContext() );
259 uno::Reference < frame::XDispatch > xDisp;
261 xDisp = xProv->queryDispatch(
aURL, OUString(), 0 );
265 beans::PropertyValue aEventParam;
266 aEventParam.Value <<= aTrigger;
267 uno::Sequence< beans::PropertyValue > aDispatchArgs( &aEventParam, 1 );
268 xDisp->dispatch(
aURL, aDispatchArgs );
274 SAL_WARN(
"sfx.notify",
"notifyEvent(): Unsupported event type" );
283 std::unique_lock aGuard(
maMutex );
291 css::uno::Sequence < css::beans::PropertyValue > aEventData =
maEventData[
nIndex ];
301 std::unique_lock aGuard(
maMutex );
312 uno::Reference< document::XDocumentEventBroadcaster >
const & xBroadcaster )
337 std::unique_ptr<SvxMacro> pMacro;
338 uno::Sequence < beans::PropertyValue >
aProperties;
352 for (
const auto& rProp : std::as_const(
aProperties) )
355 rProp.Value >>= aType;
357 rProp.Value >>= aScriptURL;
359 rProp.Value >>= aLibrary;
361 rProp.Value >>= aMacroName;
363 OSL_FAIL(
"Unknown property value!");
371 else if (aType ==
"Script" && !aScriptURL.isEmpty())
376 SAL_WARN(
"sfx.notify",
"ConvertToMacro: Unknown macro type" );
379 if ( !aMacroName.isEmpty() )
381 if ( aLibrary ==
"application" )
388 pMacro.reset(
new SvxMacro( aScriptURL, aType ));
396 const ::comphelper::NamedValueCollection aEventDescriptor( rEvent );
411 OUString aType = i_eventDescriptor.getOrDefault(
PROP_EVENT_TYPE, OUString() );
412 OUString aScript = i_eventDescriptor.getOrDefault(
PROP_SCRIPT, OUString() );
413 OUString aLibrary = i_eventDescriptor.getOrDefault(
PROP_LIBRARY, OUString() );
414 OUString aMacroName = i_eventDescriptor.getOrDefault(
PROP_MACRO_NAME, OUString() );
416 if ( !aType.isEmpty() )
418 if ( !aScript.isEmpty() )
424 if ( !aScript.isEmpty() )
426 if ( aMacroName.isEmpty() || aLibrary.isEmpty() )
428 sal_Int32 nThirdSlashPos = aScript.indexOf(
'/', 8 );
429 sal_Int32 nArgsPos = aScript.indexOf(
'(' );
430 if ( ( nThirdSlashPos != -1 ) && ( nArgsPos == -1 || nThirdSlashPos < nArgsPos ) )
433 if (pDoc && aBasMgrName ==
".")
439 aMacroName = aScript.copy( nThirdSlashPos+1, nArgsPos - nThirdSlashPos - 1 );
443 SAL_WARN(
"sfx.notify",
"ConvertToMacro: Unknown macro url format" );
447 else if ( !aMacroName.isEmpty() )
449 aScript =
"macro://";
450 if ( aLibrary !=
SfxGetpApp()->
GetName() && aLibrary !=
"StarDesktop" && aLibrary !=
"application" )
452 aScript +=
"/" + aMacroName +
"()";
458 if (aLibrary !=
"document")
461 aLibrary =
"document";
463 aLibrary =
"application";
PropertiesInfo aProperties
SfxApplication * SfxGetpApp()
static OUString decode(std::u16string_view rText, DecodeMechanism eMechanism, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8)
static std::unique_ptr< SvxMacro > ConvertToMacro(const css::uno::Any &rElement, SfxObjectShell *pDoc)
css::uno::Sequence< OUString > maEventNames
virtual ~SfxEvents_Impl() override
css::uno::Reference< css::document::XDocumentEventBroadcaster > mxBroadcaster
virtual css::uno::Any SAL_CALL getByName(const OUString &aName) override
virtual void SAL_CALL replaceByName(const OUString &aName, const css::uno::Any &aElement) override
virtual sal_Bool SAL_CALL hasElements() override
SfxEvents_Impl(SfxObjectShell *pShell, css::uno::Reference< css::document::XDocumentEventBroadcaster > const &xBroadcaster)
virtual css::uno::Sequence< OUString > SAL_CALL getElementNames() override
virtual css::uno::Type SAL_CALL getElementType() override
virtual void SAL_CALL documentEventOccured(const css::document::DocumentEvent &aEvent) override
static void NormalizeMacro(const css::uno::Any &rIn, css::uno::Any &rOut, SfxObjectShell *pDoc)
std::vector< css::uno::Sequence< css::beans::PropertyValue > > maEventData
virtual sal_Bool SAL_CALL hasByName(const OUString &aName) override
virtual void SAL_CALL disposing(const css::lang::EventObject &Source) override
SfxObjectShell * mpObjShell
static bool isScriptURLAllowed(const OUString &aScriptURL)
Check if script URL whitelist exists, and if so, if current script url is part of it.
static void Execute(css::uno::Sequence< css::beans::PropertyValue > const &aEventData, const css::document::DocumentEvent &aTrigger, SfxObjectShell *pDoc)
const css::uno::Reference< css::frame::XFrame > & GetFrameInterface() const
static ErrCode loadMacro(const OUString &aURL, css::uno::Any &rRetval, SfxObjectShell *pDoc)
virtual css::uno::Sequence< OUString > GetEventNames()
static bool UnTrustedScript(const OUString &rScriptURL)
static bool isScriptAccessAllowed(const css::uno::Reference< css::uno::XInterface > &rScriptContext)
css::uno::Reference< css::frame::XModel3 > GetModel() const
OUString GetTitle(sal_uInt16 nMaxLen=0) const
static SAL_WARN_UNUSED_RESULT SfxObjectShell * Current()
virtual void SetModified(bool bModified=true)
const OUString & GetName() const
Returns the name of the Shell object.
static SAL_WARN_UNUSED_RESULT SfxViewFrame * GetFirst(const SfxObjectShell *pDoc=nullptr, bool bOnlyVisible=true)
SfxFrame & GetFrame() const
bool has(const OUString &_rValueName) const
const css::uno::Any & get(const OUString &_rValueName) const
static bool canExtractFrom(css::uno::Any const &i_value)
bool put(const OUString &_rValueName, const VALUE_TYPE &_rValue)
css::uno::Sequence< css::beans::PropertyValue > getPropertyValues() const
virtual OUString GetName() const override
constexpr OUStringLiteral PROP_MACRO_NAME
constexpr OUStringLiteral PROP_SCRIPT
constexpr OUStringLiteral PROP_EVENT_TYPE
constexpr OUStringLiteral PROP_LIBRARY
#define SAL_WARN(area, stream)
constexpr OUStringLiteral SVX_MACRO_LANGUAGE_JAVASCRIPT
sal_Int32 findValue(const css::uno::Sequence< T1 > &_rList, const T2 &_rValue)
#define SFX_TITLE_APINAME