diff options
author | Pranam Lashkari <lpranam@collabora.com> | 2022-01-07 15:50:16 +0530 |
---|---|---|
committer | Pranam Lashkari <lpranam@collabora.com> | 2022-01-10 12:58:49 +0100 |
commit | 0a0cc4b5547f2de729474e5119d18c9837eadca2 (patch) | |
tree | ca437ddc5fd16bd098b6b2f59365711361aa5953 | |
parent | faed3047e9fa7e8ed6d33f1801e661a4e56d46c1 (diff) |
LOK: introduce way to restrict uno commands
With this new API we can define which uno commands to restrict their functionality
Change-Id: I9f3fd659d373e56542c5323922a53564f1cfb27b
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/128105
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Tor Lillqvist <tml@collabora.com>
-rw-r--r-- | comphelper/source/misc/lok.cxx | 27 | ||||
-rw-r--r-- | desktop/qa/desktop_lib/test_desktop_lib.cxx | 4 | ||||
-rw-r--r-- | desktop/source/lib/init.cxx | 21 | ||||
-rw-r--r-- | include/LibreOfficeKit/LibreOfficeKit.h | 9 | ||||
-rw-r--r-- | include/LibreOfficeKit/LibreOfficeKit.hxx | 10 | ||||
-rw-r--r-- | include/comphelper/lok.hxx | 4 | ||||
-rw-r--r-- | include/sfx2/lokhelper.hxx | 2 | ||||
-rw-r--r-- | include/sfx2/viewsh.hxx | 5 | ||||
-rw-r--r-- | sfx2/source/control/unoctitm.cxx | 17 | ||||
-rw-r--r-- | sfx2/source/view/lokhelper.cxx | 7 | ||||
-rw-r--r-- | sfx2/source/view/viewsh.cxx | 1 |
11 files changed, 106 insertions, 1 deletions
diff --git a/comphelper/source/misc/lok.cxx b/comphelper/source/misc/lok.cxx index d7b34bccafee..957697302e89 100644 --- a/comphelper/source/misc/lok.cxx +++ b/comphelper/source/misc/lok.cxx @@ -41,6 +41,8 @@ static Compat g_eCompatFlags(Compat::none); static std::vector<OUString> g_vFreemiumDenyList; +static std::vector<OUString> g_vRestrictedCommandList; + namespace { @@ -316,6 +318,31 @@ 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, ' '); + } +} + +const std::vector<OUString>& getRestrictedCommandList() +{ + return g_vRestrictedCommandList; +} + +bool isRestrictedCommand(const OUString& command) +{ + return std::find(g_vRestrictedCommandList.begin(), g_vRestrictedCommandList.end(), 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 9d454752239c..66ff39edd7b3 100644 --- a/desktop/qa/desktop_lib/test_desktop_lib.cxx +++ b/desktop/qa/desktop_lib/test_desktop_lib.cxx @@ -3309,10 +3309,12 @@ void DesktopLOKTest::testABI() 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)); // 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(66), sizeof(struct _LibreOfficeKitDocumentClass)); } CPPUNIT_TEST_SUITE_REGISTRATION(DesktopLOKTest); diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx index 5e82c3d379ff..30ee6bb0f607 100644 --- a/desktop/source/lib/init.cxx +++ b/desktop/source/lib/init.cxx @@ -1088,6 +1088,13 @@ static void doc_setFreemiumDenyList(const char* freemiumDenyList); static void doc_setFreemiumView(int nViewId, bool isFreemium); +static void doc_setRestrictedCommandList(LibreOfficeKitDocument* pThis, + const char* restrictedCommandList); + +static void doc_setRestrictedView(LibreOfficeKitDocument* pThis, + int nViewId, + bool isRestricted); + static void doc_postWindowExtTextInputEvent(LibreOfficeKitDocument* pThis, unsigned nWindowId, int nType, @@ -1374,6 +1381,9 @@ LibLODocument_Impl::LibLODocument_Impl(const uno::Reference <css::lang::XCompone m_pDocumentClass->setFreemiumDenyList = doc_setFreemiumDenyList; m_pDocumentClass->setFreemiumView = doc_setFreemiumView; + m_pDocumentClass->setRestrictedCommandList = doc_setRestrictedCommandList; + m_pDocumentClass->setRestrictedView = doc_setRestrictedView; + gDocumentClass = m_pDocumentClass; } pClass = m_pDocumentClass.get(); @@ -3684,6 +3694,17 @@ static void doc_setFreemiumView(int nViewId, bool isFreemium) SfxLokHelper::setFreemiumView(nViewId, isFreemium); } +static void doc_setRestrictedCommandList(LibreOfficeKitDocument* /*pThis*/, const char* restrictedCommandList) +{ + comphelper::LibreOfficeKit::setRestrictedCommandList(restrictedCommandList); +} + +static void doc_setRestrictedView(LibreOfficeKitDocument* /*pThis*/, int nViewId, bool isRestricted) +{ + SolarMutexGuard aGuard; + SfxLokHelper::setRestrictedView(nViewId, isRestricted); +} + 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 8383aeb9d920..a365ffe05876 100644 --- a/include/LibreOfficeKit/LibreOfficeKit.h +++ b/include/LibreOfficeKit/LibreOfficeKit.h @@ -464,6 +464,15 @@ struct _LibreOfficeKitDocumentClass /// @see lok::Document::setFreemiumView void (*setFreemiumView) (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); + #endif // defined LOK_USE_UNSTABLE_API || defined LIBO_INTERNAL_ONLY }; diff --git a/include/LibreOfficeKit/LibreOfficeKit.hxx b/include/LibreOfficeKit/LibreOfficeKit.hxx index 59143ac98185..b352d5f78055 100644 --- a/include/LibreOfficeKit/LibreOfficeKit.hxx +++ b/include/LibreOfficeKit/LibreOfficeKit.hxx @@ -800,6 +800,16 @@ public: mpDoc->pClass->setFreemiumView(nViewId, isFreemium); } + void setRestrictedCommandList(const char* restrictedCommandList) + { + mpDoc->pClass->setRestrictedCommandList(mpDoc, restrictedCommandList); + } + + void setRestrictedView(int nViewId, bool isRestricted) + { + mpDoc->pClass->setRestrictedView(mpDoc, nViewId, isRestricted); + } + #endif // defined LOK_USE_UNSTABLE_API || defined LIBO_INTERNAL_ONLY }; diff --git a/include/comphelper/lok.hxx b/include/comphelper/lok.hxx index 50e9dfecb9c5..7a7496b68475 100644 --- a/include/comphelper/lok.hxx +++ b/include/comphelper/lok.hxx @@ -113,6 +113,10 @@ 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); + +COMPHELPER_DLLPUBLIC void setRestrictedCommandList(const char* restrictedCommandList); +COMPHELPER_DLLPUBLIC const std::vector<OUString>& getRestrictedCommandList(); +COMPHELPER_DLLPUBLIC bool isRestrictedCommand(const OUString& command); } } diff --git a/include/sfx2/lokhelper.hxx b/include/sfx2/lokhelper.hxx index b552d959c487..e42093840886 100644 --- a/include/sfx2/lokhelper.hxx +++ b/include/sfx2/lokhelper.hxx @@ -64,6 +64,8 @@ public: 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); /// 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 a34e0629185e..615e798877f9 100644 --- a/include/sfx2/viewsh.hxx +++ b/include/sfx2/viewsh.hxx @@ -161,6 +161,7 @@ friend class SfxPrinterController; LanguageTag maLOKLocale; LOKDeviceFormFactor maLOKDeviceFormFactor; bool mbLOKIsFreemiumView; + bool mbLOKIsRestrictedView; /// Used to set the DocId at construction time. See SetCurrentDocId. static ViewShellDocId mnCurrentDocId; @@ -390,6 +391,10 @@ public: // 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; } }; diff --git a/sfx2/source/control/unoctitm.cxx b/sfx2/source/control/unoctitm.cxx index f43ad32ca6ab..cf497b27348a 100644 --- a/sfx2/source/control/unoctitm.cxx +++ b/sfx2/source/control/unoctitm.cxx @@ -635,6 +635,23 @@ void SfxDispatchController_Impl::dispatch( const css::util::URL& aURL, return; } + if (comphelper::LibreOfficeKit::isActive() && + SfxViewShell::Current()->isRestrictedView() && + comphelper::LibreOfficeKit::isRestrictedCommand(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()); + return; + } + if ( !(pDispatch && ( diff --git a/sfx2/source/view/lokhelper.cxx b/sfx2/source/view/lokhelper.cxx index bbfbc58f835f..e36cc0d85a28 100644 --- a/sfx2/source/view/lokhelper.cxx +++ b/sfx2/source/view/lokhelper.cxx @@ -747,6 +747,13 @@ void SfxLokHelper::setFreemiumView(int nViewId, bool isFreemium) pViewShell->setFreemiumView(isFreemium); } +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) { diff --git a/sfx2/source/view/viewsh.cxx b/sfx2/source/view/viewsh.cxx index 2b97061fa8da..d22987ed21e8 100644 --- a/sfx2/source/view/viewsh.cxx +++ b/sfx2/source/view/viewsh.cxx @@ -1088,6 +1088,7 @@ SfxViewShell::SfxViewShell , maLOKLocale(LANGUAGE_NONE) , maLOKDeviceFormFactor(LOKDeviceFormFactor::UNKNOWN) , mbLOKIsFreemiumView(false) +, mbLOKIsRestrictedView(false) { SetMargin( pViewFrame->GetMargin_Impl() ); |