[Libreoffice-commits] core.git: desktop/inc desktop/source include/LibreOfficeKit libreofficekit/source

Michael Stahl mstahl at redhat.com
Wed Jan 27 00:26:57 PST 2016


 desktop/inc/lib/init.hxx                     |    7 +++++++
 desktop/source/lib/init.cxx                  |    9 +++++++++
 desktop/source/lib/lokinteractionhandler.cxx |   19 ++++++++++++-------
 include/LibreOfficeKit/LibreOfficeKit.h      |    4 ++++
 include/LibreOfficeKit/LibreOfficeKit.hxx    |   10 ++++++++++
 include/LibreOfficeKit/LibreOfficeKitEnums.h |   26 ++++++++++++++++++++++++++
 libreofficekit/source/gtk/lokdocview.cxx     |    2 ++
 7 files changed, 70 insertions(+), 7 deletions(-)

New commits:
commit 23a0ee3c01c3588472e1c19605909d6b9401253c
Author: Michael Stahl <mstahl at redhat.com>
Date:   Tue Jan 26 15:35:42 2016 +0100

    libreofficekit: password interaction optional and off by default
    
    Add setOptionalFeatures() function that clients must call during
    initialization, and enum LibreOfficeKitOptionalFeatures.
    
    Change-Id: I73035193c87033052921c3aad94fdc057fe81111
    Reviewed-on: https://gerrit.libreoffice.org/21809
    Reviewed-by: Jan Holesovsky <kendy at collabora.com>
    Tested-by: Jan Holesovsky <kendy at collabora.com>

diff --git a/desktop/inc/lib/init.hxx b/desktop/inc/lib/init.hxx
index ee598a0..d077297 100644
--- a/desktop/inc/lib/init.hxx
+++ b/desktop/inc/lib/init.hxx
@@ -11,6 +11,7 @@
 #define INCLUDED_DESKTOP_INC_LIB_INIT_HXX
 
 #include <LibreOfficeKit/LibreOfficeKit.h>
+#include <LibreOfficeKit/LibreOfficeKitEnums.h>
 #include <com/sun/star/frame/XStorable.hpp>
 #include <com/sun/star/lang/XComponent.hpp>
 #include <memory>
@@ -39,10 +40,16 @@ namespace desktop {
         oslThread maThread;
         LibreOfficeKitCallback mpCallback;
         void *mpCallbackData;
+        int64_t mOptionalFeatures;
         std::map<OString, rtl::Reference<LOKInteractionHandler>> mInteractionMap;
 
         LibLibreOffice_Impl();
         ~LibLibreOffice_Impl();
+
+        bool hasOptionalFeature(LibreOfficeKitOptionalFeatures const feature)
+        {
+            return (mOptionalFeatures & feature) != 0;
+        }
     };
 }
 
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index 88b5d1f..eecb16a 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -427,6 +427,7 @@ static void                    lo_registerCallback (LibreOfficeKit* pThis,
                                                     LibreOfficeKitCallback pCallback,
                                                     void* pData);
 static char* lo_getFilterTypes(LibreOfficeKit* pThis);
+static void lo_setOptionalFeatures(LibreOfficeKit* pThis, uint64_t features);
 static void                    lo_setDocumentPassword(LibreOfficeKit* pThis,
                                                        const char* pURL,
                                                        const char* pPassword);
@@ -436,6 +437,7 @@ LibLibreOffice_Impl::LibLibreOffice_Impl()
     , maThread(nullptr)
     , mpCallback(nullptr)
     , mpCallbackData(nullptr)
