From 40c94cff178bd4bef4dc5ce38cc9eb67fe2eb780 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szymon=20K=C5=82os?= Date: Tue, 19 Dec 2023 19:24:19 +0100 Subject: [PATCH] lok: send error on access denied in image import 2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit followup for commit 64624d225c71229acce4f889d4863d7c29c52658 lok: send error on access denied in image import It shows an error in LOK when we try to insert image from remote host blocked by HostFilter Previously it was showing error in paste case, now do the same also on image insertion. For now disable HandleGraphicFilterError in sd, as it crashes, is synchronous and cannot be easily fixed - dialog sits inside module not linked to sfx2, needs some rework. Change-Id: I3c15ff5621add97ef9d60d4f4c1305dae2909158 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/161001 Tested-by: Jenkins CollaboraOffice Tested-by: Caolán McNamara Reviewed-by: Caolán McNamara Reviewed-on: https://gerrit.libreoffice.org/c/core/+/161774 Tested-by: Jenkins Reviewed-by: Szymon Kłos --- include/sfx2/lokhelper.hxx | 2 +- sc/source/filter/html/htmlpars.cxx | 2 +- sc/source/ui/drawfunc/fuins1.cxx | 11 +++++++++++ sd/source/ui/func/fuinsert.cxx | 14 +++++++++++++- sfx2/source/view/lokhelper.cxx | 4 ++-- sw/source/filter/html/htmlgrin.cxx | 2 +- sw/source/uibase/uiview/view2.cxx | 10 ++++++++++ 7 files changed, 39 insertions(+), 6 deletions(-) diff --git a/include/sfx2/lokhelper.hxx b/include/sfx2/lokhelper.hxx index dc9558a31f0f..8ca9ce80da08 100644 --- a/include/sfx2/lokhelper.hxx +++ b/include/sfx2/lokhelper.hxx @@ -227,7 +227,7 @@ public: static VclPtr getInPlaceDocWindow(SfxViewShell* pViewShell); /// Sends Network Access error to LOK - static void sendNetworkAccessError(); + static void sendNetworkAccessError(std::string_view rAction); static void notifyLog(const std::ostringstream& stream); diff --git a/sc/source/filter/html/htmlpars.cxx b/sc/source/filter/html/htmlpars.cxx index 10d31fc84cd4..43ff3cca2de5 100644 --- a/sc/source/filter/html/htmlpars.cxx +++ b/sc/source/filter/html/htmlpars.cxx @@ -1325,7 +1325,7 @@ void ScHTMLLayoutParser::Image( HtmlImportInfo* pInfo ) { INetURLObject aURL(pImage->aURL); if (HostFilter::isForbidden(aURL.GetHost())) - SfxLokHelper::sendNetworkAccessError(); + SfxLokHelper::sendNetworkAccessError("paste"); } sal_uInt16 nFormat; diff --git a/sc/source/ui/drawfunc/fuins1.cxx b/sc/source/ui/drawfunc/fuins1.cxx index 72886789b448..9b51a62c5b2a 100644 --- a/sc/source/ui/drawfunc/fuins1.cxx +++ b/sc/source/ui/drawfunc/fuins1.cxx @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -48,6 +49,9 @@ #include #include +#include +#include + #include #include #include @@ -279,6 +283,13 @@ FuInsertGraphic::FuInsertGraphic( ScTabViewShell& rViewSh, if ( pReqArgs->GetItemState( FN_PARAM_1, true, &pItem ) == SfxItemState::SET ) bAsLink = static_cast(pItem)->GetValue(); + if (comphelper::LibreOfficeKit::isActive()) + { + INetURLObject aURL(aFileName); + if (INetProtocol::File != aURL.GetProtocol() && HostFilter::isForbidden(aURL.GetHost())) + SfxLokHelper::sendNetworkAccessError("insert"); + } + Graphic aGraphic; ErrCode nError = GraphicFilter::LoadGraphic( aFileName, aFilterName, aGraphic, &GraphicFilter::GetGraphicFilter() ); if ( nError == ERRCODE_NONE ) diff --git a/sd/source/ui/func/fuinsert.cxx b/sd/source/ui/func/fuinsert.cxx index 31b286c822e3..e8409c815b25 100644 --- a/sd/source/ui/func/fuinsert.cxx +++ b/sd/source/ui/func/fuinsert.cxx @@ -36,6 +36,7 @@ #include #include +#include #include #include #include @@ -60,6 +61,9 @@ #include #include +#include +#include + #include #include #include @@ -129,6 +133,13 @@ void FuInsertGraphic::DoExecute( SfxRequest& rReq ) if ( pArgs->GetItemState( FN_PARAM_1, true, &pItem ) == SfxItemState::SET ) bAsLink = static_cast(pItem)->GetValue(); + if (comphelper::LibreOfficeKit::isActive()) + { + INetURLObject aURL(aFileName); + if (INetProtocol::File != aURL.GetProtocol() && HostFilter::isForbidden(aURL.GetHost())) + SfxLokHelper::sendNetworkAccessError("insert"); + } + nError = GraphicFilter::LoadGraphic( aFileName, aFilterName, aGraphic, &GraphicFilter::GetGraphicFilter() ); } else @@ -188,8 +199,9 @@ void FuInsertGraphic::DoExecute( SfxRequest& rReq ) } } } - else + else if (!comphelper::LibreOfficeKit::isActive()) { + // TODO: enable in LOK, it contains synchronous error window without LOKNotifier SdGRFFilter::HandleGraphicFilterError( nError, GraphicFilter::GetGraphicFilter().GetLastError() ); } } diff --git a/sfx2/source/view/lokhelper.cxx b/sfx2/source/view/lokhelper.cxx index 647c580610f8..f21457e1b16d 100644 --- a/sfx2/source/view/lokhelper.cxx +++ b/sfx2/source/view/lokhelper.cxx @@ -1078,13 +1078,13 @@ VclPtr SfxLokHelper::getInPlaceDocWindow(SfxViewShell* pViewShell) return {}; } -void SfxLokHelper::sendNetworkAccessError() +void SfxLokHelper::sendNetworkAccessError(std::string_view rAction) { tools::JsonWriter aWriter; aWriter.put("code", static_cast( ErrCode(ErrCodeArea::Inet, sal_uInt16(ErrCodeClass::Access)))); aWriter.put("kind", "network"); - aWriter.put("cmd", "paste"); + aWriter.put("cmd", rAction); SfxViewShell* pViewShell = SfxViewShell::Current(); if (pViewShell) diff --git a/sw/source/filter/html/htmlgrin.cxx b/sw/source/filter/html/htmlgrin.cxx index 8304fa3002f3..4b5a0d5e4bd5 100644 --- a/sw/source/filter/html/htmlgrin.cxx +++ b/sw/source/filter/html/htmlgrin.cxx @@ -513,7 +513,7 @@ IMAGE_SETEVENT: else if (m_sBaseURL.isEmpty() || !aGraphicData.isEmpty()) { if (comphelper::LibreOfficeKit::isActive() && HostFilter::isForbidden(aGraphicURL.GetHost())) - SfxLokHelper::sendNetworkAccessError(); + SfxLokHelper::sendNetworkAccessError("paste"); // sBaseURL is empty if the source is clipboard // aGraphicData is non-empty for -> not a linked graphic. diff --git a/sw/source/uibase/uiview/view2.cxx b/sw/source/uibase/uiview/view2.cxx index 2c7a07449715..1006f5b493ff 100644 --- a/sw/source/uibase/uiview/view2.cxx +++ b/sw/source/uibase/uiview/view2.cxx @@ -50,6 +50,7 @@ #include #include #include +#include #include #include #include @@ -71,6 +72,7 @@ #include #include #include +#include #include #include #include @@ -309,6 +311,14 @@ ErrCode SwView::InsertGraphic( const OUString &rPath, const OUString &rFilter, { pFilter = &GraphicFilter::GetGraphicFilter(); } + + if (comphelper::LibreOfficeKit::isActive()) + { + INetURLObject aURL(rPath); + if (INetProtocol::File != aURL.GetProtocol() && HostFilter::isForbidden(aURL.GetHost())) + SfxLokHelper::sendNetworkAccessError("insert"); + } + aResult = GraphicFilter::LoadGraphic( rPath, rFilter, aGraphic, pFilter ); if( ERRCODE_NONE == aResult )