From 32842d4bf250bcab281eb71a218d618485c60290 Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Fri, 26 Nov 2021 08:45:24 +0100 Subject: sw, viewing OLE objects: also protect "common" embeded objects Commit 4f9f1ac33366817df61c488a9f36b09c592ee939 (sw: allow viewing OLE objects in protected sections, 2021-11-25) allowed launching OLE objects in protected sections, and then made sure that changes done in "real" OLE editors (on Windows) are discarded: both the native data and preview. Extend this mechanism to also handle common embedded objects (i.e. when we load the data into an own document model, like Calc-in-Writer on Linux): there we can simply load the data read-only, so there will be no need to discard anything. This requires some way to pass down the read-only flag from sw/ to embeddedobj, implement XInitialization on OCommonEmbeddedObject to do that. Change-Id: I7b32d7514a6b0a40b4f58bed57879d292daa4ed7 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/125858 Reviewed-by: Miklos Vajna Tested-by: Jenkins --- embeddedobj/source/commonembedding/miscobj.cxx | 22 ++++++++++++++++++++++ embeddedobj/source/commonembedding/persistence.cxx | 5 +++++ embeddedobj/source/inc/commonembobj.hxx | 5 +++++ 3 files changed, 32 insertions(+) (limited to 'embeddedobj') diff --git a/embeddedobj/source/commonembedding/miscobj.cxx b/embeddedobj/source/commonembedding/miscobj.cxx index 9c24185ed184..538e0b72e3da 100644 --- a/embeddedobj/source/commonembedding/miscobj.cxx +++ b/embeddedobj/source/commonembedding/miscobj.cxx @@ -39,6 +39,7 @@ #include #include #include +#include #include "persistence.hxx" @@ -398,6 +399,11 @@ uno::Any SAL_CALL OCommonEmbeddedObject::queryInterface( const uno::Type& rType void* p = static_cast(this); return uno::Any(&p, rType); } + else if (rType == cppu::UnoType::get()) + { + void* p = static_cast(this); + return uno::Any(&p, rType); + } else if (rType == cppu::UnoType::get()) { void* p = static_cast(this); @@ -671,6 +677,7 @@ uno::Sequence SAL_CALL OCommonEmbeddedObject::getTypes() cppu::UnoType::get(), cppu::UnoType::get(), cppu::UnoType::get(), + cppu::UnoType::get(), cppu::UnoType::get(), }; return aTypes; @@ -681,4 +688,19 @@ uno::Sequence SAL_CALL OCommonEmbeddedObject::getImplementationId() return uno::Sequence(); } +void SAL_CALL OCommonEmbeddedObject::initialize(const uno::Sequence& rArguments) +{ + if (!rArguments.hasElements()) + { + return; + } + + comphelper::SequenceAsHashMap aMap(rArguments[0]); + auto it = aMap.find("ReadOnly"); + if (it != aMap.end()) + { + it->second >>= m_bReadOnly; + } +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/embeddedobj/source/commonembedding/persistence.cxx b/embeddedobj/source/commonembedding/persistence.cxx index 2ed891d33ced..faf3209e1f32 100644 --- a/embeddedobj/source/commonembedding/persistence.cxx +++ b/embeddedobj/source/commonembedding/persistence.cxx @@ -534,6 +534,11 @@ uno::Reference< util::XCloseable > OCommonEmbeddedObject::LoadDocumentFromStorag // set the document mode to embedded as the first step!!! EmbedAndReparentDoc_Impl( xDocument ); + if (m_bReadOnly) + { + aLoadArgs.put("ReadOnly", true); + } + if ( xDoc.is() ) { xDoc->loadFromStorage( xSourceStorage, aLoadArgs.getPropertyValues() ); diff --git a/embeddedobj/source/inc/commonembobj.hxx b/embeddedobj/source/inc/commonembobj.hxx index fab8ccbc717e..785a28eaf0fd 100644 --- a/embeddedobj/source/inc/commonembobj.hxx +++ b/embeddedobj/source/inc/commonembobj.hxx @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -81,6 +82,7 @@ class OCommonEmbeddedObject : public css::embed::XEmbeddedObject , public css::container::XChild , public css::chart2::XDefaultSizeTransmitter , public css::lang::XServiceInfo + , public css::lang::XInitialization , public css::lang::XTypeProvider , public ::cppu::OWeakObject { @@ -408,6 +410,9 @@ public: sal_Bool SAL_CALL supportsService( const OUString& ServiceName ) override; css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override; + // XInitialization + void SAL_CALL initialize(const css::uno::Sequence& rArguments) override; + // XTypeProvider css::uno::Sequence SAL_CALL getTypes() override; css::uno::Sequence SAL_CALL getImplementationId() override; -- cgit