From ff816ce335826937f92b6b30aca5ff75f56b3ec4 Mon Sep 17 00:00:00 2001 From: Tor Lillqvist Date: Mon, 10 Jun 2019 15:41:28 +0300 Subject: Veto process exit while an OLE client is connected Change-Id: Iad9fc1742ae371a8a162edbc16998e9cb6895919 --- extensions/Library_oleautobridge.mk | 1 + extensions/source/ole/unoobjw.cxx | 51 +++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/extensions/Library_oleautobridge.mk b/extensions/Library_oleautobridge.mk index ec59f715c504..6aaf5555e250 100644 --- a/extensions/Library_oleautobridge.mk +++ b/extensions/Library_oleautobridge.mk @@ -35,6 +35,7 @@ $(eval $(call gb_Library_use_libraries,oleautobridge,\ cppuhelper \ cppu \ sal \ + tl \ )) $(eval $(call gb_Library_use_system_win32_libs,oleautobridge,\ diff --git a/extensions/source/ole/unoobjw.cxx b/extensions/source/ole/unoobjw.cxx index fac1dcda5fec..78254a834040 100644 --- a/extensions/source/ole/unoobjw.cxx +++ b/extensions/source/ole/unoobjw.cxx @@ -59,8 +59,12 @@ #include #include #include +#include #include #include +#include +#include +#include #include #include #include @@ -112,6 +116,50 @@ static bool writeBackOutParameter(VARIANTARG* pDest, VARIANT* pSource); static bool writeBackOutParameter2( VARIANTARG* pDest, VARIANT* pSource); static HRESULT mapCannotConvertException(const CannotConvertException &e, unsigned int * puArgErr); +class TerminationVetoer : public WeakImplHelper +{ +public: + int mnCount; + + TerminationVetoer() + : mnCount(0) + { + try + { + Reference< css::frame::XDesktop > xDesktop = + css::frame::Desktop::create( comphelper::getProcessComponentContext() ); + xDesktop->addTerminateListener( this ); + } + catch( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } + } + + // XTerminateListener + void SAL_CALL queryTermination( const EventObject& ) override + { + // Always veto termination while an OLE object is active + if (mnCount > 0) + { + throw css::frame::TerminationVetoException(); + } + } + + void SAL_CALL notifyTermination( const EventObject& ) override + { + // ??? + } + + // XEventListener + void SAL_CALL disposing( const css::lang::EventObject& Source ) override + { + // ??? + } +}; + +static TerminationVetoer aTerminationVetoer; + /* Does not throw any exceptions. Param pInfo can be NULL. */ @@ -130,6 +178,7 @@ InterfaceOleWrapper::InterfaceOleWrapper( Reference const UnoConversionUtilities( xFactory, unoWrapperClass, comWrapperClass), m_defaultValueType( 0) { + aTerminationVetoer.mnCount++; } InterfaceOleWrapper::~InterfaceOleWrapper() @@ -139,6 +188,8 @@ InterfaceOleWrapper::~InterfaceOleWrapper() auto it = UnoObjToWrapperMap.find( reinterpret_cast(m_xOrigin.get())); if(it != UnoObjToWrapperMap.end()) UnoObjToWrapperMap.erase(it); + + aTerminationVetoer.mnCount--; } STDMETHODIMP InterfaceOleWrapper::QueryInterface(REFIID riid, LPVOID FAR * ppv) -- cgit v1.2.3