summaryrefslogtreecommitdiff
path: root/sd
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
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')
-rw-r--r--sd/source/ui/app/sdxfer.cxx3
-rw-r--r--sd/source/ui/dlg/sdtreelb.cxx6
-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
-rw-r--r--sd/source/ui/sidebar/MasterPageContainer.cxx6
-rw-r--r--sd/source/ui/slidesorter/shell/SlideSorterService.cxx5
-rw-r--r--sd/source/ui/view/ViewTabBar.cxx14
8 files changed, 20 insertions, 34 deletions
diff --git a/sd/source/ui/app/sdxfer.cxx b/sd/source/ui/app/sdxfer.cxx
index eb8bef68b8dd..dcd3e6d2517d 100644
--- a/sd/source/ui/app/sdxfer.cxx
+++ b/sd/source/ui/app/sdxfer.cxx
@@ -741,8 +741,7 @@ SdTransferable* SdTransferable::getImplementation( const Reference< XInterface >
{
try
{
- Reference< css::lang::XUnoTunnel > xUnoTunnel( rxData, UNO_QUERY_THROW );
- return reinterpret_cast<SdTransferable*>(sal::static_int_cast<sal_uIntPtr>(xUnoTunnel->getSomething( SdTransferable::getUnoTunnelId()) ) );
+ return comphelper::getFromUnoTunnel<SdTransferable>(rxData);
}
catch( const css::uno::Exception& )
{
diff --git a/sd/source/ui/dlg/sdtreelb.cxx b/sd/source/ui/dlg/sdtreelb.cxx
index 2b8a6142ef0b..8e87e73eb040 100644
--- a/sd/source/ui/dlg/sdtreelb.cxx
+++ b/sd/source/ui/dlg/sdtreelb.cxx
@@ -129,11 +129,7 @@ SdPageObjsTLV::SdPageObjsTransferable* SdPageObjsTLV::SdPageObjsTransferable::ge
{
try
{
- css::uno::Reference< css::lang::XUnoTunnel > xUnoTunnel( rxData, css::uno::UNO_QUERY_THROW );
-
- return reinterpret_cast<SdPageObjsTLV::SdPageObjsTransferable*>(
- sal::static_int_cast<sal_uIntPtr>(
- xUnoTunnel->getSomething( SdPageObjsTLV::SdPageObjsTransferable::getUnoTunnelId()) ) );
+ return comphelper::getFromUnoTunnel<SdPageObjsTLV::SdPageObjsTransferable>(rxData);
}
catch( const css::uno::Exception& )
{
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& )
{
diff --git a/sd/source/ui/sidebar/MasterPageContainer.cxx b/sd/source/ui/sidebar/MasterPageContainer.cxx
index c528e54a70a5..40f680210ca3 100644
--- a/sd/source/ui/sidebar/MasterPageContainer.cxx
+++ b/sd/source/ui/sidebar/MasterPageContainer.cxx
@@ -797,11 +797,9 @@ Reference<frame::XModel> MasterPageContainer::Implementation::GetModel()
// Use its tunnel to get a pointer to its core implementation.
uno::Reference<lang::XUnoTunnel> xUnoTunnel (mxModel, uno::UNO_QUERY);
- if (xUnoTunnel.is())
+ if (auto pSdXImpressDocument = comphelper::getFromUnoTunnel<SdXImpressDocument>(xUnoTunnel))
{
- mpDocument = reinterpret_cast<SdXImpressDocument*>(
- xUnoTunnel->getSomething(
- SdXImpressDocument::getUnoTunnelId()))->GetDoc();
+ mpDocument = pSdXImpressDocument->GetDoc();
}
// Create a default page.
diff --git a/sd/source/ui/slidesorter/shell/SlideSorterService.cxx b/sd/source/ui/slidesorter/shell/SlideSorterService.cxx
index 2691fbcf1778..778346aa5e60 100644
--- a/sd/source/ui/slidesorter/shell/SlideSorterService.cxx
+++ b/sd/source/ui/slidesorter/shell/SlideSorterService.cxx
@@ -27,6 +27,8 @@
#include <view/SlideSorterView.hxx>
#include <view/SlsLayouter.hxx>
#include <DrawController.hxx>
+
+#include <comphelper/servicehelper.hxx>
#include <toolkit/helper/vclunohelper.hxx>
#include <com/sun/star/lang/XUnoTunnel.hpp>
@@ -78,8 +80,7 @@ void SAL_CALL SlideSorterService::initialize (const Sequence<Any>& rArguments)
// Tunnel through the controller to obtain a ViewShellBase.
ViewShellBase* pBase = nullptr;
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)
pBase = pController->GetViewShellBase();
diff --git a/sd/source/ui/view/ViewTabBar.cxx b/sd/source/ui/view/ViewTabBar.cxx
index da624e6094ba..6b16f89ec7ea 100644
--- a/sd/source/ui/view/ViewTabBar.cxx
+++ b/sd/source/ui/view/ViewTabBar.cxx
@@ -70,9 +70,8 @@ ViewTabBar::ViewTabBar (
try
{
Reference<lang::XUnoTunnel> xTunnel (mxController, UNO_QUERY_THROW);
- DrawController* pController = reinterpret_cast<DrawController*>(
- xTunnel->getSomething(DrawController::getUnoTunnelId()));
- mpViewShellBase = pController->GetViewShellBase();
+ if (auto pController = comphelper::getFromUnoTunnel<DrawController>(xTunnel))
+ mpViewShellBase = pController->GetViewShellBase();
}
catch (const RuntimeException&)
{
@@ -150,9 +149,8 @@ vcl::Window* ViewTabBar::GetAnchorWindow(
try
{
Reference<lang::XUnoTunnel> xTunnel (rxController, UNO_QUERY_THROW);
- DrawController* pController = reinterpret_cast<DrawController*>(
- xTunnel->getSomething(DrawController::getUnoTunnelId()));
- pBase = pController->GetViewShellBase();
+ if (auto pController = comphelper::getFromUnoTunnel<DrawController>(xTunnel))
+ pBase = pController->GetViewShellBase();
}
catch (const RuntimeException&)
{
@@ -187,9 +185,7 @@ vcl::Window* ViewTabBar::GetAnchorWindow(
try
{
Reference<lang::XUnoTunnel> xTunnel (xPane, UNO_QUERY_THROW);
- framework::Pane* pPane = reinterpret_cast<framework::Pane*>(
- xTunnel->getSomething(framework::Pane::getUnoTunnelId()));
- if (pPane != nullptr)
+ if (auto pPane = comphelper::getFromUnoTunnel<framework::Pane>(xTunnel))
pWindow = pPane->GetWindow()->GetParent();
}
catch (const RuntimeException&)