embeddedobj/source/commonembedding/embedobj.cxx      |    4 +
 embeddedobj/source/commonembedding/specialobject.cxx |    5 ++
 embeddedobj/source/msole/oleembed.cxx                |    5 +-
 sfx2/source/appl/appserv.cxx                         |   42 +++++++++++++++++++
 sfx2/source/appl/linkmgr2.cxx                        |    3 -
 5 files changed, 57 insertions(+), 2 deletions(-)

New commits:
commit a321084efea4d3ecb8dc2f5a120266ec53647a63
Author:     Sarper Akdemir <sarper.akdemir.ext...@allotropia.de>
AuthorDate: Thu Feb 29 13:38:00 2024 +0300
Commit:     Sarper Akdemir <sarper.akdemir.ext...@allotropia.de>
CommitDate: Thu Mar 7 12:30:23 2024 +0100

    do not assume there are no extra seperators at the end for dde links
    
    Change-Id: Idee81b9a8a38aed2375092d2394010063c131fe2
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164368
    Tested-by: Jenkins
    Reviewed-by: Sarper Akdemir <sarper.akdemir.ext...@allotropia.de>

diff --git a/sfx2/source/appl/linkmgr2.cxx b/sfx2/source/appl/linkmgr2.cxx
index a20501a1bad6..01a88afd355f 100644
--- a/sfx2/source/appl/linkmgr2.cxx
+++ b/sfx2/source/appl/linkmgr2.cxx
@@ -259,13 +259,14 @@ bool LinkManager::GetDisplayNames( const SvBaseLink * 
pLink,
                     sal_Int32 nTmp = 0;
                     OUString sServer( sLNm.getToken( 0, cTokenSeparator, nTmp 
) );
                     OUString sTopic( sLNm.getToken( 0, cTokenSeparator, nTmp ) 
);
+                    OUString sLinkStr( sLNm.getToken(0, cTokenSeparator, nTmp) 
);
 
                     if( pType )
                         *pType = sServer;
                     if( pFile )
                         *pFile = sTopic;
                     if( pLinkStr )
-                        *pLinkStr = nTmp != -1 ? sLNm.copy(nTmp) : OUString();
+                        *pLinkStr = sLinkStr;
                     bRet = true;
                 }
                 break;
commit cb685f603e15d73fc518b8d4e896f96f21bab4ea
Author:     Sarper Akdemir <sarper.akdemir.ext...@allotropia.de>
AuthorDate: Mon Jan 29 18:40:26 2024 +0300
Commit:     Sarper Akdemir <sarper.akdemir.ext...@allotropia.de>
CommitDate: Thu Mar 7 12:30:15 2024 +0100

    tdf#158375: make it possible to hot disable embedded objects
    
    Do not require a reload of the current document for the
    embedded objects to be disabled.
    
    Also make sure the existing active embedded objects are
    disabled when DisableActiveContent is enabled via options
    dialog.
    
    Change-Id: I5a8f302af0cac64575c3e5ec6dbe71ec50a15442
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/164367
    Tested-by: Jenkins
    Reviewed-by: Sarper Akdemir <sarper.akdemir.ext...@allotropia.de>

diff --git a/embeddedobj/source/commonembedding/embedobj.cxx 
b/embeddedobj/source/commonembedding/embedobj.cxx
index 0b3843852e58..61e5d1f39ef4 100644
--- a/embeddedobj/source/commonembedding/embedobj.cxx
+++ b/embeddedobj/source/commonembedding/embedobj.cxx
@@ -40,6 +40,7 @@
 #include <comphelper/multicontainer2.hxx>
 #include <comphelper/lok.hxx>
 #include <sal/log.hxx>
+#include <officecfg/Office/Common.hxx>
 
 #include <vcl/svapp.hxx>
 
