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 40c94cff178bd4bef4dc5ce38cc9eb67fe2eb780
Author:     Szymon Kłos <szymon.k...@collabora.com>
AuthorDate: Tue Dec 19 19:24:19 2023 +0100
Commit:     Szymon Kłos <szymon.k...@collabora.com>
CommitDate: Thu Jan 11 12:23:27 2024 +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 <jenkinscollaboraoff...@gmail.com>
    Tested-by: Caolán McNamara <caolan.mcnam...@collabora.com>
    Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/161774
    Tested-by: Jenkins
    Reviewed-by: Szymon Kłos <szymon.k...@collabora.com>

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<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 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 <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 31b286c822e3..e8409c815b25 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>
@@ -60,6 +61,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>
@@ -129,6 +133,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
@@ -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<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 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 <object data="..."> -> 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 <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>
@@ -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 )

Reply via email to