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(-)

New commits:
commit 81dc88afa5742aef1e3631f75cad0f99ef50bf95
Author:     Szymon Kłos <[email protected]>
AuthorDate: Tue Dec 19 19:24:19 2023 +0100
Commit:     Caolán McNamara <[email protected]>
CommitDate: Wed Dec 20 11:19:07 2023 +0100

    lok: send error on access denied in image import 2
    
    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 <[email protected]>
    Tested-by: Caolán McNamara <[email protected]>
    Reviewed-by: Caolán McNamara <[email protected]>

diff --git a/include/sfx2/lokhelper.hxx b/include/sfx2/lokhelper.hxx
index 24a508859fa1..e015cad58cda 100644
--- a/include/sfx2/lokhelper.hxx
+++ b/include/sfx2/lokhelper.hxx
@@ -227,7 +227,7 @@ public:
     static VclPtr<vcl::Window> 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 d0d00a9ecc29..e8abde6c92d7 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 9816bdb1e363..db40755682ad 100644
--- a/sc/source/ui/drawfunc/fuins1.cxx
+++ b/sc/source/ui/drawfunc/fuins1.cxx
@@ -22,6 +22,7 @@
 #include <officecfg/Office/Common.hxx>
 #include <editeng/sizeitem.hxx>
 #include <sal/log.hxx>
+#include <sfx2/lokhelper.hxx>
 #include <sfx2/opengrf.hxx>
 #include <sfx2/viewfrm.hxx>
 #include <svx/svdograf.hxx>
@@ -48,6 +49,9 @@
 #include <globstr.hrc>
 #include <comphelper/lok.hxx>
 
+#include <tools/hostfilter.hxx>
+#include <tools/urlobj.hxx>
+
 #include <com/sun/star/frame/XDispatchProvider.hpp>
 #include <com/sun/star/media/XPlayer.hpp>
 #include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp>
@@ -279,6 +283,13 @@ FuInsertGraphic::FuInsertGraphic( ScTabViewShell&   
rViewSh,
         if ( pReqArgs->GetItemState( FN_PARAM_1, true, &pItem ) == 
SfxItemState::SET )
             bAsLink = static_cast<const SfxBoolItem*>(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 a00cb453d6b0..3ca5b863fb2b 100644
--- a/sd/source/ui/func/fuinsert.cxx
+++ b/sd/source/ui/func/fuinsert.cxx
@@ -36,6 +36,7 @@
 
 #include <svl/stritem.hxx>
 #include <sfx2/dispatch.hxx>
+#include <sfx2/lokhelper.hxx>
 #include <sfx2/msgpool.hxx>
 #include <sfx2/msg.hxx>
 #include <svtools/insdlg.hxx>
@@ -58,6 +59,9 @@
 #include <svx/charthelper.hxx>
 #include <svx/svxids.hrc>
 
+#include <tools/hostfilter.hxx>
+#include <tools/urlobj.hxx>
+
 #include <sdresid.hxx>
 #include <View.hxx>
 #include <sdmod.hxx>
@@ -127,6 +131,13 @@ void FuInsertGraphic::DoExecute( SfxRequest& rReq )
         if ( pArgs->GetItemState( FN_PARAM_1, true, &pItem ) == 
SfxItemState::SET )
             bAsLink = static_cast<const SfxBoolItem*>(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
@@ -186,8 +197,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 2436c7cbe85d..20ef1528f03a 100644
--- a/sfx2/source/view/lokhelper.cxx
+++ b/sfx2/source/view/lokhelper.cxx
@@ -1080,13 +1080,13 @@ VclPtr<vcl::Window> 
SfxLokHelper::getInPlaceDocWindow(SfxViewShell* pViewShell)
     return {};
 }
 
-void SfxLokHelper::sendNetworkAccessError()
+void SfxLokHelper::sendNetworkAccessError(std::string_view rAction)
 {
     tools::JsonWriter aWriter;
     aWriter.put("code", static_cast<sal_uInt32>(
         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 1967b93c1ea3..7f678f624f48 100644
--- a/sw/source/filter/html/htmlgrin.cxx
+++ b/sw/source/filter/html/htmlgrin.cxx
@@ -512,7 +512,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 <object data="..."> -> not a linked 
graphic.
diff --git a/sw/source/uibase/uiview/view2.cxx 
b/sw/source/uibase/uiview/view2.cxx
index 36fd4386ddc2..ac4e03ebcfad 100644
--- a/sw/source/uibase/uiview/view2.cxx
+++ b/sw/source/uibase/uiview/view2.cxx
@@ -50,6 +50,7 @@
 #include <svx/statusitem.hxx>
 #include <svx/viewlayoutitem.hxx>
 #include <svx/zoomslideritem.hxx>
+#include <sfx2/lokhelper.hxx>
 #include <sfx2/htmlmode.hxx>
 #include <vcl/svapp.hxx>
 #include <sfx2/app.hxx>
@@ -71,6 +72,7 @@
 #include <svl/ptitem.hxx>
 #include <sfx2/viewfrm.hxx>
 #include <vcl/errinf.hxx>
+#include <tools/hostfilter.hxx>
 #include <tools/urlobj.hxx>
 #include <svx/svdview.hxx>
 #include <swtypes.hxx>
@@ -307,6 +309,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 )

Reply via email to