@@ -475,6 +476,9 @@ uno::Sequence< sal_Int32 > const & 
OCommonEmbeddedObject::GetIntermediateStatesS
 
 void SAL_CALL OCommonEmbeddedObject::changeState( sal_Int32 nNewState )
 {
+    if ( 
officecfg::Office::Common::Security::Scripting::DisableActiveContent::get()
+        && nNewState != embed::EmbedStates::LOADED )
+        throw embed::UnreachableStateException();
     ::osl::ResettableMutexGuard aGuard( m_aMutex );
     if ( m_bDisposed )
         throw lang::DisposedException(); // TODO
diff --git a/embeddedobj/source/commonembedding/specialobject.cxx 
b/embeddedobj/source/commonembedding/specialobject.cxx
index 3dc1eb7e47ef..a2f282ed1aae 100644
--- a/embeddedobj/source/commonembedding/specialobject.cxx
+++ b/embeddedobj/source/commonembedding/specialobject.cxx
@@ -29,6 +29,7 @@
 #include <cppuhelper/queryinterface.hxx>
 #include <osl/diagnose.h>
 #include <cppuhelper/supportsservice.hxx>
+#include <officecfg/Office/Common.hxx>
 
 #include <specialobject.hxx>
 
@@ -137,6 +138,10 @@ sal_Int32 SAL_CALL OSpecialEmbeddedObject::getMapUnit( 
sal_Int64 nAspect )
 
 void SAL_CALL OSpecialEmbeddedObject::changeState( sal_Int32 nNewState )
 {
+    if ( 
officecfg::Office::Common::Security::Scripting::DisableActiveContent::get()
+         && nNewState != embed::EmbedStates::LOADED )
+        throw embed::UnreachableStateException();
+
     if ( nNewState == embed::EmbedStates::UI_ACTIVE )
         nNewState = embed::EmbedStates::INPLACE_ACTIVE;
     OCommonEmbeddedObject::changeState( nNewState );
diff --git a/embeddedobj/source/msole/oleembed.cxx 
b/embeddedobj/source/msole/oleembed.cxx
index 8379a78693f1..69b3ca8d239e 100644
--- a/embeddedobj/source/msole/oleembed.cxx
+++ b/embeddedobj/source/msole/oleembed.cxx
@@ -52,7 +52,7 @@
 #include <comphelper/propertyvalue.hxx>
 #include <sal/log.hxx>
 #include <comphelper/diagnose_ex.hxx>
-
+#include <officecfg/Office/Common.hxx>
 
 #include <targetstatecontrol.hxx>
 
@@ -438,6 +438,9 @@ bool OleEmbeddedObject::TryToConvertToOOo( const 
uno::Reference< io::XStream >&
 
 void SAL_CALL OleEmbeddedObject::changeState( sal_Int32 nNewState )
 {
+    if ( 
officecfg::Office::Common::Security::Scripting::DisableActiveContent::get()
+         && nNewState != embed::EmbedStates::LOADED )
+        throw embed::UnreachableStateException();
     // begin wrapping related part ====================
     uno::Reference< embed::XEmbeddedObject > xWrappedObject = m_xWrappedObject;
     if ( xWrappedObject.is() )
diff --git a/sfx2/source/appl/appserv.cxx b/sfx2/source/appl/appserv.cxx
index ed114b0d31a7..ecd290c4940b 100644
--- a/sfx2/source/appl/appserv.cxx
+++ b/sfx2/source/appl/appserv.cxx
@@ -28,6 +28,9 @@
 #include <com/sun/star/frame/UnknownModuleException.hpp>
 #include <com/sun/star/frame/XLayoutManager.hpp>
 #include <com/sun/star/frame/XSynchronousFrameLoader.hpp>
+#include <com/sun/star/embed/EmbedStates.hpp>
+#include <com/sun/star/embed/XEmbeddedObject.hpp>
+#include <com/sun/star/util/XModifiable.hpp>
 #include <com/sun/star/sdbc/DriverManager.hpp>
 #include <com/sun/star/text/ModuleDispatcher.hpp>
 #include <com/sun/star/task/OfficeRestartManager.hpp>
@@ -199,6 +202,35 @@ namespace
             TOOLS_INFO_EXCEPTION( "sfx.appl", "trying to load bibliography 
database");
         }
     }
+    void lcl_disableActiveEmbeddedObjects(SfxObjectShell* pObjSh)
+    {
+        if (!pObjSh)
+            return;
+
+        comphelper::EmbeddedObjectContainer& rContainer = 
pObjSh->getEmbeddedObjectContainer();
+        if (!rContainer.HasEmbeddedObjects())
+            return;
+
+        const uno::Sequence<OUString> aNames = rContainer.GetObjectNames();
+        for (const auto& rName : aNames)
+        {
+            uno::Reference<embed::XEmbeddedObject> xEmbeddedObj
+                = rContainer.GetEmbeddedObject(rName);
+            if (!xEmbeddedObj.is())
+                continue;
+
+            try
+            {
+                if (xEmbeddedObj->getCurrentState() != 
embed::EmbedStates::LOADED)
+                {
+                    xEmbeddedObj->changeState(embed::EmbedStates::LOADED);
+                }
+            }
+            catch (const uno::Exception&)
+            {
+            }
+        }
+    }
 }
 /// Find the correct location of the document (CREDITS.fodt, etc.), and return
 /// it in rURL if found.
@@ -1469,13 +1501,23 @@ void SfxApplication::OfaExec_Impl( SfxRequest& rReq )
             short nRet = pDlg->Execute();
             pDlg.disposeAndClear();
             SfxViewFrame* pView = SfxViewFrame::GetFirst();
+            bool bDisableActiveContent
+                    = 
officecfg::Office::Common::Security::Scripting::DisableActiveContent::get();
+
             while ( pView )
             {
                 if (nRet == RET_OK)
                 {
                     SfxObjectShell* pObjSh = pView->GetObjectShell();
                     if (pObjSh)
+                    {
                         pObjSh->SetConfigOptionsChecked(false);
+
+                        // when active content is disabled via options dialog,
+                        // disable all current active embedded objects
+                        if (bDisableActiveContent)
+                            lcl_disableActiveEmbeddedObjects(pObjSh);
+                    }
                 }
                 pView->GetBindings().InvalidateAll(false);
                 pView = SfxViewFrame::GetNext( *pView );

Reply via email to