framework/source/dispatch/dispatchprovider.cxx      |    5 +-
 include/framework/dispatchhelper.hxx                |   10 -----
 offapi/UnoApi_offapi.mk                             |    1 
 offapi/com/sun/star/util/XCacheInfo.idl             |   40 ++++++++++++++++++++
 sdext/source/presenter/PresenterProtocolHandler.hxx |    8 ++--
 5 files changed, 48 insertions(+), 16 deletions(-)

New commits:
commit b3f2ae52e381f7d5fa466dc9df7d04d3d13ca4b9
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Mon May 30 11:08:12 2022 +0200
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Mon May 30 12:08:03 2022 +0200

    framework: fix crash on Writer startup when using 
--enable-ext-wiki-publisher
    
    As reported by Julien, once the mediawiki extension is installed, the
    xHandler in framework::DispatchProvider::implts_searchProtocolHandler()
    points to an UNO component implemented in Java, and we crash in
    dynamic_cast<>(), at least on Linux with gcc 7.5 and libstdc++.
    
    This dynamic_cast<>() call was added in commit
    c0fa456436947a5c167c652d19a884064b43c03d (tdf#149261 sdext: fix crash on
    starting the presenter console for the 2nd time, 2022-05-26), to allow
    the presenter console to opt out from protocol handler caching. It was
    expected that the proxy object created for a Java UNO component would
    simply return nullptr when we try to dynamic_cast<>() it down to a C++
    interface.
    
    Fix the problem by moving the interface to an UNO one: this side-steps
    the dynamic_cast<>() crash at the price of introducing an UNO interface,
    which is not meant to be part of the public UNO API (but at least it's
    not published).
    
    It may still make sense to improve the bridges/ code at some stage to
    not crash in dynamic_cast<>() on generated Java proxy objects.
    
    Change-Id: Iaac44515339e0dc15dddc3be45ef7dee7331e47a
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135114
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>
    Reviewed-by: Caolán McNamara <caol...@redhat.com>
    Tested-by: Caolán McNamara <caol...@redhat.com>

diff --git a/framework/source/dispatch/dispatchprovider.cxx 
b/framework/source/dispatch/dispatchprovider.cxx
index c16a0085a0a5..1c214ddaa48f 100644
--- a/framework/source/dispatch/dispatchprovider.cxx
+++ b/framework/source/dispatch/dispatchprovider.cxx
@@ -32,6 +32,7 @@
 #include <com/sun/star/uno/Exception.hpp>
 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
 #include <com/sun/star/lang/XInitialization.hpp>
+#include <com/sun/star/util/XCacheInfo.hpp>
 
 #include <rtl/ustring.hxx>
 #include <vcl/svapp.hxx>
@@ -454,8 +455,8 @@ css::uno::Reference< css::frame::XDispatch > 
DispatchProvider::implts_searchProt
                         css::uno::UNO_QUERY);
 
                     // Check if the handler explicitly requested to avoid 
caching.
-                    auto pCacheInfo = 
dynamic_cast<framework::CacheInfo*>(xHandler.get());
-                    if (!pCacheInfo || pCacheInfo->IsCachingAllowed())
+                    css::uno::Reference<css::util::XCacheInfo> 
xCacheInfo(xHandler, css::uno::UNO_QUERY);
+                    if (!xCacheInfo.is() || xCacheInfo->isCachingAllowed())
                     {
                         m_aProtocolHandlers.emplace(aHandler.m_sUNOName, 
xHandler);
                     }
diff --git a/include/framework/dispatchhelper.hxx 
b/include/framework/dispatchhelper.hxx
index 1595e2a3cea2..7c89a2d79aac 100644
--- a/include/framework/dispatchhelper.hxx
+++ b/include/framework/dispatchhelper.hxx
@@ -104,16 +104,6 @@ public:
     // XEventListener
     virtual void SAL_CALL disposing(const css::lang::EventObject& aEvent) 
override;
 };