+    , mOptionalFeatures(0)
 {
     if(!m_pOfficeClass) {
         m_pOfficeClass.reset(new LibreOfficeKitClass);
@@ -448,6 +450,7 @@ LibLibreOffice_Impl::LibLibreOffice_Impl()
         m_pOfficeClass->documentLoadWithOptions = lo_documentLoadWithOptions;
         m_pOfficeClass->registerCallback = lo_registerCallback;
         m_pOfficeClass->getFilterTypes = lo_getFilterTypes;
+        m_pOfficeClass->setOptionalFeatures = lo_setOptionalFeatures;
         m_pOfficeClass->setDocumentPassword = lo_setDocumentPassword;
 
         gOfficeClass = m_pOfficeClass;
@@ -1619,6 +1622,12 @@ static char* lo_getFilterTypes(LibreOfficeKit* pThis)
     return strdup(aStream.str().c_str());
 }
 
+static void lo_setOptionalFeatures(LibreOfficeKit* pThis, uint64_t const features)
+{
+    LibLibreOffice_Impl *const pLib = static_cast<LibLibreOffice_Impl*>(pThis);
+    pLib->mOptionalFeatures = features;
+}
+
 static void lo_setDocumentPassword(LibreOfficeKit* pThis,
         const char* pURL, const char* pPassword)
 {
diff --git a/desktop/source/lib/lokinteractionhandler.cxx b/desktop/source/lib/lokinteractionhandler.cxx
index 5f125c3..ea872ea 100644
--- a/desktop/source/lib/lokinteractionhandler.cxx
+++ b/desktop/source/lib/lokinteractionhandler.cxx
@@ -89,16 +89,21 @@ throw (uno::RuntimeException, std::exception)
     task::DocumentPasswordRequest2 passwordRequest;
     if (request >>= passwordRequest)
     {
-        OString const url(passwordRequest.Name.toUtf8());
-        m_pLOKit->mpCallback(passwordRequest.IsRequestPasswordToModify
-                        ? LOK_CALLBACK_DOCUMENT_PASSWORD
-                        : LOK_CALLBACK_DOCUMENT_PASSWORD_TO_MODIFY,
+        if (m_pLOKit->hasOptionalFeature((passwordRequest.IsRequestPasswordToModify)
+                    ? LOK_FEATURE_DOCUMENT_PASSWORD_TO_MODIFY
+                    : LOK_FEATURE_DOCUMENT_PASSWORD))
+        {
+            OString const url(passwordRequest.Name.toUtf8());
+            m_pLOKit->mpCallback(passwordRequest.IsRequestPasswordToModify
+                        ? LOK_CALLBACK_DOCUMENT_PASSWORD_TO_MODIFY
+                        : LOK_CALLBACK_DOCUMENT_PASSWORD,
                     url.getStr(),
                     m_pLOKit->mpCallbackData);
 
-        // block until SetPassword is called
-        m_havePassword.wait();
-        m_havePassword.reset();
+            // block until SetPassword is called
+            m_havePassword.wait();
+            m_havePassword.reset();
+        }
 
         for (sal_Int32 i = 0; i < rContinuations.getLength(); ++i)
         {
diff --git a/include/LibreOfficeKit/LibreOfficeKit.h b/include/LibreOfficeKit/LibreOfficeKit.h
index 5a20ec5..ee9ac1a 100644
--- a/include/LibreOfficeKit/LibreOfficeKit.h
+++ b/include/LibreOfficeKit/LibreOfficeKit.h
@@ -15,6 +15,7 @@
 #if defined LOK_USE_UNSTABLE_API || defined LIBO_INTERNAL_ONLY
 // the unstable API needs C99's bool
 #include <stdbool.h>
+#include <stdint.h>
 #endif
 
 #include <LibreOfficeKit/LibreOfficeKitTypes.h>
@@ -65,6 +66,9 @@ struct _LibreOfficeKitClass
     /// @see lok::Office::getFilterTypes().
     char* (*getFilterTypes) (LibreOfficeKit* pThis);
 
+    /// @see lok::Office::setOptionalFeatures().
+    void (*setOptionalFeatures)(LibreOfficeKit* pThis, uint64_t features);
+
     /// @see lok::Office::setDocumentPassword().
     void (*setDocumentPassword) (LibreOfficeKit* pThis,
             char const* pURL,
diff --git a/include/LibreOfficeKit/LibreOfficeKit.hxx b/include/LibreOfficeKit/LibreOfficeKit.hxx
index 57066c6..3132891 100644
--- a/include/LibreOfficeKit/LibreOfficeKit.hxx
+++ b/include/LibreOfficeKit/LibreOfficeKit.hxx
@@ -462,6 +462,16 @@ public:
     }
 
     /**
+     * Set bitmask of optional features supported by the client.
+     *
+     * @see LibreOfficeKitOptionalFeatures
+     */
+    void setOptionalFeatures(uint64_t features)
+    {
+        return mpThis->pClass->setOptionalFeatures(mpThis, features);
+    }
+
+    /**
      * Set password required for loading or editing a document.
      *
      * Loading the document is blocked until the password is provided.
diff --git a/include/LibreOfficeKit/LibreOfficeKitEnums.h b/include/LibreOfficeKit/LibreOfficeKitEnums.h
index 395b2b7..b615bd9 100644
--- a/include/LibreOfficeKit/LibreOfficeKitEnums.h
+++ b/include/LibreOfficeKit/LibreOfficeKitEnums.h
@@ -40,6 +40,32 @@ typedef enum
 }
 LibreOfficeKitTileMode;
 
+/** Optional features of LibreOfficeKit, in particular callbacks that block
+ *  LibreOfficeKit until the corresponding reply is received, which would
+ *  deadlock if the client does not support the feature.
+ *
+ *  @see lok::Office::setOptionalFeatures().
+ */
+typedef enum
+{
+    /**
+     * Handle LOK_CALLBACK_DOCUMENT_PASSWORD by prompting the user
+     * for a password.
+     *
+     * @see lok::Office::setDocumentPassword().
+     */
+    LOK_FEATURE_DOCUMENT_PASSWORD = (1ULL << 0),
+
+    /**
+     * Handle LOK_CALLBACK_DOCUMENT_PASSWORD_TO_MODIFY by prompting the user
+     * for a password.
+     *
+     * @see lok::Office::setDocumentPassword().
+     */
+    LOK_FEATURE_DOCUMENT_PASSWORD_TO_MODIFY = (1ULL << 1),
+}
+LibreOfficeKitOptionalFeatures;
+
 typedef enum
 {
     /**
diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx
index 2b61e76..bf35646 100644
--- a/libreofficekit/source/gtk/lokdocview.cxx
+++ b/libreofficekit/source/gtk/lokdocview.cxx
@@ -2041,6 +2041,8 @@ static gboolean lok_doc_view_initable_init (GInitable *initable, GCancellable* /
         return FALSE;
     }
 
+//    priv->m_pOffice->pClass->setOptionalFeatures(priv->m_pOffice, LOK_FEATURE_DOCUMENT_PASSWORD|LOK_FEATURE_DOCUMENT_PASSWORD_TO_MODIFY);
+
     return TRUE;
 }
 


More information about the Libreoffice-commits mailing list