From 2168617d603a81eab62465a9b18d6f64b35e66da Mon Sep 17 00:00:00 2001 From: Pranav Kant Date: Thu, 10 Nov 2016 17:51:39 +0530 Subject: [PATCH] tdf#103641: Implement ability to hide save, print, export options Add more WOPI extensions for this - HidePrintOption, HideSaveOption, HideExportOption. Setting HideExportOption to 'true' in WOPI CheckFileInfo response would hide the 'Download as' option from the File menu. Change-Id: Ia2259ee9525cc6c4331a52e2221af4df188eab07 --- loleaflet/dist/toolbar/toolbar.js | 4 ++++ loleaflet/src/control/Control.Menubar.js | 12 ++++++++++++ loleaflet/src/core/Socket.js | 4 ++++ loleaflet/src/map/handler/Map.WOPI.js | 3 +++ loolwsd/DocumentBroker.cpp | 16 ++++++++++------ loolwsd/Storage.cpp | 11 ++++++++++- loolwsd/Storage.hpp | 12 ++++++++++++ 7 files changed, 55 insertions(+), 7 deletions(-) diff --git a/loleaflet/dist/toolbar/toolbar.js b/loleaflet/dist/toolbar/toolbar.js index 90027f51b..4cbb63e86 100644 --- a/loleaflet/dist/toolbar/toolbar.js +++ b/loleaflet/dist/toolbar/toolbar.js @@ -751,6 +751,10 @@ map.on('doclayerinit', function () { } } + if (map['wopi'].HideSaveOption) { + toolbar.hide('save'); + } + var statusbar = w2ui['toolbar-down']; switch (docType) { case 'spreadsheet': diff --git a/loleaflet/src/control/Control.Menubar.js b/loleaflet/src/control/Control.Menubar.js index 7eadface3..1854bd226 100644 --- a/loleaflet/src/control/Control.Menubar.js +++ b/loleaflet/src/control/Control.Menubar.js @@ -463,6 +463,15 @@ L.Control.Menubar = L.Control.extend({ continue; } + if (menu[i].id === 'print' && this._map['wopi'].HidePrintOption) + continue; + + if (menu[i].id === 'save' && this._map['wopi'].HideSaveOption) + continue; + + if (menu[i].id === 'downloadas' && this._map['wopi'].HideExportOption) + continue; + var liItem = L.DomUtil.create('li', ''); var aItem = L.DomUtil.create('a', '', liItem); aItem.innerHTML = menu[i].name; @@ -470,6 +479,9 @@ L.Control.Menubar = L.Control.extend({ if (menu[i].type === 'menu') { var ulItem = L.DomUtil.create('ul', '', liItem); var subitemList = this._createMenu(menu[i].menu); + if (!subitemList.length) { + continue; + } for (var j in subitemList) { ulItem.appendChild(subitemList[j]); } diff --git a/loleaflet/src/core/Socket.js b/loleaflet/src/core/Socket.js index 77d643bf1..d504ba6cb 100644 --- a/loleaflet/src/core/Socket.js +++ b/loleaflet/src/core/Socket.js @@ -188,6 +188,10 @@ L.Socket = L.Class.extend({ this._map.fire('postMessage', {msgId: 'App_LoadingStatus', args: {'DocumentLoadedTime': this._map['wopi'].DocumentLoadedTime}}); } + this._map['wopi'].HidePrintOption = !!wopiInfo['HidePrintOption']; + this._map['wopi'].HideSaveOption = !!wopiInfo['HideSaveOption']; + this._map['wopi'].HideExportOption = !!wopiInfo['HideExportOption']; + return; } else if (textMsg.startsWith('close: ')) { diff --git a/loleaflet/src/map/handler/Map.WOPI.js b/loleaflet/src/map/handler/Map.WOPI.js index 8bac0503f..a8f061e1b 100644 --- a/loleaflet/src/map/handler/Map.WOPI.js +++ b/loleaflet/src/map/handler/Map.WOPI.js @@ -6,6 +6,9 @@ L.Map.WOPI = L.Handler.extend({ PostMessageOrigin: false, DocumentLoadedTime: false, + HidePrintOption: false, + HideSaveOption: false, + HideExportOption: false, initialize: function(map) { this._map = map; diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp index 179b2e5c5..4a79836e7 100644 --- a/loolwsd/DocumentBroker.cpp +++ b/loolwsd/DocumentBroker.cpp @@ -239,17 +239,21 @@ bool DocumentBroker::load(std::shared_ptr& session, const std::st session->setReadOnly(); } + // Construct a JSON containing relevant WOPI host properties + Object::Ptr wopiInfo = new Object(); if (!wopifileinfo._postMessageOrigin.empty()) { - // Construct a JSON containing relevant WOPI host properties - Object::Ptr wopiInfo = new Object(); wopiInfo->set("PostMessageOrigin", wopifileinfo._postMessageOrigin); - std::ostringstream ossWopiInfo; - wopiInfo->stringify(ossWopiInfo); - - session->sendTextFrame("wopi: " + ossWopiInfo.str()); } + wopiInfo->set("HidePrintOption", wopifileinfo._hidePrintOption); + wopiInfo->set("HideSaveOption", wopifileinfo._hideSaveOption); + wopiInfo->set("HideExportOption", wopifileinfo._hideExportOption); + + std::ostringstream ossWopiInfo; + wopiInfo->stringify(ossWopiInfo); + session->sendTextFrame("wopi: " + ossWopiInfo.str()); + // Mark the session as 'Document owner' if WOPI hosts supports it if (wopifileinfo._enableOwnerTermination && userid == _storage->getFileInfo()._ownerId) { diff --git a/loolwsd/Storage.cpp b/loolwsd/Storage.cpp index 0a451ae3e..dcaa0a7ea 100644 --- a/loolwsd/Storage.cpp +++ b/loolwsd/Storage.cpp @@ -320,6 +320,9 @@ WopiStorage::WOPIFileInfo WopiStorage::getWOPIFileInfo(const Poco::URI& uriPubli bool canWrite = false; bool enableOwnerTermination = false; std::string postMessageOrigin; + bool hidePrintOption = false; + bool hideSaveOption = false; + bool hideExportOption = false; std::string resMsg; Poco::StreamCopier::copyToString(rs, resMsg); @@ -346,6 +349,12 @@ WopiStorage::WOPIFileInfo WopiStorage::getWOPIFileInfo(const Poco::URI& uriPubli canWrite = canWriteVar.isString() ? (canWriteVar.toString() == "true") : false; const auto postMessageOriginVar = getOrWarn(object, "PostMessageOrigin"); postMessageOrigin = postMessageOriginVar.isString() ? postMessageOriginVar.toString() : ""; + const auto hidePrintOptionVar = getOrWarn(object, "HidePrintOption"); + hidePrintOption = hidePrintOptionVar.isString() ? (hidePrintOptionVar.toString() == "true") : false; + const auto hideSaveOptionVar = getOrWarn(object, "HideSaveOption"); + hideSaveOption = hideSaveOptionVar.isString() ? (hideSaveOptionVar.toString() == "true") : false; + const auto hideExportOptionVar = getOrWarn(object, "HideExportOption"); + hideExportOption = hideExportOptionVar.isString() ? (hideExportOptionVar.toString() == "true") : false; const auto enableOwnerTerminationVar = getOrWarn(object, "EnableOwnerTermination"); enableOwnerTermination = enableOwnerTerminationVar.isString() ? (enableOwnerTerminationVar.toString() == "true") : false; } @@ -358,7 +367,7 @@ WopiStorage::WOPIFileInfo WopiStorage::getWOPIFileInfo(const Poco::URI& uriPubli _fileInfo = FileInfo({filename, ownerId, Poco::Timestamp(), size}); } - return WOPIFileInfo({userId, userName, canWrite, postMessageOrigin, enableOwnerTermination, callDuration}); + return WOPIFileInfo({userId, userName, canWrite, postMessageOrigin, hidePrintOption, hideSaveOption, hideExportOption, enableOwnerTermination, callDuration}); } /// uri format: http://server/<...>/wopi*/files//content diff --git a/loolwsd/Storage.hpp b/loolwsd/Storage.hpp index a1eb2cf96..d116eec9b 100644 --- a/loolwsd/Storage.hpp +++ b/loolwsd/Storage.hpp @@ -169,12 +169,18 @@ public: const std::string& username, const bool userCanWrite, const std::string& postMessageOrigin, + const bool hidePrintOption, + const bool hideSaveOption, + const bool hideExportOption, const bool enableOwnerTermination, const std::chrono::duration callDuration) : _userid(userid), _username(username), _userCanWrite(userCanWrite), _postMessageOrigin(postMessageOrigin), + _hidePrintOption(hidePrintOption), + _hideSaveOption(hideSaveOption), + _hideExportOption(hideExportOption), _enableOwnerTermination(enableOwnerTermination), _callDuration(callDuration) { @@ -188,6 +194,12 @@ public: bool _userCanWrite; /// WOPI Post message property std::string _postMessageOrigin; + /// Hide print button from UI + bool _hidePrintOption; + /// Hide save button from UI + bool _hideSaveOption; + /// Hide 'Download as' button/menubar item from UI + bool _hideExportOption; /// If WOPI host has enabled owner termination feature on bool _enableOwnerTermination; /// Time it took to call WOPI's CheckFileInfo