This is an automated email from the ASF dual-hosted git repository.

ardovm pushed a commit to branch AOO41X
in repository https://gitbox.apache.org/repos/asf/openoffice.git

commit 58b03506c5ac486b1153db5c7612229071716300
Author: Arrigo Marchiori <[email protected]>
AuthorDate: Sun May 4 22:38:55 2025 +0200

    GraphicObject asks for permission before downloading images
    
    (cherry picked from commit 089177b8c4bd09ab47a81e6c3e88637fdb19e3b4)
---
 main/svtools/source/graphic/grfmgr.cxx | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/main/svtools/source/graphic/grfmgr.cxx 
b/main/svtools/source/graphic/grfmgr.cxx
index ea2091cc33..efd4891449 100644
--- a/main/svtools/source/graphic/grfmgr.cxx
+++ b/main/svtools/source/graphic/grfmgr.cxx
@@ -28,7 +28,12 @@
 
 #include <algorithm>
 
+#include <com/sun/star/uno/Reference.hxx>
+#include <com/sun/star/document/XLinkAuthorizer.hpp>
+#include <com/sun/star/frame/XDesktop.hpp>
+#include <com/sun/star/lang/XMultiServiceFactory.hpp>
 #include <tools/vcompat.hxx>
+#include <ucbhelper/contentbroker.hxx>
 #include <unotools/ucbstreamhelper.hxx>
 #include <unotools/localfilehelper.hxx>
 #include <unotools/tempfile.hxx>
@@ -44,6 +49,8 @@
 #include <vcl/pdfextoutdevdata.hxx>
 // <--
 
+using namespace ::com::sun::star;
+
 // -----------
 // - Defines -
 // -----------
@@ -1440,6 +1447,33 @@ GraphicObject GraphicObject::CreateGraphicObjectFromURL( 
const ::rtl::OUString &
                Graphic         aGraphic;
                if ( aURL.Len() )
                {
+                       /* We must obtain authorization from the current 
document, and we
+                          need a ServiceManager to access it. Because 
utl::UcbStreamHelper
+                          relies on the ::ucbhelper::ContentBroker instance, 
we will
+                          use its ServiceManager. */
+                       ::ucbhelper::ContentBroker* pBroker = 
::ucbhelper::ContentBroker::get();
+                       if ( pBroker ) {
+                               uno::Reference< lang::XMultiServiceFactory > 
xFactory = pBroker->getServiceManager();
+                               uno::Any desktop( xFactory->createInstance( 
::rtl::OUString::createFromAscii( "com.sun.star.frame.Desktop" ) ) );
+                               uno::Reference< com::sun::star::frame::XDesktop 
> xDesktop( desktop, uno::UNO_QUERY );
+                               if ( xDesktop.is() ) {
+                                       uno::Reference< 
::com::sun::star::frame::XFrame > xFrame = xDesktop->getCurrentFrame();
+                                       if ( xFrame.is() ) {
+                                               uno::Reference< 
::com::sun::star::frame::XController > xController = xFrame->getController();
+                                               if ( xController.is() ) {
+                                                       uno::Reference< 
::com::sun::star::frame::XModel > xModel = xController->getModel();
+                                                       if ( xModel.is() ) {
+                                                               uno::Reference< 
com::sun::star::document::XLinkAuthorizer > xLinkAuthorizer( xModel, 
uno::UNO_QUERY);
+                                                               if ( 
xLinkAuthorizer.is() ) {
+                                                                       if ( 
!xLinkAuthorizer->authorizeLinks( aURL ) )
+                                                                               
return GraphicObject( aGraphic );
+                                                               }
+                                                       }
+                                               }
+                                       }
+                               }
+                       }
+
                        SvStream*       pStream = 
utl::UcbStreamHelper::CreateStream( aURL, STREAM_READ );
                        if( pStream )
                                GraphicConverter::Import( *pStream, aGraphic );

Reply via email to