embeddedobj/source/general/xcreator.cxx                    |   15 ++++++++++++-
 officecfg/registry/schema/org/openoffice/Office/Common.xcs |    7 ++++++
 2 files changed, 21 insertions(+), 1 deletion(-)

New commits:
commit 8d3ac3968e31d8d804d72d39a9387f225d30d087
Author:     Sarper Akdemir <sarper.akdemir.ext...@allotropia.de>
AuthorDate: Wed Dec 6 21:40:37 2023 +0300
Commit:     Sarper Akdemir <sarper.akdemir.ext...@allotropia.de>
CommitDate: Thu Dec 7 13:07:17 2023 +0100

    tdf#158375: add expert option to disable active content
    
    adds new expert option DisableActiveContent
    
    Right now only disables active embedded content / OLE.
    
    If OLE content is being imported via
    UNOEmbeddedObjectCreator::createInstanceInitFromEntry with the
    expert option DisableActiveContent set, the imported OLE object is
    now forced to be ODummyEmbeddedObject.
    
    ODummyEmbeddedObject doesn't implement any other state then
    embed::EmbedStates::LOADED (i.e. doesn't implement RUNNING,
    ACTIVE etc.) which makes it possible to prevent the imported OLE
    object becoming active.
    
    The functions that now throw lang::NoSuchElementException are
    usually called on new creation of embedded content via UI. But
    since the call sites expect the possibility of embedded content
    failing to initialize, that is handled by showing a popup stating
    some form of `unable to insert`.
    
    A follow-up improvement of disabling insertion of OLE content via
    dialogs could be implemented.
    
    Change-Id: Ib558a2a129b491798f5036a7bb269116545be75d
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/160402
    Tested-by: Jenkins
    Reviewed-by: Sarper Akdemir <sarper.akdemir.ext...@allotropia.de>

diff --git a/embeddedobj/source/general/xcreator.cxx 
b/embeddedobj/source/general/xcreator.cxx
index c4a8635e465d..c9151827a65f 100644
--- a/embeddedobj/source/general/xcreator.cxx
+++ b/embeddedobj/source/general/xcreator.cxx
@@ -25,6 +25,7 @@
 #include <com/sun/star/beans/PropertyValue.hpp>
 #include <com/sun/star/beans/XPropertySet.hpp>
 #include <com/sun/star/container/XNameAccess.hpp>
+#include <com/sun/star/lang/NoSupportException.hpp>
 #include <com/sun/star/lang/XComponent.hpp>
 
 #include <cppuhelper/supportsservice.hxx>
@@ -45,6 +46,8 @@ uno::Reference< uno::XInterface > SAL_CALL 
UNOEmbeddedObjectCreator::createInsta
                                             const OUString& sEntName,
                                             const uno::Sequence< 
beans::PropertyValue >& lObjArgs )
 {
+    if ( 
officecfg::Office::Common::Security::Scripting::DisableActiveContent::get() )
+        throw lang::NoSupportException("Active OLE content is disabled!");
     if ( !xStorage.is() )
         throw lang::IllegalArgumentException( "No parent storage is provided!",
                                             static_cast< ::cppu::OWeakObject* 
>(this),
@@ -164,7 +167,10 @@ uno::Reference< uno::XInterface > SAL_CALL 
UNOEmbeddedObjectCreator::createInsta
             aEmbedFactory = 
m_aConfigHelper.GetFactoryNameByMediaType(MIMETYPE_VND_SUN_XML_BASE_ASCII);
     }
 
-    if ( !aEmbedFactory.isEmpty() )
+    if ( !aEmbedFactory.isEmpty()
+         // when active OLE content is disabled, ignore aEmbedFactory and force
+         // the embedded object to be an ODummyEmbeddedObject
+         && 
!officecfg::Office::Common::Security::Scripting::DisableActiveContent::get() )
     {
         uno::Reference< uno::XInterface > xFact = 
m_xContext->getServiceManager()->createInstanceWithContext(aEmbedFactory, 
m_xContext);
 
@@ -238,6 +244,8 @@ uno::Reference< uno::XInterface > SAL_CALL 
UNOEmbeddedObjectCreator::createInsta
         const uno::Sequence< beans::PropertyValue >& aMediaDescr,
         const uno::Sequence< beans::PropertyValue >& lObjArgs )
 {
+    if ( 
officecfg::Office::Common::Security::Scripting::DisableActiveContent::get() )
+        throw lang::NoSupportException("Active OLE content is disabled!");
     // TODO: use lObjArgs
 
     if ( !xStorage.is() )
@@ -299,6 +307,8 @@ uno::Reference< uno::XInterface > SAL_CALL 
UNOEmbeddedObjectCreator::createInsta
         const uno::Sequence< beans::PropertyValue >& aArgs,
         const uno::Sequence< beans::PropertyValue >& aObjectArgs )
 {
+    if ( 
officecfg::Office::Common::Security::Scripting::DisableActiveContent::get() )
+        throw lang::NoSupportException("Active OLE content is disabled!");
     if ( !xStorage.is() )
         throw lang::IllegalArgumentException( "No parent storage is provided!",
                                             static_cast< ::cppu::OWeakObject* 
>(this),
@@ -330,6 +340,9 @@ uno::Reference< uno::XInterface > SAL_CALL 
UNOEmbeddedObjectCreator::createInsta
                                             const uno::Sequence< 
beans::PropertyValue >& aMediaDescr,
                                             const uno::Sequence< 
beans::PropertyValue >& lObjArgs )
 {
+    if ( 
officecfg::Office::Common::Security::Scripting::DisableActiveContent::get() )
+        throw lang::NoSupportException("Active OLE content is disabled!");
+
     uno::Reference< uno::XInterface > xResult;
 
     uno::Sequence< beans::PropertyValue > aTempMedDescr( aMediaDescr );
diff --git a/officecfg/registry/schema/org/openoffice/Office/Common.xcs 
b/officecfg/registry/schema/org/openoffice/Office/Common.xcs
index bf760476afa3..27e7eba04007 100644
--- a/officecfg/registry/schema/org/openoffice/Office/Common.xcs
+++ b/officecfg/registry/schema/org/openoffice/Office/Common.xcs
@@ -2517,6 +2517,13 @@
           </info>
           <value>false</value>
         </prop>
+        <prop oor:name="DisableActiveContent" oor:type="xs:boolean" 
oor:nillable="false">
+          <info>
+            <desc>Specifies whether or not to disable active content. Right now
+            only disables active embedded content (OLE).</desc>
+          </info>
+          <value>false</value>
+        </prop>
         <prop oor:name="CheckDocumentEvents" oor:type="xs:boolean" 
oor:nillable="false">
           <info>
             <desc>Warn on load when a document binds an event to a macro</desc>

Reply via email to