[Libreoffice-commits] core.git: comphelper/source desktop/qa desktop/source include/comphelper include/LibreOfficeKit include/sfx2 sfx2/source

Pranam Lashkari (via logerrit) logerrit at kemper.freedesktop.org
Mon Aug 16 07:02:09 UTC 2021


 comphelper/source/misc/lok.cxx              |   28 ++++++++++++++++++++++++++++
 desktop/qa/desktop_lib/test_desktop_lib.cxx |    4 +++-
 desktop/source/lib/init.cxx                 |   18 ++++++++++++++++++
 include/LibreOfficeKit/LibreOfficeKit.h     |    5 +++++
 include/LibreOfficeKit/LibreOfficeKit.hxx   |    9 +++++++++
 include/comphelper/lok.hxx                  |    5 +++++
 include/sfx2/lokhelper.hxx                  |    5 ++++-
 include/sfx2/viewsh.hxx                     |    5 +++++
 sfx2/source/control/unoctitm.cxx            |   19 +++++++++++++++++++
 sfx2/source/view/lokhelper.cxx              |   25 +++++++++++++++++++++++++
 10 files changed, 121 insertions(+), 2 deletions(-)

New commits:
commit 513120d24c770079773559367202d54ff62b39b4
Author:     Pranam Lashkari <lpranam at collabora.com>
AuthorDate: Wed Jun 2 19:06:52 2021 +0530
Commit:     Pranam Lashkari <lpranam at collabora.com>
CommitDate: Mon Aug 16 09:01:11 2021 +0200

    LOK: introduced Freemium LOK API
    
    also block the uno commands from deny list
    
    Change-Id: Iee994411891b73b865e6496403682f996d5e9321
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/116384
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>
    Reviewed-by: Pranam Lashkari <lpranam at collabora.com>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/120482
    Tested-by: Jenkins

diff --git a/comphelper/source/misc/lok.cxx b/comphelper/source/misc/lok.cxx
index b11bf4e83582..c7c57cb61e27 100644
--- a/comphelper/source/misc/lok.cxx
+++ b/comphelper/source/misc/lok.cxx
@@ -10,6 +10,7 @@
 #include <comphelper/lok.hxx>
 #include <i18nlangtag/languagetag.hxx>
 #include <sal/log.hxx>
+#include <algorithm>
 
 #include <iostream>
 
@@ -34,6 +35,8 @@ static bool g_bLocalRendering(false);
 
 static Compat g_eCompatFlags(Compat::none);
 
+static std::vector<OUString> g_vFreemiumDenyList;
+
 namespace
 {
 
@@ -282,6 +285,31 @@ void statusIndicatorFinish()
         pStatusIndicatorCallback(pStatusIndicatorCallbackData, statusIndicatorCallbackType::Finish, 0, nullptr);
 }
 
+void setFreemiumDenyList(const char* freemiumDenyList)
+{
+    if(!g_vFreemiumDenyList.empty())
+        return;
+
+    OUString DenyListString(freemiumDenyList, strlen(freemiumDenyList), RTL_TEXTENCODING_UTF8);
+
+    OUString command = DenyListString.getToken(0, ' ');
+    for (size_t i = 1; !command.isEmpty(); i++)
+    {
+        g_vFreemiumDenyList.emplace_back(command);
+        command = DenyListString.getToken(i, ' ');
+    }
+}
+
+const std::vector<OUString>& getFreemiumDenyList()
+{
+    return g_vFreemiumDenyList;
+}
+
+bool isCommandFreemiumDenied(const OUString& command)
+{
+    return std::find(g_vFreemiumDenyList.begin(), g_vFreemiumDenyList.end(), command) != g_vFreemiumDenyList.end();
+}
+
 } // namespace
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx
index dc8b4caf1de4..7752a2c2d24c 100644
--- a/desktop/qa/desktop_lib/test_desktop_lib.cxx
+++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx
@@ -3250,10 +3250,12 @@ void DesktopLOKTest::testABI()
     CPPUNIT_ASSERT_EQUAL(documentClassOffset(60), offsetof(struct _LibreOfficeKitDocumentClass, setWindowTextSelection));
     CPPUNIT_ASSERT_EQUAL(documentClassOffset(61), offsetof(struct _LibreOfficeKitDocumentClass, sendFormFieldEvent));
     CPPUNIT_ASSERT_EQUAL(documentClassOffset(62), offsetof(struct _LibreOfficeKitDocumentClass, renderSearchResult));
