diff options
author | Pranam Lashkari <lpranam@collabora.com> | 2021-09-17 19:13:15 +0530 |
---|---|---|
committer | Tor Lillqvist <tml@collabora.com> | 2021-10-18 15:30:37 +0200 |
commit | 7fee2a542eca7e346c9dd79fdf02cf0ef8febe8c (patch) | |
tree | aad83286a7576dd100d1ae961fc2e19384ddfba6 | |
parent | be717e5062f353526e78749b74f3c9888ecfcc5c (diff) |
LOK: maintain blocked command list per view
Change-Id: I7c621accd84f49447ab3e08a4bb662a9b91b834a
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/122253
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Tor Lillqvist <tml@collabora.com>
-rw-r--r-- | comphelper/source/misc/lok.cxx | 60 | ||||
-rw-r--r-- | desktop/qa/desktop_lib/test_desktop_lib.cxx | 5 | ||||
-rw-r--r-- | desktop/source/lib/init.cxx | 17 | ||||
-rw-r--r-- | include/LibreOfficeKit/LibreOfficeKit.h | 7 | ||||
-rw-r--r-- | include/LibreOfficeKit/LibreOfficeKit.hxx | 9 | ||||
-rw-r--r-- | include/LibreOfficeKit/LibreOfficeKitEnums.h | 7 | ||||
-rw-r--r-- | include/comphelper/lok.hxx | 7 | ||||
-rw-r--r-- | include/sfx2/lokhelper.hxx | 2 | ||||
-rw-r--r-- | include/sfx2/viewsh.hxx | 14 | ||||
-rw-r--r-- | libreofficekit/source/gtk/lokdocview.cxx | 1 | ||||
-rw-r--r-- | sfx2/source/control/unoctitm.cxx | 31 | ||||
-rw-r--r-- | sfx2/source/view/lokhelper.cxx | 7 | ||||
-rw-r--r-- | sfx2/source/view/viewsh.cxx | 23 |
13 files changed, 53 insertions, 137 deletions
diff --git a/comphelper/source/misc/lok.cxx b/comphelper/source/misc/lok.cxx index d3b3e9bdec2d..8765c8eb2847 100644 --- a/comphelper/source/misc/lok.cxx +++ b/comphelper/source/misc/lok.cxx @@ -35,10 +35,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 { @@ -289,62 +285,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 /* 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 ee4d0e8a4b34..495293b76246 100644 --- a/desktop/qa/desktop_lib/test_desktop_lib.cxx +++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx @@ -3548,12 +3548,11 @@ 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)); - CPPUNIT_ASSERT_EQUAL(documentClassOffset(64), offsetof(struct _LibreOfficeKitDocumentClass, renderSearchResult)); + CPPUNIT_ASSERT_EQUAL(documentClassOffset(63), offsetof(struct _LibreOfficeKitDocumentClass, renderSearchResult)); // Extending is fine, update this, and add new assert for the offsetof the // new method - CPPUNIT_ASSERT_EQUAL(documentClassOffset(65), 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 eb560c56a13e..9216b12b213c 100644 --- a/desktop/source/lib/init.cxx +++ b/desktop/source/lib/init.cxx @@ -1077,12 +1077,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, @@ -1375,7 +1371,6 @@ LibLODocument_Impl::LibLODocument_Impl(const uno::Reference <css::lang::XCompone m_pDocumentClass->renderSearchResult = doc_renderSearchResult; m_pDocumentClass->setBlockedCommandList = doc_setBlockedCommandList; - m_pDocumentClass->setBlockedCommandView = doc_setBlockedCommandView; gDocumentClass = m_pDocumentClass; } @@ -3681,16 +3676,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 72beeb613246..29ffeff44bbb 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); - /// @see lok::Document::renderSearchResult bool (*renderSearchResult) (LibreOfficeKitDocument* pThis, const char* pSearchResult, diff --git a/include/LibreOfficeKit/LibreOfficeKit.hxx b/include/LibreOfficeKit/LibreOfficeKit.hxx index 506befe74bb8..2a4a8fd72661 100644 --- a/include/LibreOfficeKit/LibreOfficeKit.hxx +++ b/include/LibreOfficeKit/LibreOfficeKit.hxx @@ -787,14 +787,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); } /** diff --git a/include/LibreOfficeKit/LibreOfficeKitEnums.h b/include/LibreOfficeKit/LibreOfficeKitEnums.h index c9d694ca8b4d..e00968a86dc8 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 1ea5b23f017d..54d461dc8cbc 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); } #endif // INCLUDED_COMPHELPER_LOK_HXX diff --git a/include/sfx2/lokhelper.hxx b/include/sfx2/lokhelper.hxx index 13a01c91d347..060e0b152722 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 72091daa2153..84b648d57986 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; @@ -165,8 +166,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; @@ -393,13 +393,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 9102672e12ec..1d40ebc2db90 100644 --- a/libreofficekit/source/gtk/lokdocview.cxx +++ b/libreofficekit/source/gtk/lokdocview.cxx @@ -1415,6 +1415,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 d9e6b4d10069..7bc371cc78d3 100644 --- a/sfx2/source/control/unoctitm.cxx +++ b/sfx2/source/control/unoctitm.cxx @@ -636,17 +636,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, @@ -658,18 +647,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 1b944a709719..a841956cc1a6 100644 --- a/sfx2/source/view/lokhelper.cxx +++ b/sfx2/source/view/lokhelper.cxx @@ -737,16 +737,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 98ebe7bde3cf..3fe5c5e86542 100644 --- a/sfx2/source/view/viewsh.cxx +++ b/sfx2/source/view/viewsh.cxx @@ -87,7 +87,7 @@ #include <sfx2/lokcallback.hxx> #include <openuriexternally.hxx> #include <shellimpl.hxx> - +#include <iostream> #include <vector> #include <libxml/xmlwriter.h> @@ -1077,8 +1077,6 @@ SfxViewShell::SfxViewShell , maLOKLanguageTag(LANGUAGE_NONE) , maLOKLocale(LANGUAGE_NONE) , maLOKDeviceFormFactor(LOKDeviceFormFactor::UNKNOWN) -, mbLOKIsFreemiumView(false) -, mbLOKIsRestrictedView(false) { SetMargin( pViewFrame->GetMargin_Impl() ); @@ -2084,4 +2082,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: */ |