diff options
author | Michael Stahl <mstahl@redhat.com> | 2016-01-26 15:35:42 +0100 |
---|---|---|
committer | Jan Holesovsky <kendy@collabora.com> | 2016-01-27 08:26:19 +0000 |
commit | 23a0ee3c01c3588472e1c19605909d6b9401253c (patch) | |
tree | bd455470684500e310c1801fdde6fe2f528f93f9 | |
parent | f8151c9ced1a2fdce6273fbbce2656bea25cf754 (diff) |
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@collabora.com>
Tested-by: Jan Holesovsky <kendy@collabora.com>
-rw-r--r-- | desktop/inc/lib/init.hxx | 7 | ||||
-rw-r--r-- | desktop/source/lib/init.cxx | 9 | ||||
-rw-r--r-- | desktop/source/lib/lokinteractionhandler.cxx | 19 | ||||
-rw-r--r-- | include/LibreOfficeKit/LibreOfficeKit.h | 4 | ||||
-rw-r--r-- | include/LibreOfficeKit/LibreOfficeKit.hxx | 10 | ||||
-rw-r--r-- | include/LibreOfficeKit/LibreOfficeKitEnums.h | 26 | ||||
-rw-r--r-- | libreofficekit/source/gtk/lokdocview.cxx | 2 |
7 files changed, 70 insertions, 7 deletions
diff --git a/desktop/inc/lib/init.hxx b/desktop/inc/lib/init.hxx index ee598a0c07b0..d07729731b39 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 88b5d1fc70b4..eecb16adb75f 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 5f125c3a40c1..ea872ead048b 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 5a20ec5e47a1..ee9ac1aca646 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 57066c69c18c..31328914e239 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 395b2b761891..b615bd94f9d1 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 2b61e76d6136..bf35646bf5ea 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; } |