summaryrefslogtreecommitdiff
path: root/sd/source/ui/framework
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2021-09-13 11:29:37 +0300
committerMike Kaganski <mike.kaganski@collabora.com>2021-09-15 06:08:27 +0200
commit96bd77de5ad7b7a13f7e48e0f95c05ef49255aa0 (patch)
tree4c79c57712124a8589c9e6579b6ec7fec9200c3b /sd/source/ui/framework
parent3f65724ec5fc92d5a0078a99932358ef7091435c (diff)
Use <comphelper/servicehelper.hxx> implementing XUnoTunnel part 5
- Revise uses of getSomething to use getFromUnoTunnel Where that is impossible, use getSomething_cast to unify casting, and minimize number of places doing low-level transformations. The change keeps the existing tunnel references that last for the duration of the pointers' life, because sometimes destroying such reference may destroy the pointed object, and result in use after free. Change-Id: I291c33223582c34cd2c763aa8aacf0ae899ca4c0 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/122101 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'sd/source/ui/framework')
-rw-r--r--sd/source/ui/framework/factories/BasicPaneFactory.cxx8
-rw-r--r--sd/source/ui/framework/factories/BasicViewFactory.cxx4
-rw-r--r--sd/source/ui/framework/tools/FrameworkHelper.cxx8
3 files changed, 8 insertions, 12 deletions
diff --git a/sd/source/ui/framework/factories/BasicPaneFactory.cxx b/sd/source/ui/framework/factories/BasicPaneFactory.cxx
index b746090a6534..e45b35c9015c 100644
--- a/sd/source/ui/framework/factories/BasicPaneFactory.cxx
+++ b/sd/source/ui/framework/factories/BasicPaneFactory.cxx
@@ -26,6 +26,7 @@
#include "FrameWindowPane.hxx"
#include "FullScreenPane.hxx"
+#include <comphelper/servicehelper.hxx>
#include <framework/FrameworkHelper.hxx>
#include <PaneShells.hxx>
#include <ViewShellBase.hxx>
@@ -133,11 +134,8 @@ void SAL_CALL BasicPaneFactory::initialize (const Sequence<Any>& aArguments)
try
{
Reference<lang::XUnoTunnel> xTunnel (xController, UNO_QUERY_THROW);
- DrawController* pController
- = reinterpret_cast<DrawController*>(
- (sal::static_int_cast<sal_uIntPtr>(
- xTunnel->getSomething(DrawController::getUnoTunnelId()))));
- mpViewShellBase = pController->GetViewShellBase();
+ if (auto pController = comphelper::getFromUnoTunnel<DrawController>(xTunnel))
+ mpViewShellBase = pController->GetViewShellBase();
}
catch(RuntimeException&)
{}
diff --git a/sd/source/ui/framework/factories/BasicViewFactory.cxx b/sd/source/ui/framework/factories/BasicViewFactory.cxx
index 581260d347c4..18f9ff123dc4 100644
--- a/sd/source/ui/framework/factories/BasicViewFactory.cxx
+++ b/sd/source/ui/framework/factories/BasicViewFactory.cxx
@@ -36,6 +36,7 @@
#include <FrameView.hxx>
#include <Window.hxx>
+#include <comphelper/servicehelper.hxx>
#include <sfx2/viewfrm.hxx>
#include <vcl/wrkwin.hxx>
#include <toolkit/helper/vclunohelper.hxx>
@@ -239,8 +240,7 @@ void SAL_CALL BasicViewFactory::initialize (const Sequence<Any>& aArguments)
// Tunnel through the controller to obtain a ViewShellBase.
Reference<lang::XUnoTunnel> xTunnel (xController, UNO_QUERY_THROW);
- ::sd::DrawController* pController = reinterpret_cast<sd::DrawController*>(
- xTunnel->getSomething(sd::DrawController::getUnoTunnelId()));
+ ::sd::DrawController* pController = comphelper::getFromUnoTunnel<sd::DrawController>(xTunnel);
if (pController != nullptr)
mpBase = pController->GetViewShellBase();
diff --git a/sd/source/ui/framework/tools/FrameworkHelper.cxx b/sd/source/ui/framework/tools/FrameworkHelper.cxx
index 61245ecf1da6..c1ec2f0d38fd 100644
--- a/sd/source/ui/framework/tools/FrameworkHelper.cxx
+++ b/sd/source/ui/framework/tools/FrameworkHelper.cxx
@@ -30,6 +30,7 @@
#include <app.hrc>
#include <com/sun/star/drawing/framework/XControllerManager.hpp>
#include <com/sun/star/frame/XController.hpp>
+#include <comphelper/servicehelper.hxx>
#include <cppuhelper/compbase.hxx>
#include <svl/lstner.hxx>
#include <rtl/ustrbuf.hxx>
@@ -201,14 +202,11 @@ namespace
::std::shared_ptr< ViewShell > lcl_getViewShell( const Reference< XResource >& i_rViewShellWrapper )
{
::std::shared_ptr< ViewShell > pViewShell;
- if ( !i_rViewShellWrapper.is() )
- return pViewShell;
-
try
{
Reference<lang::XUnoTunnel> xViewTunnel( i_rViewShellWrapper, UNO_QUERY_THROW );
- pViewShell = reinterpret_cast< ViewShellWrapper* >(
- xViewTunnel->getSomething( ViewShellWrapper::getUnoTunnelId() ) )->GetViewShell();
+ if (auto pWrapper = comphelper::getFromUnoTunnel<ViewShellWrapper>(xViewTunnel))
+ pViewShell = pWrapper->GetViewShell();
}
catch( const Exception& )
{