From 1b9fe58acb7b5bbbc83ecca30e17663fff7f0db4 Mon Sep 17 00:00:00 2001 From: Pranam Lashkari Date: Wed, 2 Jun 2021 19:06:52 +0530 Subject: 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 Reviewed-by: Pranam Lashkari --- sfx2/source/control/unoctitm.cxx | 19 +++++++++++++++++++ sfx2/source/view/lokhelper.cxx | 25 +++++++++++++++++++++++++ 2 files changed, 44 insertions(+) (limited to 'sfx2') 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 #include #include +#include #include #include @@ -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 &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 &xWindow, int nType, const OUString &rText) { -- cgit