+    CPPUNIT_ASSERT_EQUAL(documentClassOffset(63), offsetof(struct _LibreOfficeKitDocumentClass, setFreemiumDenyList));
+    CPPUNIT_ASSERT_EQUAL(documentClassOffset(64), offsetof(struct _LibreOfficeKitDocumentClass, setFreemiumView));
 
     // Extending is fine, update this, and add new assert for the offsetof the
     // new method
-    CPPUNIT_ASSERT_EQUAL(documentClassOffset(63), sizeof(struct _LibreOfficeKitDocumentClass));
+    CPPUNIT_ASSERT_EQUAL(documentClassOffset(65), sizeof(struct _LibreOfficeKitDocumentClass));
 }
 
 CPPUNIT_TEST_SUITE_REGISTRATION(DesktopLOKTest);
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index be1682047ab9..0eecb2b4b352 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -1043,6 +1043,10 @@ static void doc_postKeyEvent(LibreOfficeKitDocument* pThis,
                              int nType,
                              int nCharCode,
                              int nKeyCode);
+static void doc_setFreemiumDenyList(const char* freemiumDenyList);
+
+static void doc_setFreemiumView(int nViewId, bool isFreemium);
+
 static void doc_postWindowExtTextInputEvent(LibreOfficeKitDocument* pThis,
                                             unsigned nWindowId,
                                             int nType,
@@ -1333,6 +1337,9 @@ LibLODocument_Impl::LibLODocument_Impl(const uno::Reference <css::lang::XCompone
         m_pDocumentClass->sendFormFieldEvent = doc_sendFormFieldEvent;
         m_pDocumentClass->renderSearchResult = doc_renderSearchResult;
 
+        m_pDocumentClass->setFreemiumDenyList = doc_setFreemiumDenyList;
+        m_pDocumentClass->setFreemiumView = doc_setFreemiumView;
+
         gDocumentClass = m_pDocumentClass;
     }
     pClass = m_pDocumentClass.get();
@@ -3550,6 +3557,17 @@ static void doc_postKeyEvent(LibreOfficeKitDocument* pThis, int nType, int nChar
     }
 }
 
+static void doc_setFreemiumDenyList(const char* freemiumDenyList)
+{
+    comphelper::LibreOfficeKit::setFreemiumDenyList(freemiumDenyList);
+}
+
+static void doc_setFreemiumView(int nViewId, bool isFreemium)
+{
+    SolarMutexGuard aGuard;
+    SfxLokHelper::setFreemiumView(nViewId, isFreemium);
+}
+
 static void doc_postWindowExtTextInputEvent(LibreOfficeKitDocument* pThis, unsigned nWindowId, int nType, const char* pText)
 {
     comphelper::ProfileZone aZone("doc_postWindowExtTextInputEvent");
diff --git a/include/LibreOfficeKit/LibreOfficeKit.h b/include/LibreOfficeKit/LibreOfficeKit.h
index 8c9e0012552e..527fee4f2e7d 100644
--- a/include/LibreOfficeKit/LibreOfficeKit.h
+++ b/include/LibreOfficeKit/LibreOfficeKit.h
@@ -463,6 +463,11 @@ struct _LibreOfficeKitDocumentClass
                                 const char* pSearchResult,
                                 unsigned char** pBitmapBuffer,
                                 int* pWidth, int* pHeight, size_t* pByteSize);
+    /// @see lok::Document::setFreemiumDenyList
+    void (*setFreemiumDenyList) (const char* freemiumDenyList);
+
+    /// @see lok::Document::setFreemiumView
+    void (*setFreemiumView) (int nViewId, bool isFreemium);
 
 #endif // defined LOK_USE_UNSTABLE_API || defined LIBO_INTERNAL_ONLY
 };
diff --git a/include/LibreOfficeKit/LibreOfficeKit.hxx b/include/LibreOfficeKit/LibreOfficeKit.hxx
index b1d579849cbd..cd35cdc51fe6 100644
--- a/include/LibreOfficeKit/LibreOfficeKit.hxx
+++ b/include/LibreOfficeKit/LibreOfficeKit.hxx
@@ -802,6 +802,15 @@ public:
     {
         return mpDoc->pClass->renderSearchResult(mpDoc, pSearchResult, pBitmapBuffer, pWidth, pHeight, pByteSize);
     }
+    void setFreemiumDenyList(const char* freemiumDenyList)
+    {
+        mpDoc->pClass->setFreemiumDenyList(freemiumDenyList);
+    }
+
+    void setFreemiumView(int nViewId, bool isFreemium)
+    {
+        mpDoc->pClass->setFreemiumView(nViewId, isFreemium);
+    }
 
 #endif // defined LOK_USE_UNSTABLE_API || defined LIBO_INTERNAL_ONLY
 };
diff --git a/include/comphelper/lok.hxx b/include/comphelper/lok.hxx
index 99f3dd30dfce..d68fabb2e600 100644
--- a/include/comphelper/lok.hxx
+++ b/include/comphelper/lok.hxx
@@ -12,6 +12,7 @@
 
 #include <comphelper/comphelperdllapi.h>
 #include <rtl/ustring.hxx>
+#include <vector>
 
 class LanguageTag;
 
@@ -108,6 +109,10 @@ COMPHELPER_DLLPUBLIC bool isAllowlistedLanguage(const OUString& lang);
 COMPHELPER_DLLPUBLIC void statusIndicatorStart(const OUString& sText);
 COMPHELPER_DLLPUBLIC void statusIndicatorSetValue(int percent);
 COMPHELPER_DLLPUBLIC void statusIndicatorFinish();
+
+COMPHELPER_DLLPUBLIC void setFreemiumDenyList(const char* freemiumDenyList);
+COMPHELPER_DLLPUBLIC const std::vector<OUString>& getFreemiumDenyList();
+COMPHELPER_DLLPUBLIC bool isCommandFreemiumDenied(const OUString& command);
 }
 
 #endif // INCLUDED_COMPHELPER_LOK_HXX
diff --git a/include/sfx2/lokhelper.hxx b/include/sfx2/lokhelper.hxx
index a806f022fa19..ce5c9f4a63e3 100644
--- a/include/sfx2/lokhelper.hxx
+++ b/include/sfx2/lokhelper.hxx
@@ -55,13 +55,16 @@ public:
     static void destroyView(int nId);
     /// Set a view shell as current one.
     static void setView(int nId);
+    /// Get view shell with id
+    static SfxViewShell* getViewOfId(int nId);
     /// Get the currently active view.
     static int getView(const SfxViewShell* pViewShell = nullptr);
     /// Get the number of views of the current DocId.
     static std::size_t getViewsCount(int nDocId);
     /// Get viewIds of views of the current DocId.
     static bool getViewIds(int nDocId, int* pArray, size_t nSize);
-
+    /// Set View Freemium
+    static void setFreemiumView(int nViewId, bool isFreemium);
     /// Get the document id for a view
     static int getDocumentIdOfView(int nViewId);
     /// Get the default language that should be used for views
diff --git a/include/sfx2/viewsh.hxx b/include/sfx2/viewsh.hxx
index cc93f249bbd6..c1d9457419e6 100644
--- a/include/sfx2/viewsh.hxx
+++ b/include/sfx2/viewsh.hxx
@@ -165,6 +165,7 @@ friend class SfxPrinterController;
     LanguageTag                 maLOKLanguageTag;
     LanguageTag                 maLOKLocale;
     LOKDeviceFormFactor         maLOKDeviceFormFactor;
+    bool                        mbLOKIsFreemiumView;
 
     /// Used to set the DocId at construction time. See SetCurrentDocId.
     static ViewShellDocId       mnCurrentDocId;
@@ -385,6 +386,10 @@ public:
     bool isLOKMobilePhone() const { return maLOKDeviceFormFactor == LOKDeviceFormFactor::MOBILE; }
 
     virtual tools::Rectangle getLOKVisibleArea() const { return tools::Rectangle(); }
+
+    // Fremium view settings
+    void setFreemiumView(bool isFreemium) { mbLOKIsFreemiumView = isFreemium; }
+    bool isFreemiumView() { return mbLOKIsFreemiumView; }
 };
 
 
diff --git a/sfx2/source/control/unoctitm.cxx b/sfx2/source/control/unoctitm.cxx
index 3d3bfd430c4f..4395f19cd3da 100644
--- a/sfx2/source/control/unoctitm.cxx
+++ b/sfx2/source/control/unoctitm.cxx
@@ -68,6 +68,7 @@
 #include <unotools/pathoptions.hxx>
 #include <osl/time.h>
 #include <sfx2/lokhelper.hxx>
+#include <basic/sberrors.hxx>
 
 #include <map>
 #include <memory>
@@ -526,6 +527,24 @@ void SfxDispatchController_Impl::dispatch( const css::util::URL& aURL,
     collectUIInformation(aURL, aArgs);
 
     SolarMutexGuard aGuard;
+
+    if (comphelper::LibreOfficeKit::isActive() &&
+        SfxViewShell::Current()->isFreemiumView() &&
+        comphelper::LibreOfficeKit::isCommandFreemiumDenied(aURL.Complete))
+    {
+        boost::property_tree::ptree aTree;
+        aTree.put("code", "");
+        aTree.put("kind", "freemiumdeny");
+        aTree.put("cmd", aURL.Complete);
+        aTree.put("message", "Blocked Freemium feature");
+        aTree.put("viewID", SfxViewShell::Current()->GetViewShellId().get());
+
+        std::stringstream aStream;
+        boost::property_tree::write_json(aStream, aTree);
+        SfxViewShell::Current()->libreOfficeKitViewCallback(LOK_CALLBACK_ERROR, aStream.str().c_str());
+        return;
+    }
+
     if (
         !(pDispatch &&
         (
diff --git a/sfx2/source/view/lokhelper.cxx b/sfx2/source/view/lokhelper.cxx
index 2f68b37e3bd9..97bef9e48472 100644
--- a/sfx2/source/view/lokhelper.cxx
+++ b/sfx2/source/view/lokhelper.cxx
@@ -182,6 +182,23 @@ void SfxLokHelper::setView(int nId)
 
 }
 
+SfxViewShell* SfxLokHelper::getViewOfId(int nId)
+{
+    SfxApplication* pApp = SfxApplication::Get();
+    if (pApp == nullptr)
+        return nullptr;
+
+    const ViewShellId nViewShellId(nId);
+    SfxViewShellArr_Impl& rViewArr = pApp->GetViewShells_Impl();
+    for (SfxViewShell* pViewShell : rViewArr)
+    {
+        if (pViewShell->GetViewShellId() == nViewShellId)
+            return pViewShell;
+    }
+
+    return nullptr;
+}
+
 int SfxLokHelper::getView(const SfxViewShell* pViewShell)
 {
     if (!pViewShell)
@@ -723,6 +740,14 @@ void SfxLokHelper::postKeyEventAsync(const VclPtr<vcl::Window> &xWindow,
     postEventAsync(pLOKEv);
 }
 
+void SfxLokHelper::setFreemiumView(int nViewId, bool isFreemium)
+{
+    SfxViewShell* pViewShell = SfxLokHelper::getViewOfId(nViewId);
+
+    if(pViewShell)
+        pViewShell->setFreemiumView(isFreemium);
+}
+
 void SfxLokHelper::postExtTextEventAsync(const VclPtr<vcl::Window> &xWindow,
                                          int nType, const OUString &rText)
 {


More information about the Libreoffice-commits mailing list