summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPranam Lashkari <lpranam@collabora.com>2021-09-15 23:39:32 +0530
committerTor Lillqvist <tml@collabora.com>2021-10-18 15:16:54 +0200
commitbe717e5062f353526e78749b74f3c9888ecfcc5c (patch)
treed97b40438ed0c9471badd967b4bc05f6b382ba0f
parent5393f9bf41f4a35385526205bb51f9b29bf8c20d (diff)
LOK: unify freemium APIs and uno command restriction APIs
Signed-off-by: Pranam Lashkari <lpranam@collabora.com> Change-Id: I3badb038822331ab5cb30df6a66ce9a0640cf340 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/122162 Tested-by: Tor Lillqvist <tml@collabora.com> Reviewed-by: Tor Lillqvist <tml@collabora.com>
-rw-r--r--comphelper/source/misc/lok.cxx64
-rw-r--r--desktop/qa/desktop_lib/test_desktop_lib.cxx10
-rw-r--r--desktop/source/lib/init.cxx43
-rw-r--r--include/LibreOfficeKit/LibreOfficeKit.h22
-rw-r--r--include/LibreOfficeKit/LibreOfficeKit.hxx18
-rw-r--r--include/comphelper/lok.hxx8
-rw-r--r--include/sfx2/lokhelper.hxx6
-rw-r--r--sfx2/source/control/unoctitm.cxx42
-rw-r--r--sfx2/source/view/lokhelper.cxx16
9 files changed, 93 insertions, 136 deletions
diff --git a/comphelper/source/misc/lok.cxx b/comphelper/source/misc/lok.cxx
index 659765f802da..d3b3e9bdec2d 100644
--- a/comphelper/source/misc/lok.cxx
+++ b/comphelper/source/misc/lok.cxx
@@ -35,9 +35,9 @@ static bool g_bLocalRendering(false);
static Compat g_eCompatFlags(Compat::none);
-static std::vector<OUString> g_vFreemiumDenyList;
+static std::unordered_set<OUString> g_vFreemiumDenyList;
-static std::vector<OUString> g_vRestrictedCommandList;
+static std::unordered_set<OUString> g_vRestrictedCommandList;
namespace
{
@@ -289,54 +289,60 @@ void statusIndicatorFinish()
pStatusIndicatorCallback(pStatusIndicatorCallbackData, statusIndicatorCallbackType::Finish, 0, nullptr);
}
-void setFreemiumDenyList(const char* freemiumDenyList)
+void setBlockedCommandList(const char* bolckedCommandList)
{
- if(!g_vFreemiumDenyList.empty())
- return;
- OUString DenyListString(freemiumDenyList, strlen(freemiumDenyList), RTL_TEXTENCODING_UTF8);
+ OUString BolckedListString(bolckedCommandList, strlen(bolckedCommandList), RTL_TEXTENCODING_UTF8);
- OUString command = DenyListString.getToken(0, ' ');
- for (size_t i = 1; !command.isEmpty(); i++)
+ OUString type = BolckedListString.getToken(0, '-');
+
+ if (type == "freemium")
{
- g_vFreemiumDenyList.emplace_back(command);
- command = DenyListString.getToken(i, ' ');
+ if(!g_vFreemiumDenyList.empty())
+ return;
+ OUString commands = BolckedListString.getToken(1, '-');
+
+ OUString command = commands.getToken(0, ' ');
+ for (size_t i = 1; !command.isEmpty(); i++)
+ {
+ g_vFreemiumDenyList.emplace(command);
+ command = commands.getToken(i, ' ');
+ }
+ }
+ else
+ {
+ if(!g_vRestrictedCommandList.empty())
+ return;
+
+ OUString commands = BolckedListString.getToken(1, '-');
+
+ OUString command = commands.getToken(0, ' ');
+ for (size_t i = 1; !command.isEmpty(); i++)
+ {
+ g_vRestrictedCommandList.emplace(command);
+ command = commands.getToken(i, ' ');
+ }
}
}
-const std::vector<OUString>& getFreemiumDenyList()
+const std::unordered_set<OUString>& getFreemiumDenyList()
{
return g_vFreemiumDenyList;
}
bool isCommandFreemiumDenied(const OUString& command)
{
- return std::find(g_vFreemiumDenyList.begin(), g_vFreemiumDenyList.end(), command) != g_vFreemiumDenyList.end();
-}
-
-void setRestrictedCommandList(const char* restrictedCommandList)
-{
- if(!g_vRestrictedCommandList.empty())
- return;
-
- OUString RestrictedListString(restrictedCommandList, strlen(restrictedCommandList), RTL_TEXTENCODING_UTF8);
-
- OUString command = RestrictedListString.getToken(0, ' ');
- for (size_t i = 1; !command.isEmpty(); i++)
- {
- g_vRestrictedCommandList.emplace_back(command);
- command = RestrictedListString.getToken(i, ' ');
- }
+ return g_vFreemiumDenyList.find(command) != g_vFreemiumDenyList.end();
}
-const std::vector<OUString>& getRestrictedCommandList()
+const std::unordered_set<OUString>& getRestrictedCommandList()
{
return g_vRestrictedCommandList;
}
bool isRestrictedCommand(const OUString& command)
{
- return std::find(g_vRestrictedCommandList.begin(), g_vRestrictedCommandList.end(), command) != g_vRestrictedCommandList.end();
+ return g_vRestrictedCommandList.find(command) != g_vRestrictedCommandList.end();
}
} // namespace
diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx
index e66ebb159cb3..ee4d0e8a4b34 100644
--- a/desktop/qa/desktop_lib/test_desktop_lib.cxx
+++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx
@@ -3547,15 +3547,13 @@ 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));
- CPPUNIT_ASSERT_EQUAL(documentClassOffset(64), offsetof(struct _LibreOfficeKitDocumentClass, setRestrictedCommandList));
- CPPUNIT_ASSERT_EQUAL(documentClassOffset(65), offsetof(struct _LibreOfficeKitDocumentClass, setRestrictedView));
- CPPUNIT_ASSERT_EQUAL(documentClassOffset(66), offsetof(struct _LibreOfficeKitDocumentClass, renderSearchResult));
+ CPPUNIT_ASSERT_EQUAL(documentClassOffset(62), offsetof(struct _LibreOfficeKitDocumentClass, setBlockedCommandList));
+ CPPUNIT_ASSERT_EQUAL(documentClassOffset(63), offsetof(struct _LibreOfficeKitDocumentClass, setBlockedCommandView));
+ CPPUNIT_ASSERT_EQUAL(documentClassOffset(64), offsetof(struct _LibreOfficeKitDocumentClass, renderSearchResult));
// Extending is fine, update this, and add new assert for the offsetof the
// new method
- CPPUNIT_ASSERT_EQUAL(documentClassOffset(67), 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 93eaa3e78f42..eb560c56a13e 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -1076,19 +1076,13 @@ static void doc_postKeyEvent(LibreOfficeKitDocument* pThis,
int nType,
int nCharCode,
int nKeyCode);
-static void doc_setFreemiumDenyList(LibreOfficeKitDocument* pThis,
- const char* freemiumDenyList);
+static void doc_setBlockedCommandList(LibreOfficeKitDocument* pThis,
+ const char* bolckedCommandList);
-static void doc_setFreemiumView(LibreOfficeKitDocument* pThis,
+static void doc_setBlockedCommandView(LibreOfficeKitDocument* pThis,
int nViewId,
- bool isFreemium);
-
-static void doc_setRestrictedCommandList(LibreOfficeKitDocument* pThis,
- const char* restrictedCommandList);
-
-static void doc_setRestrictedView(LibreOfficeKitDocument* pThis,
- int nViewId,
- bool isRestricted);
+ const char* type,
+ bool isBlocked);
static void doc_postWindowExtTextInputEvent(LibreOfficeKitDocument* pThis,
unsigned nWindowId,
@@ -1380,11 +1374,8 @@ 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;
-
- m_pDocumentClass->setRestrictedCommandList = doc_setRestrictedCommandList;
- m_pDocumentClass->setRestrictedView = doc_setRestrictedView;
+ m_pDocumentClass->setBlockedCommandList = doc_setBlockedCommandList;
+ m_pDocumentClass->setBlockedCommandView = doc_setBlockedCommandView;
gDocumentClass = m_pDocumentClass;
}
@@ -3690,26 +3681,16 @@ static void doc_postKeyEvent(LibreOfficeKitDocument* pThis, int nType, int nChar
}
}
-static void doc_setFreemiumDenyList(LibreOfficeKitDocument* /*pThis*/, const char* freemiumDenyList)
-{
- comphelper::LibreOfficeKit::setFreemiumDenyList(freemiumDenyList);
-}
-
-static void doc_setFreemiumView(LibreOfficeKitDocument* /*pThis*/, int nViewId, bool isFreemium)
-{
- SolarMutexGuard aGuard;
- SfxLokHelper::setFreemiumView(nViewId, isFreemium);
-}
-
-static void doc_setRestrictedCommandList(LibreOfficeKitDocument* /*pThis*/, const char* restrictedCommandList)
+static void doc_setBlockedCommandList(LibreOfficeKitDocument* /*pThis*/, const char* bolckedCommandList)
{
- comphelper::LibreOfficeKit::setRestrictedCommandList(restrictedCommandList);
+ comphelper::LibreOfficeKit::setBlockedCommandList(bolckedCommandList);
}
-static void doc_setRestrictedView(LibreOfficeKitDocument* /*pThis*/, int nViewId, bool isRestricted)
+static void doc_setBlockedCommandView(LibreOfficeKitDocument* /*pThis*/, int nViewId, const char* type, bool isBlocked)
{
SolarMutexGuard aGuard;
- SfxLokHelper::setRestrictedView(nViewId, isRestricted);
+ OUString aType(type, strlen(type), RTL_TEXTENCODING_UTF8);
+ SfxLokHelper::setBlockedCommandView(nViewId, aType, isBlocked);
}
static void doc_postWindowExtTextInputEvent(LibreOfficeKitDocument* pThis, unsigned nWindowId, int nType, const char* pText)
diff --git a/include/LibreOfficeKit/LibreOfficeKit.h b/include/LibreOfficeKit/LibreOfficeKit.h
index 6a94583b8bf3..72beeb613246 100644
--- a/include/LibreOfficeKit/LibreOfficeKit.h
+++ b/include/LibreOfficeKit/LibreOfficeKit.h
@@ -458,23 +458,15 @@ struct _LibreOfficeKitDocumentClass
void (*sendFormFieldEvent) (LibreOfficeKitDocument* pThis,
const char* pArguments);
- /// @see lok::Document::setFreemiumDenyList
- void (*setFreemiumDenyList) (LibreOfficeKitDocument* pThis,
- const char* freemiumDenyList);
+ /// @see lok::Document::setBlockedCommandList
+ void (*setBlockedCommandList) (LibreOfficeKitDocument* pThis,
+ const char* bolckedCommandList);
- /// @see lok::Document::setFreemiumView
- void (*setFreemiumView) (LibreOfficeKitDocument* pThis,
+ /// @see lok::Document::setBlockedCommandView
+ void (*setBlockedCommandView) (LibreOfficeKitDocument* pThis,
int nViewId,
- bool isFreemium);
-
- /// @see lok::Document::setRestrictedCommandList
- void (*setRestrictedCommandList) (LibreOfficeKitDocument* pThis,
- const char* restrictedCommandList);
-
- /// @see lok::Document::setRestrictedView
- void (*setRestrictedView) (LibreOfficeKitDocument* pThis,
- int nViewId,
- bool isRestricted);
+ const char* type,
+ bool isBlocked);
/// @see lok::Document::renderSearchResult
bool (*renderSearchResult) (LibreOfficeKitDocument* pThis,
diff --git a/include/LibreOfficeKit/LibreOfficeKit.hxx b/include/LibreOfficeKit/LibreOfficeKit.hxx
index 14170ed361a7..506befe74bb8 100644
--- a/include/LibreOfficeKit/LibreOfficeKit.hxx
+++ b/include/LibreOfficeKit/LibreOfficeKit.hxx
@@ -787,24 +787,14 @@ public:
mpDoc->pClass->sendFormFieldEvent(mpDoc, pArguments);
}
- void setFreemiumDenyList(const char* freemiumDenyList)
+ void setBlockedCommandList(const char* bolckedCommandList)
{
- mpDoc->pClass->setFreemiumDenyList(mpDoc, freemiumDenyList);
+ mpDoc->pClass->setBlockedCommandList(mpDoc, bolckedCommandList);
}
- void setFreemiumView(int nViewId, bool isFreemium)
+ void setBlockedCommandView(int nViewId, const char* type, bool isBlocked)
{
- mpDoc->pClass->setFreemiumView(mpDoc, nViewId, isFreemium);
- }
-
- void setRestrictedCommandList(const char* restrictedCommandList)
- {
- mpDoc->pClass->setRestrictedCommandList(mpDoc, restrictedCommandList);
- }
-
- void setRestrictedView(int nViewId, bool isRestricted)
- {
- mpDoc->pClass->setRestrictedView(mpDoc, nViewId, isRestricted);
+ mpDoc->pClass->setBlockedCommandView(mpDoc, nViewId, type, isBlocked);
}
/**
diff --git a/include/comphelper/lok.hxx b/include/comphelper/lok.hxx
index 847c56012565..1ea5b23f017d 100644
--- a/include/comphelper/lok.hxx
+++ b/include/comphelper/lok.hxx
@@ -13,6 +13,7 @@
#include <comphelper/comphelperdllapi.h>
#include <rtl/ustring.hxx>
#include <vector>
+#include <unordered_set>
class LanguageTag;
@@ -110,12 +111,11 @@ 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 void setBlockedCommandList(const char* bolckedCommandList);
+COMPHELPER_DLLPUBLIC const std::unordered_set<OUString>& getFreemiumDenyList();
COMPHELPER_DLLPUBLIC bool isCommandFreemiumDenied(const OUString& command);
-COMPHELPER_DLLPUBLIC void setRestrictedCommandList(const char* restrictedCommandList);
-COMPHELPER_DLLPUBLIC const std::vector<OUString>& getRestrictedCommandList();
+COMPHELPER_DLLPUBLIC const std::unordered_set<OUString>& getRestrictedCommandList();
COMPHELPER_DLLPUBLIC bool isRestrictedCommand(const OUString& command);
}
diff --git a/include/sfx2/lokhelper.hxx b/include/sfx2/lokhelper.hxx
index 76f822a1af5f..13a01c91d347 100644
--- a/include/sfx2/lokhelper.hxx
+++ b/include/sfx2/lokhelper.hxx
@@ -62,10 +62,8 @@ public:
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);
- /// Set View Restricted
- static void setRestrictedView(int nViewId, bool isRestricted);
+ /// Set View Blocked for some uno commands
+ static void setBlockedCommandView(int nViewId, const OUString& type, bool isBlocked);
/// 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/sfx2/source/control/unoctitm.cxx b/sfx2/source/control/unoctitm.cxx
index fe52ed3ff9fb..d9e6b4d10069 100644
--- a/sfx2/source/control/unoctitm.cxx
+++ b/sfx2/source/control/unoctitm.cxx
@@ -49,6 +49,7 @@
#include <vcl/svapp.hxx>
#include <vcl/uitest/logger.hxx>
#include <boost/property_tree/json_parser.hpp>
+#include <tools/json_writer.hxx>
#include <sfx2/app.hxx>
#include <unoctitm.hxx>
@@ -635,6 +636,17 @@ void collectUIInformation(const util::URL& rURL, const css::uno::Sequence< css::
}
}
+void lcl_BlockCommand(const rtl::OUString& command, const rtl::OUString& kind)
+{
+ tools::JsonWriter aTree;
+ aTree.put("code", "");
+ aTree.put("kind", kind);
+ aTree.put("cmd", command);
+ aTree.put("message", "Blocked feature");
+ aTree.put("viewID", SfxViewShell::Current()->GetViewShellId().get());
+
+ SfxViewShell::Current()->libreOfficeKitViewCallback(LOK_CALLBACK_ERROR, aTree.extractData());
+}
void SfxDispatchController_Impl::dispatch( const css::util::URL& aURL,
const css::uno::Sequence< css::beans::PropertyValue >& aArgs,
@@ -646,36 +658,18 @@ void SfxDispatchController_Impl::dispatch( const css::util::URL& aURL,
SolarMutexGuard aGuard;
if (comphelper::LibreOfficeKit::isActive() &&
- SfxViewShell::Current()->isFreemiumView() &&
- comphelper::LibreOfficeKit::isCommandFreemiumDenied(aURL.Complete))
+ SfxViewShell::Current()->isRestrictedView() &&
+ comphelper::LibreOfficeKit::isRestrictedCommand(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());
+ lcl_BlockCommand(aURL.Complete, "restricted");
return;
}
if (comphelper::LibreOfficeKit::isActive() &&
- SfxViewShell::Current()->isRestrictedView() &&
- comphelper::LibreOfficeKit::isRestrictedCommand(aURL.Complete))
+ SfxViewShell::Current()->isFreemiumView() &&
+ comphelper::LibreOfficeKit::isCommandFreemiumDenied(aURL.Complete))
{
- boost::property_tree::ptree aTree;
- aTree.put("code", "");
- aTree.put("kind", "restricted");
- aTree.put("cmd", aURL.Complete);
- aTree.put("message", "Blocked restricted 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());
+ lcl_BlockCommand(aURL.Complete, "freemiumdeny");
return;
}
diff --git a/sfx2/source/view/lokhelper.cxx b/sfx2/source/view/lokhelper.cxx
index 2e9be1d80c2f..1b944a709719 100644
--- a/sfx2/source/view/lokhelper.cxx
+++ b/sfx2/source/view/lokhelper.cxx
@@ -737,21 +737,19 @@ void SfxLokHelper::postKeyEventAsync(const VclPtr<vcl::Window> &xWindow,
postEventAsync(pLOKEv);
}
-void SfxLokHelper::setFreemiumView(int nViewId, bool isFreemium)
+void SfxLokHelper::setBlockedCommandView(int nViewId, const OUString& type, bool isBlocked)
{
SfxViewShell* pViewShell = SfxLokHelper::getViewOfId(nViewId);
if(pViewShell)
- pViewShell->setFreemiumView(isFreemium);
+ {
+ if(type == "freemium")
+ pViewShell->setFreemiumView(isBlocked);
+ else
+ pViewShell->setRestrictedView(isBlocked);
+ }
}
-void SfxLokHelper::setRestrictedView(int nViewId, bool isRestricted)
-{
- SfxViewShell* pViewShell = SfxLokHelper::getViewOfId(nViewId);
-
- if(pViewShell)
- pViewShell->setRestrictedView(isRestricted);
-}
void SfxLokHelper::postExtTextEventAsync(const VclPtr<vcl::Window> &xWindow,
int nType, const OUString &rText)
{