kbrown / rpms / libreoffice

Forked from rpms/libreoffice 2 years ago
Clone

Blame SOURCES/0389-libreofficekit-password-interaction-optional-and-off.patch

f325b2
From 419ebb636dc46040fe508f71af3f6baad3c930ff Mon Sep 17 00:00:00 2001
f325b2
From: Michael Stahl <mstahl@redhat.com>
f325b2
Date: Fri, 22 Jan 2016 13:39:32 +0100
f325b2
Subject: [PATCH 389/398] libreofficekit: password interaction optional and off
f325b2
 by default
f325b2
f325b2
Add setOptionalFeatures() function that clients must call during
f325b2
initialization, and enum LibreOfficeKitOptionalFeatures.
f325b2
f325b2
Reviewed-on: https://gerrit.libreoffice.org/21809
f325b2
Reviewed-by: Jan Holesovsky <kendy@collabora.com>
f325b2
Tested-by: Jan Holesovsky <kendy@collabora.com>
f325b2
(cherry picked from commit 23a0ee3c01c3588472e1c19605909d6b9401253c)
f325b2
f325b2
libreofficekit: ask for password when loading encrypted documents
f325b2
(cherry picked from commit 2b63e576a5cf06f4af877d63403ad7955ac71b72)
f325b2
f325b2
desktop: use x prefix for uno::Reference
f325b2
(cherry picked from commit 0101cd3da6262169fa273309a86ba5e7cfe573bf)
f325b2
f325b2
loplugin:defaultparams
f325b2
(cherry picked from commit 95c8b8e85d3328bfbe906ef3f69145842aae01db)
f325b2
f325b2
Reviewed-on: https://gerrit.libreoffice.org/21838
f325b2
Tested-by: Jenkins <ci@libreoffice.org>
f325b2
Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
f325b2
(cherry picked from commit 2241a7fd97b8b70d2d3106ac531cc72192ad708f)
f325b2
f325b2
Change-Id: I73035193c87033052921c3aad94fdc057fe81111
f325b2
---
f325b2
 desktop/inc/lib/init.hxx                     |  13 +++-
f325b2
 desktop/source/lib/init.cxx                  |  38 +++++++++-
f325b2
 desktop/source/lib/lokinteractionhandler.cxx | 107 +++++++++++++++++++++++++--
f325b2
 desktop/source/lib/lokinteractionhandler.hxx |  19 ++++-
f325b2
 include/LibreOfficeKit/LibreOfficeKit.h      |   9 +++
f325b2
 include/LibreOfficeKit/LibreOfficeKit.hxx    |  34 +++++++++
f325b2
 include/LibreOfficeKit/LibreOfficeKitEnums.h |  45 ++++++++++-
f325b2
 libreofficekit/source/gtk/lokdocview.cxx     |  10 +++
f325b2
 8 files changed, 264 insertions(+), 11 deletions(-)
f325b2
f325b2
diff --git a/desktop/inc/lib/init.hxx b/desktop/inc/lib/init.hxx
f325b2
index 4f878d26c007..560bd06c6cd9 100644
f325b2
--- a/desktop/inc/lib/init.hxx
f325b2
+++ b/desktop/inc/lib/init.hxx
f325b2
@@ -7,13 +7,16 @@
f325b2
  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
f325b2
  */
f325b2
 #include <LibreOfficeKit/LibreOfficeKit.h>
f325b2
+#include <LibreOfficeKit/LibreOfficeKitEnums.h>
f325b2
 #include <com/sun/star/frame/XStorable.hpp>
f325b2
 #include <com/sun/star/lang/XComponent.hpp>
f325b2
 #include <boost/shared_ptr.hpp>
f325b2
+#include <memory>
f325b2
+#include <map>
f325b2
 #include "../../source/inc/desktopdllapi.h"
f325b2
 #include <osl/thread.h>
f325b2
 
f325b2
-using namespace css;
f325b2
+class LOKInteractionHandler;
f325b2
 
