comphelper/source/misc/lok.cxx | 60 --------------------------- desktop/qa/desktop_lib/test_desktop_lib.cxx | 3 - desktop/source/lib/init.cxx | 17 +------ include/LibreOfficeKit/LibreOfficeKit.h | 7 --- include/LibreOfficeKit/LibreOfficeKit.hxx | 9 ---- include/LibreOfficeKit/LibreOfficeKitEnums.h | 7 +++ include/comphelper/lok.hxx | 7 --- include/sfx2/lokhelper.hxx | 2 include/sfx2/viewsh.hxx | 14 ++---- libreofficekit/source/gtk/lokdocview.cxx | 1 sfx2/source/control/unoctitm.cxx | 31 ++++--------- sfx2/source/view/lokhelper.cxx | 7 --- sfx2/source/view/viewsh.cxx | 23 +++++++++- 13 files changed, 52 insertions(+), 136 deletions(-)
New commits: commit e4e5ced464744fae7682ed9ef2871e51203aca91 Author: Pranam Lashkari <lpra...@collabora.com> AuthorDate: Fri Sep 17 19:13:15 2021 +0530 Commit: Pranam Lashkari <lpra...@collabora.com> CommitDate: Wed Jan 12 05:04:37 2022 +0100 LOK: maintain blocked command list per view Change-Id: I7c621accd84f49447ab3e08a4bb662a9b91b834a Reviewed-on: https://gerrit.libreoffice.org/c/core/+/122253 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Tor Lillqvist <t...@collabora.com> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/128107 diff --git a/comphelper/source/misc/lok.cxx b/comphelper/source/misc/lok.cxx index 28e66723f298..ee1faa4e0658 100644 --- a/comphelper/source/misc/lok.cxx +++ b/comphelper/source/misc/lok.cxx @@ -39,10 +39,6 @@ static bool g_bLocalRendering(false); static Compat g_eCompatFlags(Compat::none); -static std::unordered_set<OUString> g_vFreemiumDenyList; - -static std::unordered_set<OUString> g_vRestrictedCommandList; - namespace { @@ -293,62 +289,6 @@ void statusIndicatorFinish() pStatusIndicatorCallback(pStatusIndicatorCallbackData, statusIndicatorCallbackType::Finish, 0, nullptr); } -void setBlockedCommandList(const char* bolckedCommandList) -{ - - OUString BolckedListString(bolckedCommandList, strlen(bolckedCommandList), RTL_TEXTENCODING_UTF8); - - OUString type = BolckedListString.getToken(0, '-'); - - if (type == "freemium") - { - 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::unordered_set<OUString>& getFreemiumDenyList() -{ - return g_vFreemiumDenyList; -} - -bool isCommandFreemiumDenied(const OUString& command) -{ - return g_vFreemiumDenyList.find(command) != g_vFreemiumDenyList.end(); -} - -const std::unordered_set<OUString>& getRestrictedCommandList() -{ - return g_vRestrictedCommandList; -} - -bool isRestrictedCommand(const OUString& command) -{ - return g_vRestrictedCommandList.find(command) != g_vRestrictedCommandList.end(); -} - } // namespace LibreOfficeKit } // namespace comphelper diff --git a/desktop/qa/desktop_lib/test_desktop_lib.cxx b/desktop/qa/desktop_lib/test_desktop_lib.cxx index f5b0916197a8..ad351343295a 100644 --- a/desktop/qa/desktop_lib/test_desktop_lib.cxx +++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx @@ -3308,11 +3308,10 @@ 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, setBlockedCommandList)); - CPPUNIT_ASSERT_EQUAL(documentClassOffset(63), offsetof(struct _LibreOfficeKitDocumentClass, setBlockedCommandView)); // Extending is fine, update this, and add new assert for the offsetof the // new method - CPPUNIT_ASSERT_EQUAL(documentClassOffset(64), sizeof(struct _LibreOfficeKitDocumentClass)); + CPPUNIT_ASSERT_EQUAL(documentClassOffset(63), sizeof(struct _LibreOfficeKitDocumentClass)); } CPPUNIT_TEST_SUITE_REGISTRATION(DesktopLOKTest); diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx index 2a5831ec0b79..632deac8fd42 100644 --- a/desktop/source/lib/init.cxx +++ b/desktop/source/lib/init.cxx @@ -1085,12 +1085,8 @@ static void doc_postKeyEvent(LibreOfficeKitDocument* pThis, int nCharCode, int nKeyCode); static void doc_setBlockedCommandList(LibreOfficeKitDocument* pThis, - const char* bolckedCommandList); - -static void doc_setBlockedCommandView(LibreOfficeKitDocument* pThis, int nViewId, - const char* type, - bool isBlocked); + const char* bolckedCommandList); static void doc_postWindowExtTextInputEvent(LibreOfficeKitDocument* pThis, unsigned nWindowId, @@ -1376,7 +1372,6 @@ LibLODocument_Impl::LibLODocument_Impl(const uno::Reference <css::lang::XCompone m_pDocumentClass->sendFormFieldEvent = doc_sendFormFieldEvent; m_pDocumentClass->setBlockedCommandList = doc_setBlockedCommandList; - m_pDocumentClass->setBlockedCommandView = doc_setBlockedCommandView; gDocumentClass = m_pDocumentClass; } @@ -3677,16 +3672,10 @@ static void doc_postKeyEvent(LibreOfficeKitDocument* pThis, int nType, int nChar } } -static void doc_setBlockedCommandList(LibreOfficeKitDocument* /*pThis*/, const char* bolckedCommandList) -{ - comphelper::LibreOfficeKit::setBlockedCommandList(bolckedCommandList); -} - -static void doc_setBlockedCommandView(LibreOfficeKitDocument* /*pThis*/, int nViewId, const char* type, bool isBlocked) +static void doc_setBlockedCommandList(LibreOfficeKitDocument* /*pThis*/, int nViewId, const char* bolckedCommandList) { SolarMutexGuard aGuard; - OUString aType(type, strlen(type), RTL_TEXTENCODING_UTF8); - SfxLokHelper::setBlockedCommandView(nViewId, aType, isBlocked); + SfxLokHelper::setBlockedCommandList(nViewId, bolckedCommandList); } 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 f9b9fc8148ba..364ff5cb0669 100644 --- a/include/LibreOfficeKit/LibreOfficeKit.h +++ b/include/LibreOfficeKit/LibreOfficeKit.h @@ -460,14 +460,9 @@ struct _LibreOfficeKitDocumentClass /// @see lok::Document::setBlockedCommandList void (*setBlockedCommandList) (LibreOfficeKitDocument* pThis, + int nViewId, const char* bolckedCommandList); - /// @see lok::Document::setBlockedCommandView - void (*setBlockedCommandView) (LibreOfficeKitDocument* pThis, - int nViewId, - const char* type, - bool isBlocked); - #endif // defined LOK_USE_UNSTABLE_API || defined LIBO_INTERNAL_ONLY }; diff --git a/include/LibreOfficeKit/LibreOfficeKit.hxx b/include/LibreOfficeKit/LibreOfficeKit.hxx index c7011dd2d06e..6ead8a8d80d8 100644 --- a/include/LibreOfficeKit/LibreOfficeKit.hxx +++ b/include/LibreOfficeKit/LibreOfficeKit.hxx @@ -790,14 +790,9 @@ public: mpDoc->pClass->sendFormFieldEvent(mpDoc, pArguments); } - void setBlockedCommandList(const char* bolckedCommandList) + void setBlockedCommandList(int nViewId, const char* bolckedCommandList) { - mpDoc->pClass->setBlockedCommandList(mpDoc, bolckedCommandList); - } - - void setBlockedCommandView(int nViewId, const char* type, bool isBlocked) - { - mpDoc->pClass->setBlockedCommandView(mpDoc, nViewId, type, isBlocked); + mpDoc->pClass->setBlockedCommandList(mpDoc, nViewId, bolckedCommandList); } #endif // defined LOK_USE_UNSTABLE_API || defined LIBO_INTERNAL_ONLY diff --git a/include/LibreOfficeKit/LibreOfficeKitEnums.h b/include/LibreOfficeKit/LibreOfficeKitEnums.h index 90a7f23d82b6..2140c833624d 100644 --- a/include/LibreOfficeKit/LibreOfficeKitEnums.h +++ b/include/LibreOfficeKit/LibreOfficeKitEnums.h @@ -778,6 +778,11 @@ typedef enum * color in the payload as a RGB hex string (RRGGBB). */ LOK_CALLBACK_DOCUMENT_BACKGROUND_COLOR = 52, + + /** + * When a user tries to use command which is restricted for that user + */ + LOK_COMMAND_BLOCKED = 53, } LibreOfficeKitCallbackType; @@ -912,6 +917,8 @@ static inline const char* lokCallbackTypeToString(int nType) return "LOK_CALLBACK_INVALIDATE_SHEET_GEOMETRY"; case LOK_CALLBACK_DOCUMENT_BACKGROUND_COLOR: return "LOK_CALLBACK_DOCUMENT_BACKGROUND_COLOR"; + case LOK_COMMAND_BLOCKED: + return "LOK_COMMAND_BLOCKED"; } assert(!"Unknown LibreOfficeKitCallbackType type."); diff --git a/include/comphelper/lok.hxx b/include/comphelper/lok.hxx index e48126015ff5..257b59f38165 100644 --- a/include/comphelper/lok.hxx +++ b/include/comphelper/lok.hxx @@ -12,8 +12,6 @@ #include <comphelper/comphelperdllapi.h> #include <rtl/ustring.hxx> -#include <vector> -#include <unordered_set> class LanguageTag; @@ -112,11 +110,6 @@ COMPHELPER_DLLPUBLIC void statusIndicatorSetValue(int percent); COMPHELPER_DLLPUBLIC void statusIndicatorFinish(); COMPHELPER_DLLPUBLIC void setBlockedCommandList(const char* bolckedCommandList); -COMPHELPER_DLLPUBLIC const std::unordered_set<OUString>& getFreemiumDenyList(); -COMPHELPER_DLLPUBLIC bool isCommandFreemiumDenied(const OUString& command); - -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 6281bfbdd8be..8d6d8de7ef70 100644 --- a/include/sfx2/lokhelper.hxx +++ b/include/sfx2/lokhelper.hxx @@ -63,7 +63,7 @@ public: /// Get viewIds of views of the current DocId. static bool getViewIds(int nDocId, int* pArray, size_t nSize); /// Set View Blocked for some uno commands - static void setBlockedCommandView(int nViewId, const OUString& type, bool isBlocked); + static void setBlockedCommandList(int nViewId, const char* bolckedCommandList); /// 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 615e798877f9..d5066759e142 100644 --- a/include/sfx2/viewsh.hxx +++ b/include/sfx2/viewsh.hxx @@ -34,6 +34,7 @@ #include <LibreOfficeKit/LibreOfficeKitTypes.h> #include <editeng/outliner.hxx> #include <functional> +#include <unordered_set> class SfxTabPage; class SfxBaseController; @@ -160,8 +161,7 @@ friend class SfxPrinterController; LanguageTag maLOKLanguageTag; LanguageTag maLOKLocale; LOKDeviceFormFactor maLOKDeviceFormFactor; - bool mbLOKIsFreemiumView; - bool mbLOKIsRestrictedView; + std::unordered_set<OUString> mvLOKBlockedCommandList; /// Used to set the DocId at construction time. See SetCurrentDocId. static ViewShellDocId mnCurrentDocId; @@ -388,13 +388,9 @@ public: virtual tools::Rectangle getLOKVisibleArea() const { return tools::Rectangle(); } - // Fremium view settings - void setFreemiumView(bool isFreemium) { mbLOKIsFreemiumView = isFreemium; } - bool isFreemiumView() { return mbLOKIsFreemiumView; } - - // Restricted view setting - void setRestrictedView(bool isRestricted) { mbLOKIsRestrictedView = isRestricted; } - bool isRestrictedView() { return mbLOKIsRestrictedView; } + // Blocked Command view settings + void setBlockedCommandList(const char* bolckedCommandList); + bool isBlockedCommand(OUString command); }; diff --git a/libreofficekit/source/gtk/lokdocview.cxx b/libreofficekit/source/gtk/lokdocview.cxx index 3f61fbb8aad7..91a26dbb79b3 100644 --- a/libreofficekit/source/gtk/lokdocview.cxx +++ b/libreofficekit/source/gtk/lokdocview.cxx @@ -1387,6 +1387,7 @@ callback (gpointer pData) case LOK_CALLBACK_FORM_FIELD_BUTTON: case LOK_CALLBACK_INVALIDATE_SHEET_GEOMETRY: case LOK_CALLBACK_DOCUMENT_BACKGROUND_COLOR: + case LOK_COMMAND_BLOCKED: { // TODO: Implement me break; diff --git a/sfx2/source/control/unoctitm.cxx b/sfx2/source/control/unoctitm.cxx index 49949db6f317..8366e2eef254 100644 --- a/sfx2/source/control/unoctitm.cxx +++ b/sfx2/source/control/unoctitm.cxx @@ -609,17 +609,6 @@ 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, @@ -631,18 +620,16 @@ void SfxDispatchController_Impl::dispatch( const css::util::URL& aURL, SolarMutexGuard aGuard; if (comphelper::LibreOfficeKit::isActive() && - SfxViewShell::Current()->isRestrictedView() && - comphelper::LibreOfficeKit::isRestrictedCommand(aURL.Complete)) - { - lcl_BlockCommand(aURL.Complete, "restricted"); - return; - } - - if (comphelper::LibreOfficeKit::isActive() && - SfxViewShell::Current()->isFreemiumView() && - comphelper::LibreOfficeKit::isCommandFreemiumDenied(aURL.Complete)) + SfxViewShell::Current()->isBlockedCommand(aURL.Complete)) { - lcl_BlockCommand(aURL.Complete, "freemiumdeny"); + tools::JsonWriter aTree; + aTree.put("code", ""); + aTree.put("kind", "BlockedCommand"); + aTree.put("cmd", aURL.Complete); + aTree.put("message", "Blocked feature"); + aTree.put("viewID", SfxViewShell::Current()->GetViewShellId().get()); + + SfxViewShell::Current()->libreOfficeKitViewCallback(LOK_COMMAND_BLOCKED, aTree.extractData()); return; } diff --git a/sfx2/source/view/lokhelper.cxx b/sfx2/source/view/lokhelper.cxx index b478a73c58ad..8eab6c772528 100644 --- a/sfx2/source/view/lokhelper.cxx +++ b/sfx2/source/view/lokhelper.cxx @@ -739,16 +739,13 @@ void SfxLokHelper::postKeyEventAsync(const VclPtr<vcl::Window> &xWindow, postEventAsync(pLOKEv); } -void SfxLokHelper::setBlockedCommandView(int nViewId, const OUString& type, bool isBlocked) +void SfxLokHelper::setBlockedCommandList(int nViewId, const char* bolckedCommandList) { SfxViewShell* pViewShell = SfxLokHelper::getViewOfId(nViewId); if(pViewShell) { - if(type == "freemium") - pViewShell->setFreemiumView(isBlocked); - else - pViewShell->setRestrictedView(isBlocked); + pViewShell->setBlockedCommandList(bolckedCommandList); } } diff --git a/sfx2/source/view/viewsh.cxx b/sfx2/source/view/viewsh.cxx index d22987ed21e8..c59db5582ea9 100644 --- a/sfx2/source/view/viewsh.cxx +++ b/sfx2/source/view/viewsh.cxx @@ -98,7 +98,7 @@ #include <sfx2/lokhelper.hxx> #include <openuriexternally.hxx> #include <shellimpl.hxx> - +#include <iostream> #include <vector> #include <libxml/xmlwriter.h> @@ -1087,8 +1087,6 @@ SfxViewShell::SfxViewShell , maLOKLanguageTag(LANGUAGE_NONE) , maLOKLocale(LANGUAGE_NONE) , maLOKDeviceFormFactor(LOKDeviceFormFactor::UNKNOWN) -, mbLOKIsFreemiumView(false) -, mbLOKIsRestrictedView(false) { SetMargin( pViewFrame->GetMargin_Impl() ); @@ -2102,4 +2100,23 @@ weld::Window* SfxViewShell::GetFrameWeld() const return pWindow ? pWindow->GetFrameWeld() : nullptr; } +void SfxViewShell::setBlockedCommandList(const char* bolckedCommandList) +{ + if(!mvLOKBlockedCommandList.empty()) + return; + + OUString BolckedListString(bolckedCommandList, strlen(bolckedCommandList), RTL_TEXTENCODING_UTF8); + OUString command = BolckedListString.getToken(0, ' '); + for (size_t i = 1; !command.isEmpty(); i++) + { + mvLOKBlockedCommandList.emplace(command); + command = BolckedListString.getToken(i, ' '); + } +} + +bool SfxViewShell::isBlockedCommand(OUString command) +{ + return mvLOKBlockedCommandList.find(command) != mvLOKBlockedCommandList.end(); +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */