summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPranam Lashkari <lpranam@collabora.com>2021-06-02 19:06:52 +0530
committerPranam Lashkari <lpranam@collabora.com>2021-06-23 17:11:46 +0200
commit1b9fe58acb7b5bbbc83ecca30e17663fff7f0db4 (patch)
tree5f957f515079cae501c2b2f12d08cbd77bd82461
parenttdf#142716 Update selection after any text is inserted. (diff)
downloadcore-1b9fe58acb7b5bbbc83ecca30e17663fff7f0db4.tar.gz
core-1b9fe58acb7b5bbbc83ecca30e17663fff7f0db4.zip
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@gmail.com> Reviewed-by: Pranam Lashkari <lpranam@collabora.com>
-rw-r--r--comphelper/source/misc/lok.cxx28
-rw-r--r--desktop/qa/desktop_lib/test_desktop_lib.cxx4
-rw-r--r--desktop/source/lib/init.cxx18
-rw-r--r--include/LibreOfficeKit/LibreOfficeKit.h6
-rw-r--r--include/LibreOfficeKit/LibreOfficeKit.hxx10
-rw-r--r--include/comphelper/lok.hxx5
-rw-r--r--include/sfx2/lokhelper.hxx5
-rw-r--r--include/sfx2/viewsh.hxx5
-rw-r--r--sfx2/source/control/unoctitm.cxx19
-rw-r--r--sfx2/source/view/lokhelper.cxx25
10 files changed, 123 insertions, 2 deletions
diff --git a/comphelper/source/misc/lok.cxx b/comphelper/source/misc/lok.cxx
index 796a3dc3b839..5c922e84e2b1 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
{
@@ -284,6 +287,31 @@ void statusIndicatorFinish()
pStatusIndicatorCallback(pStatusIndicatorCallbackData, statusIndicatorCallbackType::Finish, 0);
}
+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 74d7668cd2e6..0d18b4c13eb6 100644
--- a/desktop/qa/desktop_lib/test_desktop_lib.cxx
+++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx
@@ -3175,10 +3175,12 @@ void DesktopLOKTest::testABI()
CPPUNIT_ASSERT_EQUAL(documentClassOffset(59), offsetof(struct _LibreOfficeKitDocumentClass, completeFunction));
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, setFreemiumDenyList));
+ CPPUNIT_ASSERT_EQUAL(documentClassOffset(63), offsetof(struct _LibreOfficeKitDocumentClass, setFreemiumView));
// Extending is fine, update this, and add new assert for the offsetof the
// new method
- CPPUNIT_ASSERT_EQUAL(documentClassOffset(62), sizeof(struct _LibreOfficeKitDocumentClass));
+ CPPUNIT_ASSERT_EQUAL(documentClassOffset(64), sizeof(struct _LibreOfficeKitDocumentClass));
}
CPPUNIT_TEST_SUITE_REGISTRATION(DesktopLOKTest);
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index a24fdfaa8a1c..eded3bf4a8ed 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -1042,6 +1042,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,
@@ -1326,6 +1330,9 @@ LibLODocument_Impl::LibLODocument_Impl(const uno::Reference <css::lang::XCompone
m_pDocumentClass->sendFormFieldEvent = doc_sendFormFieldEvent;
+ m_pDocumentClass->setFreemiumDenyList = doc_setFreemiumDenyList;
+ m_pDocumentClass->setFreemiumView = doc_setFreemiumView;
+
gDocumentClass = m_pDocumentClass;
}
pClass = m_pDocumentClass.get();
@@ -3545,6 +3552,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 82738d65ff93..8383aeb9d920 100644
--- a/include/LibreOfficeKit/LibreOfficeKit.h
+++ b/include/LibreOfficeKit/LibreOfficeKit.h
@@ -458,6 +458,12 @@ struct _LibreOfficeKitDocumentClass
void (*sendFormFieldEvent) (LibreOfficeKitDocument* pThis,
const char* pArguments);
+ /// @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 06fe5abc19e2..2756dac9c919 100644
--- a/include/LibreOfficeKit/LibreOfficeKit.hxx
+++ b/include/LibreOfficeKit/LibreOfficeKit.hxx
@@ -787,6 +787,16 @@ public:
mpDoc->pClass->sendFormFieldEvent(mpDoc, pArguments);
}
+ 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 07b8ef6aa426..2d8081da902c 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;
@@ -107,6 +108,10 @@ COMPHELPER_DLLPUBLIC bool isAllowlistedLanguage(const OUString& lang);
COMPHELPER_DLLPUBLIC void statusIndicatorStart();
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 521bf4207458..07baf8a20a3c 100644
--- a/include/sfx2/lokhelper.hxx
+++ b/include/sfx2/lokhelper.hxx
@@ -53,13 +53,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 bf52719f99b5..1fd5a281f561 100644
--- a/include/sfx2/viewsh.hxx
+++ b/include/sfx2/viewsh.hxx
@@ -164,6 +164,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;
@@ -384,6 +385,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 e9019fab2326..f8039ca9d4b7 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>
@@ -617,6 +618,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 53f95e60e737..364490a479ac 100644
--- a/sfx2/source/view/lokhelper.cxx
+++ b/sfx2/source/view/lokhelper.cxx
@@ -178,6 +178,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)
@@ -717,6 +734,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)
{