f325b2
 namespace desktop {
f325b2
     struct DESKTOP_DLLPUBLIC LibLODocument_Impl : public _LibreOfficeKitDocument
f325b2
@@ -34,7 +37,15 @@ namespace desktop {
f325b2
         oslThread maThread;
f325b2
         LibreOfficeKitCallback mpCallback;
f325b2
         void *mpCallbackData;
f325b2
+        int64_t mOptionalFeatures;
f325b2
+        std::map<OString, rtl::Reference<LOKInteractionHandler>> mInteractionMap;
f325b2
 
f325b2
         LibLibreOffice_Impl();
f325b2
+        ~LibLibreOffice_Impl();
f325b2
+
f325b2
+        bool hasOptionalFeature(LibreOfficeKitOptionalFeatures const feature)
f325b2
+        {
f325b2
+            return (mOptionalFeatures & feature) != 0;
f325b2
+        }
f325b2
     };
f325b2
 }
f325b2
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
f325b2
index 6bed25514137..35ba91306036 100644
f325b2
--- a/desktop/source/lib/init.cxx
f325b2
+++ b/desktop/source/lib/init.cxx
f325b2
@@ -433,11 +433,16 @@ static void                    lo_registerCallback (LibreOfficeKit* pThis,
f325b2
                                                     LibreOfficeKitCallback pCallback,
f325b2
                                                     void* pData);
f325b2
 static char* lo_getFilterTypes(LibreOfficeKit* pThis);
f325b2
+static void lo_setOptionalFeatures(LibreOfficeKit* pThis, uint64_t features);
f325b2
+static void                    lo_setDocumentPassword(LibreOfficeKit* pThis,
f325b2
+                                                       const char* pURL,
f325b2
+                                                       const char* pPassword);
f325b2
 
f325b2
 LibLibreOffice_Impl::LibLibreOffice_Impl()
f325b2
     : maThread(0)
f325b2
     , mpCallback(nullptr)
f325b2
     , mpCallbackData(nullptr)
f325b2
+    , mOptionalFeatures(0)
f325b2
 {
f325b2
     if(!(m_pOfficeClass = gOfficeClass.lock())) {
f325b2
         m_pOfficeClass.reset(new LibreOfficeKitClass);
f325b2
@@ -449,6 +454,8 @@ LibLibreOffice_Impl::LibLibreOffice_Impl()
f325b2
         m_pOfficeClass->documentLoadWithOptions = lo_documentLoadWithOptions;
f325b2
         m_pOfficeClass->registerCallback = lo_registerCallback;
f325b2
         m_pOfficeClass->getFilterTypes = lo_getFilterTypes;
f325b2
+        m_pOfficeClass->setOptionalFeatures = lo_setOptionalFeatures;
f325b2
+        m_pOfficeClass->setDocumentPassword = lo_setDocumentPassword;
f325b2
 
f325b2
         gOfficeClass = m_pOfficeClass;
f325b2
     }
f325b2
@@ -456,6 +463,10 @@ LibLibreOffice_Impl::LibLibreOffice_Impl()
f325b2
     pClass = m_pOfficeClass.get();
f325b2
 }
f325b2
 
f325b2
+LibLibreOffice_Impl::~LibLibreOffice_Impl()
f325b2
+{
f325b2
+}
f325b2
+
f325b2
 namespace
