[Libreoffice-commits] core.git: framework/source

Samuel Mehrbrodt Samuel.Mehrbrodt at cib.de
Mon Oct 10 10:42:59 UTC 2016


 framework/source/dispatch/closedispatcher.cxx |   28 ++++++++++++++++++--------
 1 file changed, 20 insertions(+), 8 deletions(-)

New commits:
commit ecec5524476448d35dd24c5594c2fcbb1a8b6218
Author: Samuel Mehrbrodt <Samuel.Mehrbrodt at cib.de>
Date:   Mon Sep 19 13:08:23 2016 +0200

    tdf#102274 Closing LibreOffice should not kill active UNO connections
    
    When closing the last window, check whether there are active UNO connections.
    If that's the case, just close the window, don't terminate the application
    so that the connected application keeps working.
    
    This doesn't affect the behavior of "File->Exit LibreOffice". In that case,
    the application still gets terminated and existing connections are closed.
    
    Change-Id: If2d22d51c9b566be8abd51969f35c80896ed4767
    Reviewed-on: https://gerrit.libreoffice.org/29018
    Reviewed-by: Thorsten Behrens <Thorsten.Behrens at CIB.de>
    Tested-by: Thorsten Behrens <Thorsten.Behrens at CIB.de>

diff --git a/framework/source/dispatch/closedispatcher.cxx b/framework/source/dispatch/closedispatcher.cxx
index 991c3e9..eedefcd 100644
--- a/framework/source/dispatch/closedispatcher.cxx
+++ b/framework/source/dispatch/closedispatcher.cxx
@@ -23,6 +23,8 @@
 #include <services.h>
 #include <general.h>
 
+#include <com/sun/star/bridge/BridgeFactory.hpp>
+#include <com/sun/star/bridge/XBridgeFactory2.hpp>
 #include <com/sun/star/frame/Desktop.hpp>
 #include <com/sun/star/frame/XController.hpp>
 #include <com/sun/star/frame/CommandGroup.hpp>
@@ -293,6 +295,12 @@ IMPL_LINK_NOARG(CloseDispatcher, impl_asyncCallback, LinkParamNone*, void)
     css::uno::Reference< css::frame::XFramesSupplier > xDesktop( css::frame::Desktop::create(xContext), css::uno::UNO_QUERY_THROW);
     FrameListAnalyzer aCheck1(xDesktop, xCloseFrame, FrameListAnalyzer::E_HELP | FrameListAnalyzer::E_BACKINGCOMPONENT);
 
+    // Check for existing UNO connections.
+    // NOTE: There is a race between checking this and connections being created/destroyed before
+    //       we close the frame / terminate the app.
+    css::uno::Reference<css::bridge::XBridgeFactory2> bridgeFac( css::bridge::BridgeFactory::create(xContext) );
+    bool bHasActiveConnections = bridgeFac->getExistingBridges().getLength() > 0;
+
     // a) If the current frame (where the close dispatch was requested for) does not have
     //    any parent frame ... it will close this frame only. Such frame isn't part of the
     //    global desktop tree ... and such frames are used as "implementation details" only.
@@ -310,13 +318,15 @@ IMPL_LINK_NOARG(CloseDispatcher, impl_asyncCallback, LinkParamNone*, void)
     else if (aCheck1.m_bReferenceIsHelp)
         bCloseFrame = true;
 
-    // c) If we are already in "backing mode", we have to terminate
-    //    the application, if this special frame is closed.
-    //    It doesn't matter, how many other frames (can be the help or hidden frames only)
-    //    are open then.
-    //    => terminate the application!
-    else if (aCheck1.m_bReferenceIsBacking)
-        bTerminateApp = true;
+    // c) If we are already in "backing mode", we terminate the application, if no active UNO connections are found.
+    //    If there is an active UNO connection, we only close the frame and leave the application alive.
+    //    It doesn't matter, how many other frames (can be the help or hidden frames only) are open then.
+    else if (aCheck1.m_bReferenceIsBacking) {
+        if (bHasActiveConnections)
+            bCloseFrame = true;
+        else
+            bTerminateApp = true;
+    }
 
     // d) Otherwhise we have to: close all views to the same document, close the
     //    document inside our own frame and decide then again, what has to be done!
@@ -352,7 +362,9 @@ IMPL_LINK_NOARG(CloseDispatcher, impl_asyncCallback, LinkParamNone*, void)
             //     application or establish the backing mode now.
             //     And that depends from the dispatched URL ...
             {
-                if (eOperation == E_CLOSE_FRAME)
+                if (bHasActiveConnections)
+                    bCloseFrame = true;
+                else if (eOperation == E_CLOSE_FRAME)
                     bTerminateApp = true;
                 else if( SvtModuleOptions().IsModuleInstalled(SvtModuleOptions::EModule::STARTMODULE) )
                     bEstablishBackingMode = true;


More information about the Libreoffice-commits mailing list