-
-/// Interface that allows a protocol handler implementation to opt out from 
framework caching.
-class SAL_NO_VTABLE SAL_DLLPUBLIC_RTTI CacheInfo
-{
-public:
-    virtual bool IsCachingAllowed() const = 0;
-
-protected:
-    ~CacheInfo() noexcept = default;
-};
 }
 
 #endif
diff --git a/offapi/UnoApi_offapi.mk b/offapi/UnoApi_offapi.mk
index a9b92639a667..5f0ae2e84d56 100644
--- a/offapi/UnoApi_offapi.mk
+++ b/offapi/UnoApi_offapi.mk
@@ -4157,6 +4157,7 @@ $(eval $(call 
gb_UnoApi_add_idlfiles,offapi,com/sun/star/util,\
        XAtomServer \
        XBinaryDataContainer \
        XBroadcaster \
+       XCacheInfo \
        XCancellable \
        XChainable \
        XChangesBatch \
diff --git a/offapi/com/sun/star/util/XCacheInfo.idl 
b/offapi/com/sun/star/util/XCacheInfo.idl
new file mode 100644
index 000000000000..299d49690246
--- /dev/null
+++ b/offapi/com/sun/star/util/XCacheInfo.idl
@@ -0,0 +1,40 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ *   Licensed to the Apache Software Foundation (ASF) under one or more
+ *   contributor license agreements. See the NOTICE file distributed
+ *   with this work for additional information regarding copyright
+ *   ownership. The ASF licenses this file to you under the Apache
+ *   License, Version 2.0 (the "License"); you may not use this file
+ *   except in compliance with the License. You may obtain a copy of
+ *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+#ifndef __com_sun_star_util_XCacheInfo_idl__
+#define __com_sun_star_util_XCacheInfo_idl__
+
+#include <com/sun/star/uno/XInterface.idl>
+
+module com {  module sun {  module star {  module util {
+
+/** Interface that allows an implementation to opt out from caching.
+
+    @since LibreOffice 7.4
+ */
+interface XCacheInfo: com::sun::star::uno::XInterface
+{
+    boolean isCachingAllowed();
+
+};
+
+}; }; }; };
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sdext/source/presenter/PresenterProtocolHandler.hxx 
b/sdext/source/presenter/PresenterProtocolHandler.hxx
index eaced08d9e6a..217fb2658abe 100644
--- a/sdext/source/presenter/PresenterProtocolHandler.hxx
+++ b/sdext/source/presenter/PresenterProtocolHandler.hxx
@@ -26,14 +26,15 @@
 #include <com/sun/star/frame/XDispatch.hpp>
 #include <com/sun/star/lang/XInitialization.hpp>
 #include <com/sun/star/lang/XServiceInfo.hpp>
+#include <com/sun/star/util/XCacheInfo.hpp>
 #include <rtl/ref.hxx>
-#include <framework/dispatchhelper.hxx>
 
 namespace sdext::presenter {
 
 typedef ::cppu::WeakComponentImplHelper <
     css::lang::XInitialization,
     css::lang::XServiceInfo,
+    css::util::XCacheInfo,
     css::frame::XDispatchProvider
 > PresenterProtocolHandlerInterfaceBase;
 
@@ -41,7 +42,6 @@ class PresenterController;
 
 class PresenterProtocolHandler
     : protected ::cppu::BaseMutex,
-      public framework::CacheInfo,
       public PresenterProtocolHandlerInterfaceBase
 {
 public:
@@ -73,8 +73,8 @@ public:
         queryDispatches(
             const css::uno::Sequence< css::frame::DispatchDescriptor>& 
rDescriptors) override;
 
-    /// See framework::CacheInfo::IsCachingAllowed().
-    bool IsCachingAllowed() const override { return false; }
+    /// See XCacheInfo::IsCachingAllowed().
+    sal_Bool SAL_CALL isCachingAllowed() override { return false; }
 
 private:
     class Dispatch;

Reply via email to