f325b2
 {
f325b2
 
f325b2
@@ -517,7 +528,10 @@ static LibreOfficeKitDocument* lo_documentLoadWithOptions(LibreOfficeKit* pThis,
f325b2
                                                        uno::makeAny(OUString::createFromAscii(pOptions)),
f325b2
                                                        beans::PropertyState_DIRECT_VALUE);
f325b2
 
f325b2
-        uno::Reference<task::XInteractionHandler2> xInteraction(new LOKInteractionHandler(::comphelper::getProcessComponentContext()));
f325b2
+        rtl::Reference<LOKInteractionHandler> const pInteraction(
f325b2
+            new LOKInteractionHandler(::comphelper::getProcessComponentContext(), pLib));
f325b2
+        auto const pair(pLib->mInteractionMap.insert(std::make_pair(aURL.toUtf8(), pInteraction)));
f325b2
+        uno::Reference<task::XInteractionHandler2> const xInteraction(pInteraction.get());
f325b2
         aFilterOptions[1].Name = "InteractionHandler";
f325b2
         aFilterOptions[1].Value <<= xInteraction;
f325b2
 
f325b2
@@ -536,6 +550,12 @@ static LibreOfficeKitDocument* lo_documentLoadWithOptions(LibreOfficeKit* pThis,
f325b2
                                             aURL, OUString("_blank"), 0,
f325b2
                                             aFilterOptions);
f325b2
 
f325b2
+        assert(!xComponent.is() || pair.second); // concurrent loading of same URL ought to fail
f325b2
+        if (!pair.second)
f325b2
+        {
f325b2
+            pLib->mInteractionMap.erase(aURL.toUtf8());
f325b2
+        }
f325b2
+
f325b2
         if (!xComponent.is())
f325b2
         {
f325b2
             pLib->maLastExceptionMsg = "loadComponentFromURL returned an empty reference";
f325b2
@@ -1579,6 +1599,22 @@ static char* lo_getFilterTypes(LibreOfficeKit* pThis)
f325b2
     return strdup(aStream.str().c_str());
f325b2
 }
f325b2
 
f325b2
+static void lo_setOptionalFeatures(LibreOfficeKit* pThis, uint64_t const features)
f325b2
+{
f325b2
+    LibLibreOffice_Impl *const pLib = static_cast<LibLibreOffice_Impl*>(pThis);
f325b2
+    pLib->mOptionalFeatures = features;
f325b2
+}
f325b2
+
f325b2
+static void lo_setDocumentPassword(LibreOfficeKit* pThis,
f325b2
+        const char* pURL, const char* pPassword)
f325b2
+{
f325b2
+    assert(pThis);
f325b2
+    assert(pURL);
f325b2
+    LibLibreOffice_Impl *const pLib = static_cast<LibLibreOffice_Impl*>(pThis);
f325b2
+    assert(pLib->mInteractionMap.find(OString(pURL)) != pLib->mInteractionMap.end());
f325b2
+    pLib->mInteractionMap.find(OString(pURL))->second->SetPassword(pPassword);
f325b2
+}
f325b2
+
f325b2
 static void force_c_locale()
f325b2
 {
f325b2
     // force locale (and resource files loaded) to en-US
f325b2
diff --git a/desktop/source/lib/lokinteractionhandler.cxx b/desktop/source/lib/lokinteractionhandler.cxx
f325b2
index 1d20b0219e28..50a79721ff69 100644
f325b2
--- a/desktop/source/lib/lokinteractionhandler.cxx
f325b2
+++ b/desktop/source/lib/lokinteractionhandler.cxx
f325b2
@@ -19,14 +19,28 @@
f325b2
 
f325b2
 #include "lokinteractionhandler.hxx"
f325b2
 
f325b2
+#include <rtl/ref.hxx>
f325b2
 #include <cppuhelper/supportsservice.hxx>
f325b2
 
f325b2
+#include <com/sun/star/task/XInteractionAbort.hpp>
f325b2
 #include <com/sun/star/task/XInteractionApprove.hpp>
f325b2
+#include <com/sun/star/task/XInteractionPassword2.hpp>
f325b2
+#include <com/sun/star/task/DocumentPasswordRequest2.hpp>
f325b2
+
f325b2
+#define LOK_USE_UNSTABLE_API
f325b2
+#include <../../inc/lib/init.hxx>
f325b2
+
f325b2
+#include <LibreOfficeKit/LibreOfficeKitEnums.h>
f325b2
 
f325b2
 using namespace com::sun::star;
f325b2
 
f325b2
-LOKInteractionHandler::LOKInteractionHandler(uno::Reference<uno::XComponentContext> const & /*rxContext*/)
f325b2
+LOKInteractionHandler::LOKInteractionHandler(
f325b2
+        uno::Reference<uno::XComponentContext> const & /*rxContext*/,
f325b2
+        desktop::LibLibreOffice_Impl *const pLOKit)
f325b2
+    : m_pLOKit(pLOKit)
f325b2
+    , m_usePassword(false)
f325b2
 {
f325b2
+    assert(m_pLOKit);
f325b2
 }
f325b2
 
f325b2
 LOKInteractionHandler::~LOKInteractionHandler()
f325b2
@@ -58,15 +72,84 @@ void SAL_CALL LOKInteractionHandler::initialize(uno::Sequence<uno::Any> const &
f325b2
 {
f325b2
 }
f325b2
 
f325b2
-void SAL_CALL LOKInteractionHandler::handle(uno::Reference<task::XInteractionRequest> const & rRequest) throw (uno::RuntimeException, std::exception)
f325b2
+void SAL_CALL LOKInteractionHandler::handle(
f325b2
+        uno::Reference<task::XInteractionRequest> const & xRequest)
f325b2
+throw (uno::RuntimeException, std::exception)
f325b2
 {
f325b2
     // just do the same thing in both cases
f325b2
-    handleInteractionRequest(rRequest);
f325b2
+    handleInteractionRequest(xRequest);
f325b2
 }
f325b2
 
f325b2
-sal_Bool SAL_CALL LOKInteractionHandler::handleInteractionRequest(const uno::Reference<task::XInteractionRequest >& rRequest) throw ( uno::RuntimeException, std::exception )
f325b2
+sal_Bool SAL_CALL LOKInteractionHandler::handleInteractionRequest(
f325b2
+        const uno::Reference<task::XInteractionRequest>& xRequest)
f325b2
+throw (uno::RuntimeException, std::exception)
f325b2
 {
f325b2
-    uno::Sequence<uno::Reference<task::XInteractionContinuation>> const &rContinuations = rRequest->getContinuations();
f325b2
+    uno::Sequence<uno::Reference<task::XInteractionContinuation>> const &rContinuations = xRequest->getContinuations();
f325b2
+
f325b2
+    uno::Any const request(xRequest->getRequest());
f325b2
+    task::DocumentPasswordRequest2 passwordRequest;
f325b2
+    if (request >>= passwordRequest)
f325b2
+    {
f325b2
+        if (m_pLOKit->hasOptionalFeature((passwordRequest.IsRequestPasswordToModify)
f325b2
+                    ? LOK_FEATURE_DOCUMENT_PASSWORD_TO_MODIFY
f325b2
+                    : LOK_FEATURE_DOCUMENT_PASSWORD))
f325b2
+        {
f325b2
+            OString const url(passwordRequest.Name.toUtf8());
f325b2
+            m_pLOKit->mpCallback(passwordRequest.IsRequestPasswordToModify
f325b2
+                        ? LOK_CALLBACK_DOCUMENT_PASSWORD_TO_MODIFY
f325b2
+                        : LOK_CALLBACK_DOCUMENT_PASSWORD,
f325b2
+                    url.getStr(),
f325b2
+                    m_pLOKit->mpCallbackData);
f325b2
+
f325b2
+            // block until SetPassword is called
f325b2
+            m_havePassword.wait();
f325b2
+            m_havePassword.reset();
f325b2
+        }
f325b2
+
f325b2
+        for (sal_Int32 i = 0; i < rContinuations.getLength(); ++i)
f325b2
+        {
f325b2
+            if (m_usePassword)
f325b2
+            {
f325b2
+                if (passwordRequest.IsRequestPasswordToModify)
f325b2
+                {
f325b2
+                    uno::Reference<task::XInteractionPassword2> const xIPW2(
f325b2
+                            rContinuations[i], uno::UNO_QUERY);
f325b2
+                    xIPW2->setPasswordToModify(m_Password);
f325b2
+                    xIPW2->select();
f325b2
+                }
f325b2
+                else
f325b2
+                {
f325b2
+                    uno::Reference<task::XInteractionPassword> const xIPW(
f325b2
+                            rContinuations[i], uno::UNO_QUERY);
f325b2
+                    if (xIPW.is())
f325b2
+                    {
f325b2
+                        xIPW->setPassword(m_Password);
f325b2
+                        xIPW->select();
f325b2
+                    }
f325b2
+                }
f325b2
+            }
f325b2
+            else
f325b2
+            {
f325b2
+                if (passwordRequest.IsRequestPasswordToModify)
f325b2
+                {
f325b2
+                    uno::Reference<task::XInteractionPassword2> const xIPW2(
f325b2
+                            rContinuations[i], uno::UNO_QUERY);
f325b2
+                    xIPW2->setRecommendReadOnly(true);
f325b2
+                    xIPW2->select();
f325b2
+                }
f325b2
+                else
f325b2
+                {
f325b2
+                    uno::Reference<task::XInteractionAbort> const xAbort(
f325b2
+                            rContinuations[i], uno::UNO_QUERY);
f325b2
+                    if (xAbort.is())
f325b2
+                    {
f325b2
+                        xAbort->select();
f325b2
+                    }
f325b2
+                }
f325b2
+            }
f325b2
+        }
f325b2
+        return sal_True;
f325b2
+    }
f325b2
 
f325b2
     // TODO: add LOK api that allows handling this for real, for the moment we
f325b2
     // just set the interaction as 'Approved'
f325b2
@@ -80,4 +163,18 @@ sal_Bool SAL_CALL LOKInteractionHandler::handleInteractionRequest(const uno::Ref
f325b2
     return sal_True;
f325b2
 }
f325b2
 
f325b2
+void LOKInteractionHandler::SetPassword(char const*const pPassword)
f325b2
+{
f325b2
+    if (pPassword)
f325b2
+    {
f325b2
+        m_Password = OUString(pPassword, strlen(pPassword), RTL_TEXTENCODING_UTF8);
f325b2
+        m_usePassword = true;
f325b2
+    }
f325b2
+    else
f325b2
+    {
f325b2
+        m_usePassword = false;
f325b2
+    }
f325b2
+    m_havePassword.set();
f325b2
+}
f325b2
+
f325b2
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
f325b2
diff --git a/desktop/source/lib/lokinteractionhandler.hxx b/desktop/source/lib/lokinteractionhandler.hxx
f325b2
index 6d4aa8231daf..584658337fc4 100644
f325b2
--- a/desktop/source/lib/lokinteractionhandler.hxx
f325b2
+++ b/desktop/source/lib/lokinteractionhandler.hxx
f325b2
@@ -20,12 +20,15 @@
f325b2
 #ifndef INCLUDED_DESKTOP_SOURCE_LIB_LOKINTERACTIONHANDLER_HXX
f325b2
 #define INCLUDED_DESKTOP_SOURCE_LIB_LOKINTERACTIONHANDLER_HXX
f325b2
 
f325b2
+#include <osl/conditn.hxx>
f325b2
 #include <cppuhelper/implbase.hxx>
f325b2
 
f325b2
 #include <com/sun/star/lang/XInitialization.hpp>
f325b2
 #include <com/sun/star/lang/XServiceInfo.hpp>
f325b2
 #include <com/sun/star/task/InteractionHandler.hpp>
f325b2
 
f325b2
+namespace desktop { struct LibLibreOffice_Impl; }
f325b2
+
f325b2
 /** InteractionHandler is an interface that provides the user with various dialogs / error messages.
f325b2
 
f325b2
 We need an own implementation for the LibreOfficeKit so that we can route the
f325b2
@@ -38,11 +41,21 @@ class LOKInteractionHandler: public cppu::WeakImplHelper
f325b2
                                                          com::sun::star::lang::XInitialization,
f325b2
                                                          com::sun::star::task::XInteractionHandler2>
f325b2
 {
f325b2
-    LOKInteractionHandler(const LOKInteractionHandler&) SAL_DELETED_FUNCTION;
f325b2
-    LOKInteractionHandler& operator=(const LOKInteractionHandler&) SAL_DELETED_FUNCTION;
f325b2
+private:
f325b2
+    desktop::LibLibreOffice_Impl * m_pLOKit;
f325b2
+    OUString m_Password;
f325b2
+    bool m_usePassword;
f325b2
+    osl::Condition m_havePassword;
f325b2
+
f325b2
+    LOKInteractionHandler(const LOKInteractionHandler&) = delete;
f325b2
+    LOKInteractionHandler& operator=(const LOKInteractionHandler&) = delete;
f325b2
 
f325b2
 public:
f325b2
-    explicit LOKInteractionHandler(com::sun::star::uno::Reference<com::sun::star::uno::XComponentContext> const & rxContext);
f325b2
+    void SetPassword(char const* pPassword);
f325b2
+
f325b2
+    explicit LOKInteractionHandler(
f325b2
+            com::sun::star::uno::Reference<com::sun::star::uno::XComponentContext> const & rxContext,
f325b2
+            desktop::LibLibreOffice_Impl *);
f325b2
 
f325b2
     virtual ~LOKInteractionHandler();
f325b2
 
f325b2
diff --git a/include/LibreOfficeKit/LibreOfficeKit.h b/include/LibreOfficeKit/LibreOfficeKit.h
f325b2
index 5189cca5eb5e..b31e5eef1c01 100644
f325b2
--- a/include/LibreOfficeKit/LibreOfficeKit.h
f325b2
+++ b/include/LibreOfficeKit/LibreOfficeKit.h
f325b2
@@ -15,6 +15,7 @@
f325b2
 #ifdef LOK_USE_UNSTABLE_API
f325b2
 // the unstable API needs C99's bool
f325b2
 #include <stdbool.h>
f325b2
+#include <stdint.h>
f325b2
 #endif
f325b2
 
f325b2
 #include <LibreOfficeKit/LibreOfficeKitTypes.h>
f325b2
@@ -62,6 +63,14 @@ struct _LibreOfficeKitClass
f325b2
 
f325b2
     /// @see lok::Office::getFilterTypes().
f325b2
     char* (*getFilterTypes) (LibreOfficeKit* pThis);
f325b2
+
f325b2
+    /// @see lok::Office::setOptionalFeatures().
f325b2
+    void (*setOptionalFeatures)(LibreOfficeKit* pThis, uint64_t features);
f325b2
+
f325b2
+    /// @see lok::Office::setDocumentPassword().
f325b2
+    void (*setDocumentPassword) (LibreOfficeKit* pThis,
f325b2
+            char const* pURL,
f325b2
+            char const* pPassword);
f325b2
 #endif
f325b2
 };
f325b2
 
f325b2
diff --git a/include/LibreOfficeKit/LibreOfficeKit.hxx b/include/LibreOfficeKit/LibreOfficeKit.hxx
f325b2
index e592bbe549ab..53ad4359357a 100644
f325b2
--- a/include/LibreOfficeKit/LibreOfficeKit.hxx
f325b2
+++ b/include/LibreOfficeKit/LibreOfficeKit.hxx
f325b2
@@ -442,6 +442,40 @@ public:
f325b2
     {
f325b2
         return mpThis->pClass->getFilterTypes(mpThis);
f325b2
     }
f325b2
+
f325b2
+    /**
f325b2
+     * Set bitmask of optional features supported by the client.
f325b2
+     *
f325b2
+     * @see LibreOfficeKitOptionalFeatures
f325b2
+     */
f325b2
+    void setOptionalFeatures(uint64_t features)
f325b2
+    {
f325b2
+        return mpThis->pClass->setOptionalFeatures(mpThis, features);
f325b2
+    }
f325b2
+
f325b2
+    /**
f325b2
+     * Set password required for loading or editing a document.
f325b2
+     *
f325b2
+     * Loading the document is blocked until the password is provided.
f325b2
+     *
f325b2
+     * @param pURL      the URL of the document, as sent to the callback
f325b2
+     * @param pPassword the password, nullptr indicates no password
f325b2
+     *
f325b2
+     * In response to LOK_CALLBACK_DOCUMENT_PASSWORD, a vaild password
f325b2
+     * will continue loading the document, an invalid password will
f325b2
+     * result in another LOK_CALLBACK_DOCUMENT_PASSWORD request,
f325b2
+     * and a NULL password will abort loading the document.
f325b2
+     *
f325b2
+     * In response to LOK_CALLBACK_DOCUMENT_PASSWORD_TO_MODIFY, a vaild
f325b2
+     * password will continue loading the document, an invalid password will
f325b2
+     * result in another LOK_CALLBACK_DOCUMENT_PASSWORD_TO_MODIFY request,
f325b2
+     * and a NULL password will continue loading the document in read-only
f325b2
+     * mode.
f325b2
+     */
f325b2
+    inline void setDocumentPassword(char const* pURL, char const* pPassword)
f325b2
+    {
f325b2
+        mpThis->pClass->setDocumentPassword(mpThis, pURL, pPassword);
f325b2
+    }
f325b2
 #endif // LOK_USE_UNSTABLE_API
f325b2
 };
f325b2
 
f325b2
diff --git a/include/LibreOfficeKit/LibreOfficeKitEnums.h b/include/LibreOfficeKit/LibreOfficeKitEnums.h
f325b2
index a0f5e886dcac..5931f7871e50 100644
f325b2
--- a/include/LibreOfficeKit/LibreOfficeKitEnums.h
f325b2
+++ b/include/LibreOfficeKit/LibreOfficeKitEnums.h
f325b2
@@ -40,6 +40,32 @@ typedef enum
f325b2
 }
f325b2
 LibreOfficeKitTileMode;
f325b2
 
f325b2
+/** Optional features of LibreOfficeKit, in particular callbacks that block
f325b2
+ *  LibreOfficeKit until the corresponding reply is received, which would
f325b2
+ *  deadlock if the client does not support the feature.
f325b2
+ *
f325b2
+ *  @see lok::Office::setOptionalFeatures().
f325b2
+ */
f325b2
+typedef enum
f325b2
+{
f325b2
+    /**
f325b2
+     * Handle LOK_CALLBACK_DOCUMENT_PASSWORD by prompting the user
f325b2
+     * for a password.
f325b2
+     *
f325b2
+     * @see lok::Office::setDocumentPassword().
f325b2
+     */
f325b2
+    LOK_FEATURE_DOCUMENT_PASSWORD = (1ULL << 0),
f325b2
+
f325b2
+    /**
f325b2
+     * Handle LOK_CALLBACK_DOCUMENT_PASSWORD_TO_MODIFY by prompting the user
f325b2
+     * for a password.
f325b2
+     *
f325b2
+     * @see lok::Office::setDocumentPassword().
f325b2
+     */
f325b2
+    LOK_FEATURE_DOCUMENT_PASSWORD_TO_MODIFY = (1ULL << 1),
f325b2
+}
f325b2
+LibreOfficeKitOptionalFeatures;
f325b2
+
f325b2
 typedef enum
f325b2
 {
f325b2
     /**
f325b2
@@ -221,7 +247,24 @@ typedef enum
f325b2
     /**
f325b2
      * The text content of the formula bar in Calc.
f325b2
      */
f325b2
-    LOK_CALLBACK_CELL_FORMULA
f325b2
+    LOK_CALLBACK_CELL_FORMULA,
f325b2
+
f325b2
+    /**
f325b2
+     * Loading a document requires a password.
f325b2
+     *
f325b2
+     * Loading the document is blocked until the password is provided via
f325b2
+     * lok::Office::setDocumentPassword().  The document cannot be loaded
f325b2
+     * without the password.
f325b2
+     */
f325b2
+    LOK_CALLBACK_DOCUMENT_PASSWORD,
f325b2
+
f325b2
+    /**
f325b2
+     * Editing a document requires a password.
f325b2
+     *
f325b2
+     * Loading the document is blocked until the password is provided via
f325b2
+     * lok::Office::setDocumentPassword().
f325b2
+     */
f325b2
+    LOK_CALLBACK_DOCUMENT_PASSWORD_TO_MODIFY,
f325b2
 }
f325b2
 LibreOfficeKitCallbackType;
f325b2
 
f325b2
diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx
f325b2
index 1af678e1acc2..960c8c1f2624 100644
f325b2
--- a/libreofficekit/source/gtk/lokdocview.cxx
f325b2
+++ b/libreofficekit/source/gtk/lokdocview.cxx
f325b2
@@ -804,6 +804,14 @@ globalCallback (gpointer pData)
f325b2
         g_signal_emit (pCallback->m_pDocView, doc_view_signals[LOAD_CHANGED], 0, 1.0);
f325b2
     }
f325b2
     break;
f325b2
+    case LOK_CALLBACK_DOCUMENT_PASSWORD:
f325b2
+    case LOK_CALLBACK_DOCUMENT_PASSWORD_TO_MODIFY:
f325b2
+    {
f325b2
+        char const*const pURL(pCallback->m_aPayload.c_str());
f325b2
+        // TODO maybe allow more passwords
f325b2
+        priv->m_pOffice->pClass->setDocumentPassword(priv->m_pOffice, pURL, "1");
f325b2
+    }
f325b2
+    break;
f325b2
     default:
f325b2
         g_assert(false);
f325b2
         break;
f325b2
@@ -2026,6 +2034,8 @@ static gboolean lok_doc_view_initable_init (GInitable *initable, GCancellable* /
f325b2
         return FALSE;
f325b2
     }
f325b2
 
f325b2
+//    priv->m_pOffice->pClass->setOptionalFeatures(priv->m_pOffice, LOK_FEATURE_DOCUMENT_PASSWORD|LOK_FEATURE_DOCUMENT_PASSWORD_TO_MODIFY);
f325b2
+
f325b2
     return TRUE;
f325b2
 }
f325b2
 
f325b2
-- 
f325b2
2.12.0
f325b2