Revert "tdf#88985 block app from exiting during macro execution"

This isn't needed anymore with the fixes for tdf#127205.

Reverts commit 68cf256f506d4601a2d2cf3ec2d56713afd491e6.

Change-Id: I1a7944632af8330f68d451d2c293143233039b34
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/88837
Tested-by: Jenkins
Reviewed-by: Jan-Marek Glogowski <glogow@fbihome.de>
diff --git a/framework/inc/services/desktop.hxx b/framework/inc/services/desktop.hxx
index 1f0f791..0cf9cb3 100644
--- a/framework/inc/services/desktop.hxx
+++ b/framework/inc/services/desktop.hxx
@@ -418,18 +418,6 @@ class Desktop final : private cppu::BaseMutex,
          */
        css::uno::Reference< css::frame::XTerminateListener > m_xQuickLauncher;

        /** special terminate listener active when a macro is executing.
          * Because basic runs Application::Yield internally the application may quit
          * while running inside the internal basic event loop. So all the basic
          * infrastructure may be deleted while the call is executing, leading to
          * a variant of crashes. So this special terminate listener will
          * veto the current quit attempt, stop basic execution, which will
          * cause the inner event loop to quit, and on return to the outer normal
          * application event loop then resend the quit attempt.
          * So these implementation must be a special terminate listener too .-(
          */
        css::uno::Reference< css::frame::XTerminateListener > m_xStarBasicQuitGuard;

        /** special terminate listener which loads images asynchronous for current open documents.
          * Because internally it uses blocking system APIs... it can't be guaranteed that
          * running jobs can be cancelled successfully if the corresponding document will be closed...
diff --git a/framework/source/services/desktop.cxx b/framework/source/services/desktop.cxx
index 260ddcb..28f5015 100644
--- a/framework/source/services/desktop.cxx
+++ b/framework/source/services/desktop.cxx
@@ -161,7 +161,6 @@ Desktop::Desktop( const css::uno::Reference< css::uno::XComponentContext >& xCon
        ,   m_xDispatchRecorderSupplier(                                            )
        ,   m_xPipeTerminator       (                                               )
        ,   m_xQuickLauncher        (                                               )
        ,   m_xStarBasicQuitGuard   (                                               )
        ,   m_xSWThreadManager      (                                               )
        ,   m_xSfxTerminator        (                                               )
        ,   m_xTitleNumberGenerator (                                               )
@@ -206,7 +205,6 @@ sal_Bool SAL_CALL Desktop::terminate()

    css::uno::Reference< css::frame::XTerminateListener > xPipeTerminator    = m_xPipeTerminator;
    css::uno::Reference< css::frame::XTerminateListener > xQuickLauncher     = m_xQuickLauncher;
    css::uno::Reference< css::frame::XTerminateListener > xStarBasicQuitGuard = m_xStarBasicQuitGuard;
    css::uno::Reference< css::frame::XTerminateListener > xSWThreadManager   = m_xSWThreadManager;
    css::uno::Reference< css::frame::XTerminateListener > xSfxTerminator     = m_xSfxTerminator;

@@ -257,12 +255,6 @@ sal_Bool SAL_CALL Desktop::terminate()
            lCalledTerminationListener.push_back( xQuickLauncher );
        }

        if ( xStarBasicQuitGuard.is() )
        {
            xStarBasicQuitGuard->queryTermination( aEvent );
            lCalledTerminationListener.push_back( xStarBasicQuitGuard );
        }

        if ( xSWThreadManager.is() )
        {
            xSWThreadManager->queryTermination( aEvent );
@@ -308,9 +300,6 @@ sal_Bool SAL_CALL Desktop::terminate()
        if( bAskQuickStart && xQuickLauncher.is() )
            xQuickLauncher->notifyTermination( aEvent );

        if ( xStarBasicQuitGuard.is() )
            xStarBasicQuitGuard->notifyTermination( aEvent );

        if ( xSWThreadManager.is() )
            xSWThreadManager->notifyTermination( aEvent );

@@ -416,11 +405,6 @@ void SAL_CALL Desktop::addTerminateListener( const css::uno::Reference< css::fra
            m_xQuickLauncher = xListener;
            return;
        }
        if( sImplementationName == "com.sun.star.comp.svx.StarBasicQuitGuard" )
        {
            m_xStarBasicQuitGuard = xListener;
            return;
        }
        if( sImplementationName == "com.sun.star.util.comp.FinalThreadManager" )
        {
            m_xSWThreadManager = xListener;
@@ -466,12 +450,6 @@ void SAL_CALL Desktop::removeTerminateListener( const css::uno::Reference< css::
            return;
        }

        if( sImplementationName == "com.sun.star.comp.svx.StarBasicQuitGuard" )
        {
            m_xStarBasicQuitGuard.clear();
            return;
        }

        if( sImplementationName == "com.sun.star.util.comp.FinalThreadManager" )
        {
            m_xSWThreadManager.clear();
@@ -1105,7 +1083,6 @@ void SAL_CALL Desktop::disposing()

    m_xPipeTerminator.clear();
    m_xQuickLauncher.clear();
    m_xStarBasicQuitGuard.clear();
    m_xSWThreadManager.clear();

    // we need a copy because the disposing might call the removeEventListener method
diff --git a/svx/source/form/fmscriptingenv.cxx b/svx/source/form/fmscriptingenv.cxx
index 14374f1..6edc7046 100644
--- a/svx/source/form/fmscriptingenv.cxx
+++ b/svx/source/form/fmscriptingenv.cxx
@@ -737,109 +737,6 @@ namespace svxform
        m_pScriptExecutor = nullptr;
    }

    namespace {

    // tdf#88985 If LibreOffice tries to exit during the execution of a macro
    // then: detect the effort, stop basic execution, block until the macro
    // returns due to that stop, then restart the quit. This avoids the app
    // exiting and destroying itself until the macro is parked at a safe place
    // to do that.
    class QuitGuard
    {
    private:

        class TerminateListener : public cppu::WeakComponentImplHelper<css::frame::XTerminateListener,
                                                                       css::lang::XServiceInfo>
        {
        private:
            css::uno::Reference<css::frame::XDesktop2> m_xDesktop;
            osl::Mutex maMutex;
            bool mbQuitBlocked;
        public:
            // XTerminateListener
            virtual void SAL_CALL queryTermination(const css::lang::EventObject& /*rEvent*/) override
            {
                mbQuitBlocked = true;
#if HAVE_FEATURE_SCRIPTING
                StarBASIC::Stop();
#endif
                throw css::frame::TerminationVetoException();
            }

            virtual void SAL_CALL notifyTermination(const css::lang::EventObject& /*rEvent*/) override
            {
                mbQuitBlocked = false;
            }

            using cppu::WeakComponentImplHelperBase::disposing;

            virtual void SAL_CALL disposing(const css::lang::EventObject& rEvent) override
            {
                const bool bShutDown = (rEvent.Source == m_xDesktop);
                if (bShutDown && m_xDesktop.is())
                {
                    m_xDesktop->removeTerminateListener(this);
                    m_xDesktop.clear();
                }
            }

            // XServiceInfo
            virtual OUString SAL_CALL getImplementationName() override
            {
                return "com.sun.star.comp.svx.StarBasicQuitGuard";
            }

            virtual sal_Bool SAL_CALL supportsService(OUString const & ServiceName) override
            {
                return cppu::supportsService(this, ServiceName);
            }

            virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() override
            {
                return { "com.sun.star.svx.StarBasicQuitGuard" };
            }

        public:
            TerminateListener()
                : cppu::WeakComponentImplHelper<css::frame::XTerminateListener,
                                                css::lang::XServiceInfo>(maMutex)
                , mbQuitBlocked(false)
            {
            }

            void start()
            {
                css::uno::Reference<css::uno::XComponentContext> xContext(comphelper::getProcessComponentContext());
                m_xDesktop = css::frame::Desktop::create(xContext);
                m_xDesktop->addTerminateListener(this);
            }

            void stop()
            {
                if (!m_xDesktop.is())
                    return;
                m_xDesktop->removeTerminateListener(this);
                if (mbQuitBlocked)
                    m_xDesktop->terminate();
            }
        };

        rtl::Reference<TerminateListener> mxListener;
    public:
        QuitGuard()
            : mxListener(new TerminateListener)
        {
            mxListener->start();
        }

        ~QuitGuard()
        {
            mxListener->stop();
        }
    };

    }

    IMPL_LINK( FormScriptListener, OnAsyncScriptEvent, void*, p, void )
    {
        ScriptEvent* _pEvent = static_cast<ScriptEvent*>(p);
@@ -851,10 +748,7 @@ namespace svxform
            ::osl::ClearableMutexGuard aGuard( m_aMutex );

            if ( !impl_isDisposed_nothrow() )
            {
                QuitGuard aQuitGuard;
                impl_doFireScriptEvent_nothrow( aGuard, *_pEvent, nullptr );
            }
        }

        delete _pEvent;