summaryrefslogtreecommitdiff
path: root/sfx2/source
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 /sfx2/source
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 'sfx2/source')
-rw-r--r--sfx2/source/control/bindings.cxx11
-rw-r--r--sfx2/source/control/sfxstatuslistener.cxx10
-rw-r--r--sfx2/source/control/statcach.cxx10
-rw-r--r--sfx2/source/doc/objxtor.cxx5
-rw-r--r--sfx2/source/statbar/stbitem.cxx10
-rw-r--r--sfx2/source/toolbox/tbxitem.cxx10
6 files changed, 12 insertions, 44 deletions
diff --git a/sfx2/source/control/bindings.cxx b/sfx2/source/control/bindings.cxx
index 9feef5f541f0..1fd72c1dbdfb 100644
--- a/sfx2/source/control/bindings.cxx
+++ b/sfx2/source/control/bindings.cxx
@@ -21,6 +21,7 @@
#include <iomanip>
+#include <comphelper/servicehelper.hxx>
#include <sal/log.hxx>
#include <svl/itempool.hxx>
#include <svl/itemiter.hxx>
@@ -1528,15 +1529,7 @@ SfxItemState SfxBindings::QueryState( sal_uInt16 nSlot, std::unique_ptr<SfxPoolI
if ( xDisp.is() )
{
- css::uno::Reference< css::lang::XUnoTunnel > xTunnel( xDisp, css::uno::UNO_QUERY );
- SfxOfficeDispatch* pDisp = nullptr;
- if ( xTunnel.is() )
- {
- sal_Int64 nImplementation = xTunnel->getSomething(SfxOfficeDispatch::getUnoTunnelId());
- pDisp = reinterpret_cast< SfxOfficeDispatch* >( sal::static_int_cast< sal_IntPtr >( nImplementation ));
- }
-
- if ( !pDisp )
+ if (!comphelper::getFromUnoTunnel<SfxOfficeDispatch>(xDisp))
{
bool bDeleteCache = false;
if ( !pCache )
diff --git a/sfx2/source/control/sfxstatuslistener.cxx b/sfx2/source/control/sfxstatuslistener.cxx
index bae714699bc2..09b52ee01954 100644
--- a/sfx2/source/control/sfxstatuslistener.cxx
+++ b/sfx2/source/control/sfxstatuslistener.cxx
@@ -25,6 +25,7 @@
#include <svl/visitem.hxx>
#include <cppuhelper/weak.hxx>
#include <comphelper/processfactory.hxx>
+#include <comphelper/servicehelper.hxx>
#include <vcl/svapp.hxx>
#include <com/sun/star/util/URLTransformer.hpp>
#include <com/sun/star/util/XURLTransformer.hpp>
@@ -143,14 +144,7 @@ void SAL_CALL SfxStatusListener::statusChanged( const FeatureStateEvent& rEvent)
if ( m_xDispatch.is() )
{
Reference< XUnoTunnel > xTunnel( m_xDispatch, UNO_QUERY );
- SfxOfficeDispatch* pDisp = nullptr;
- if ( xTunnel.is() )
- {
- sal_Int64 nImplementation = xTunnel->getSomething(SfxOfficeDispatch::getUnoTunnelId());
- pDisp = reinterpret_cast< SfxOfficeDispatch* >(sal::static_int_cast< sal_IntPtr >( nImplementation ));
- }
-
- if ( pDisp )
+ if (auto pDisp = comphelper::getFromUnoTunnel<SfxOfficeDispatch>(xTunnel))
pViewFrame = pDisp->GetDispatcher_Impl()->GetFrame();
}
diff --git a/sfx2/source/control/statcach.cxx b/sfx2/source/control/statcach.cxx
index e24650cc0d35..23814e9548db 100644
--- a/sfx2/source/control/statcach.cxx
+++ b/sfx2/source/control/statcach.cxx
@@ -26,6 +26,7 @@
#include <com/sun/star/frame/DispatchResultState.hpp>
#include <com/sun/star/frame/XFrame.hpp>
#include <com/sun/star/beans/PropertyValue.hpp>
+#include <comphelper/servicehelper.hxx>
#include <cppuhelper/weak.hxx>
#include <svl/eitem.hxx>
#include <svl/intitem.hxx>
@@ -263,14 +264,7 @@ const SfxSlotServer* SfxStateCache::GetSlotServer( SfxDispatcher &rDispat , cons
{
// test the dispatch object if it is just a wrapper for a SfxDispatcher
css::uno::Reference< css::lang::XUnoTunnel > xTunnel( xDisp, css::uno::UNO_QUERY );
- SfxOfficeDispatch* pDisp = nullptr;
- if ( xTunnel.is() )
- {
- sal_Int64 nImplementation = xTunnel->getSomething(SfxOfficeDispatch::getUnoTunnelId());
- pDisp = reinterpret_cast< SfxOfficeDispatch* >(sal::static_int_cast< sal_IntPtr >( nImplementation ));
- }
-
- if ( pDisp )
+ if (auto pDisp = comphelper::getFromUnoTunnel<SfxOfficeDispatch>(xTunnel))
{
// The intercepting object is an SFX component
// If this dispatch object does not use the wanted dispatcher or the AppDispatcher, it's treated like any other UNO component
diff --git a/sfx2/source/doc/objxtor.cxx b/sfx2/source/doc/objxtor.cxx
index 0532c63e35ab..7418f9136d53 100644
--- a/sfx2/source/doc/objxtor.cxx
+++ b/sfx2/source/doc/objxtor.cxx
@@ -46,6 +46,7 @@
#include <sfx2/sfxmodelfactory.hxx>
#include <comphelper/processfactory.hxx>
+#include <comphelper/servicehelper.hxx>
#include <com/sun/star/document/XStorageBasedDocument.hpp>
#include <com/sun/star/script/DocumentDialogLibraryContainer.hpp>
@@ -1033,9 +1034,7 @@ SfxObjectShell* SfxObjectShell::GetShellFromComponent(const Reference<uno::XInte
{
Reference<lang::XUnoTunnel> xTunnel(xComp, UNO_QUERY_THROW);
Sequence <sal_Int8> aSeq( SvGlobalName( SFX_GLOBAL_CLASSID ).GetByteSequence() );
- sal_Int64 nHandle = xTunnel->getSomething( aSeq );
- if (nHandle)
- return reinterpret_cast<SfxObjectShell*>(sal::static_int_cast<sal_IntPtr>(nHandle));
+ return comphelper::getSomething_cast<SfxObjectShell>(xTunnel->getSomething(aSeq));
}
catch (const Exception&)
{
diff --git a/sfx2/source/statbar/stbitem.cxx b/sfx2/source/statbar/stbitem.cxx
index d9deef15bda5..c48fc970efa7 100644
--- a/sfx2/source/statbar/stbitem.cxx
+++ b/sfx2/source/statbar/stbitem.cxx
@@ -42,6 +42,7 @@
#include <sfx2/objsh.hxx>
#include <comphelper/processfactory.hxx>
+#include <comphelper/servicehelper.hxx>
#include <svl/eitem.hxx>
#include <svl/intitem.hxx>
#include <toolkit/helper/vclunohelper.hxx>
@@ -184,14 +185,7 @@ void SAL_CALL SfxStatusBarControl::statusChanged( const frame::FeatureStateEvent
if ( xDisp.is() )
{
uno::Reference< lang::XUnoTunnel > xTunnel( xDisp, uno::UNO_QUERY );
- SfxOfficeDispatch* pDisp = nullptr;
- if ( xTunnel.is() )
- {
- sal_Int64 nImplementation = xTunnel->getSomething(SfxOfficeDispatch::getUnoTunnelId());
- pDisp = reinterpret_cast< SfxOfficeDispatch* >(sal::static_int_cast< sal_IntPtr >( nImplementation ));
- }
-
- if ( pDisp )
+ if (auto pDisp = comphelper::getFromUnoTunnel<SfxOfficeDispatch>(xTunnel))
pViewFrame = pDisp->GetDispatcher_Impl()->GetFrame();
}
}
diff --git a/sfx2/source/toolbox/tbxitem.cxx b/sfx2/source/toolbox/tbxitem.cxx
index 8b383e21593b..dfd767062004 100644
--- a/sfx2/source/toolbox/tbxitem.cxx
+++ b/sfx2/source/toolbox/tbxitem.cxx
@@ -43,6 +43,7 @@
#include <vcl/toolbox.hxx>
#include <comphelper/processfactory.hxx>
+#include <comphelper/servicehelper.hxx>
#include <toolkit/helper/vclunohelper.hxx>
#include <vcl/InterimItemWindow.hxx>
@@ -294,14 +295,7 @@ void SAL_CALL SfxToolBoxControl::statusChanged( const FeatureStateEvent& rEvent
if ( xDisp.is() )
{
Reference< XUnoTunnel > xTunnel( xDisp, UNO_QUERY );
- SfxOfficeDispatch* pDisp = nullptr;
- if ( xTunnel.is() )
- {
- sal_Int64 nImplementation = xTunnel->getSomething(SfxOfficeDispatch::getUnoTunnelId());
- pDisp = reinterpret_cast< SfxOfficeDispatch* >( sal::static_int_cast< sal_IntPtr >( nImplementation ));
- }
-
- if ( pDisp )
+ if (auto pDisp = comphelper::getFromUnoTunnel<SfxOfficeDispatch>(xTunnel))
pViewFrame = pDisp->GetDispatcher_Impl()->GetFrame();
}
}