loleaflet/src/control/Toolbar.js | 9 +++++++- loleaflet/src/layer/tile/TileLayer.js | 2 - loleaflet/src/map/handler/Map.WOPI.js | 6 +++++ wsd/ClientSession.cpp | 37 ++++++++++++++++++++++++++++++++-- wsd/DocumentBroker.cpp | 9 ++++++++ wsd/Storage.cpp | 8 ++++++- wsd/Storage.hpp | 12 +++++++++++ wsd/protocol.txt | 5 +++- 8 files changed, 82 insertions(+), 6 deletions(-)
New commits: commit eb52992911cc649e819df2741ec6563bf7f452fb Author: Pranav Kant <pran...@collabora.co.uk> Date: Tue Dec 13 15:36:33 2016 +0530 Disable{Print,Export,Copy} feature This is a combination of following commits: loleaflet: Use readable id= argument in downloadas Change-Id: Ica9ba833f487f2c75f8629fd91f31b216c4797b5 (cherry picked from commit 8135e678bb3ae51b638002e1e6f990021a4cb0b3) Document downloadas protocol message Change-Id: Iad8775c441e8fbb531b4608bd6ccb391435e7dcf (cherry picked from commit 1ddd85c77c2d8683a48c5060c7c07e421f0d8dc0) wsd: Allow hosts to disable print, export Change-Id: I415597d710107f9d8cbb8757f361365cc2a88eb1 (cherry picked from commit 6affbb307c5408fa3b3c090bf2cdfdb0b2529dc5) wsd: Allow disabling copy/paste to/from the document to browser Change-Id: I73c70f46f1db11d69ebff582f72127d304689aa2 (cherry picked from commit 3ce8c3158a6b9375d4b8ca862ea5b50490af4c35) Pass Disable{Print,Export,Copy} options to client and handle them Change-Id: I59a9432bbdd06d8b184f96882c5f4009fcd0be54 (cherry picked from commit a76825728e13a36ed570621cfb9da72b5e3c0a24) wsd: If Disabled, turn their corresponding Hide options on Change-Id: I65a320850a35b5af4291d896d5942dddfaaa0c98 (cherry picked from commit b914aa422264ff68b69d75a397f1fd0836791dd7) Reviewed-on: https://gerrit.libreoffice.org/32171 Reviewed-by: Michael Meeks <michael.me...@collabora.com> Tested-by: Michael Meeks <michael.me...@collabora.com> diff --git a/loleaflet/src/control/Toolbar.js b/loleaflet/src/control/Toolbar.js index 3de887f..8ad990a 100644 --- a/loleaflet/src/control/Toolbar.js +++ b/loleaflet/src/control/Toolbar.js @@ -52,13 +52,20 @@ L.Map.include({ return; } + id = id || 'export'; // not any special download, simple export + + if ((id === 'print' && this['wopi'].DisablePrint) || + (id === 'export' && this['wopi'].DisableExport)) { + this.hideBusy(); + return; + } + if (format === undefined || format === null) { format = ''; } if (options === undefined || options === null) { options = ''; } - id = id || -1; // not a special download this.showBusy(_('Downloading...'), false); this._socket.sendMessage('downloadas ' + diff --git a/loleaflet/src/layer/tile/TileLayer.js b/loleaflet/src/layer/tile/TileLayer.js index ba57b74..b5b0c21 100644 --- a/loleaflet/src/layer/tile/TileLayer.js +++ b/loleaflet/src/layer/tile/TileLayer.js @@ -476,7 +476,7 @@ L.TileLayer = L.GridLayer.extend({ else if (command.id === 'slideshow') { this._map.fire('slidedownloadready', {url: url}); } - else { + else if (command.id === 'export') { this._map._fileDownloader.src = url; } }, diff --git a/loleaflet/src/map/handler/Map.WOPI.js b/loleaflet/src/map/handler/Map.WOPI.js index a47fc09..38e0a5b 100644 --- a/loleaflet/src/map/handler/Map.WOPI.js +++ b/loleaflet/src/map/handler/Map.WOPI.js @@ -10,6 +10,9 @@ L.Map.WOPI = L.Handler.extend({ HidePrintOption: false, HideSaveOption: false, HideExportOption: false, + DisablePrint: false, + DisableExport: false, + DisableCopy: false, _appLoadedConditions: { doclayerinit: false, @@ -57,6 +60,9 @@ L.Map.WOPI = L.Handler.extend({ this.HidePrintOption = !!wopiInfo['HidePrintOption']; this.HideSaveOption = !!wopiInfo['HideSaveOption']; this.HideExportOption = !!wopiInfo['HideExportOption']; + this.DisablePrint = !!wopiInfo['DisablePrint']; + this.DisableExport = !!wopiInfo['DisableExport']; + this.DisableCopy = !!wopiInfo['DisableCopy']; this._map.fire('postMessage', {msgId: 'App_LoadingStatus', args: {Status: 'Frame_Ready'}}); }, diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp index 000459b..4bccd87 100644 --- a/wsd/ClientSession.cpp +++ b/wsd/ClientSession.cpp @@ -403,10 +403,43 @@ bool ClientSession::filterMessage(const std::string& message) const { bool allowed = true; StringTokenizer tokens(message, " ", StringTokenizer::TOK_IGNORE_EMPTY | StringTokenizer::TOK_TRIM); - if (isReadOnly()) + + // Set allowed flag to false depending on if particular WOPI properties are set + if (tokens[0] == "downloadas") + { + std::string id; + if (getTokenString(tokens[2], "id", id)) + { + if (id == "print" && _wopiFileInfo && _wopiFileInfo->_disablePrint) + { + allowed = false; + LOG_WRN("WOPI host has disabled print for this session"); + } + else if (id == "export" && _wopiFileInfo && _wopiFileInfo->_disableExport) + { + allowed = false; + LOG_WRN("WOPI host has disabled export for this session"); + } + } + else + { + allowed = false; + LOG_WRN("No value of id in downloadas message"); + } + } + else if (tokens[0] == "gettextselection" || tokens[0] == "paste" || tokens[0] == "insertfile") + { + if (_wopiFileInfo && _wopiFileInfo->_disableCopy) + { + allowed = false; + LOG_WRN("WOPI host has disabled copying to/from the document"); + } + } + else if (isReadOnly()) { + // By default, don't allow anything allowed = false; - if (tokens[0] == "downloadas" || tokens[0] == "userinactive" || tokens[0] == "useractive") + if (tokens[0] == "userinactive" || tokens[0] == "useractive") { allowed = true; } diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp index 365bd0b..6aaea39 100644 --- a/wsd/DocumentBroker.cpp +++ b/wsd/DocumentBroker.cpp @@ -266,9 +266,18 @@ bool DocumentBroker::load(std::shared_ptr<ClientSession>& session, const std::st wopiInfo->set("PostMessageOrigin", wopifileinfo->_postMessageOrigin); } + // If print, export are disabled, order client to hide these options in the UI + if (wopifileinfo->_disablePrint) + wopifileinfo->_hidePrintOption = true; + if (wopifileinfo->_disableExport) + wopifileinfo->_hideExportOption = true; + wopiInfo->set("HidePrintOption", wopifileinfo->_hidePrintOption); wopiInfo->set("HideSaveOption", wopifileinfo->_hideSaveOption); wopiInfo->set("HideExportOption", wopifileinfo->_hideExportOption); + wopiInfo->set("DisablePrint", wopifileinfo->_disablePrint); + wopiInfo->set("DisableExport", wopifileinfo->_disableExport); + wopiInfo->set("DisableCopy", wopifileinfo->_disableCopy); std::ostringstream ossWopiInfo; wopiInfo->stringify(ossWopiInfo); diff --git a/wsd/Storage.cpp b/wsd/Storage.cpp index b99c556..585711f 100644 --- a/wsd/Storage.cpp +++ b/wsd/Storage.cpp @@ -390,6 +390,9 @@ std::unique_ptr<WopiStorage::WOPIFileInfo> WopiStorage::getWOPIFileInfo(const Po bool hidePrintOption = false; bool hideSaveOption = false; bool hideExportOption = false; + bool disablePrint = false; + bool disableExport = false; + bool disableCopy = false; std::string resMsg; Poco::StreamCopier::copyToString(rs, resMsg); @@ -414,6 +417,9 @@ std::unique_ptr<WopiStorage::WOPIFileInfo> WopiStorage::getWOPIFileInfo(const Po getWOPIValue(object, "HideSaveOption", hideSaveOption); getWOPIValue(object, "HideExportOption", hideExportOption); getWOPIValue(object, "EnableOwnerTermination", enableOwnerTermination); + getWOPIValue(object, "DisablePrint", disablePrint); + getWOPIValue(object, "DisableExport", disableExport); + getWOPIValue(object, "DisableCopy", disableCopy); } else Log::error("WOPI::CheckFileInfo is missing JSON payload"); @@ -424,7 +430,7 @@ std::unique_ptr<WopiStorage::WOPIFileInfo> WopiStorage::getWOPIFileInfo(const Po _fileInfo = FileInfo({filename, ownerId, Poco::Timestamp(), size}); } - return std::unique_ptr<WopiStorage::WOPIFileInfo>(new WOPIFileInfo({userId, userName, canWrite, postMessageOrigin, hidePrintOption, hideSaveOption, hideExportOption, enableOwnerTermination, callDuration})); + return std::unique_ptr<WopiStorage::WOPIFileInfo>(new WOPIFileInfo({userId, userName, canWrite, postMessageOrigin, hidePrintOption, hideSaveOption, hideExportOption, enableOwnerTermination, disablePrint, disableExport, disableCopy, callDuration})); } /// uri format: http://server/<...>/wopi*/files/<id>/content diff --git a/wsd/Storage.hpp b/wsd/Storage.hpp index 689f7db..58d7ecb 100644 --- a/wsd/Storage.hpp +++ b/wsd/Storage.hpp @@ -180,6 +180,9 @@ public: const bool hideSaveOption, const bool hideExportOption, const bool enableOwnerTermination, + const bool disablePrint, + const bool disableExport, + const bool disableCopy, const std::chrono::duration<double> callDuration) : _userid(userid), _username(username), @@ -189,6 +192,9 @@ public: _hideSaveOption(hideSaveOption), _hideExportOption(hideExportOption), _enableOwnerTermination(enableOwnerTermination), + _disablePrint(disablePrint), + _disableExport(disableExport), + _disableCopy(disableCopy), _callDuration(callDuration) { } @@ -209,6 +215,12 @@ public: bool _hideExportOption; /// If WOPI host has enabled owner termination feature on bool _enableOwnerTermination; + /// If WOPI host has allowed the user to print the document + bool _disablePrint; + /// If WOPI host has allowed the user to export the document + bool _disableExport; + /// If WOPI host has allowed the user to copy to/from the document + bool _disableCopy; /// Time it took to call WOPI's CheckFileInfo std::chrono::duration<double> _callDuration; }; diff --git a/wsd/protocol.txt b/wsd/protocol.txt index d8f1231..f43f76c 100644 --- a/wsd/protocol.txt +++ b/wsd/protocol.txt @@ -34,7 +34,10 @@ canceltiles downloadas name=<fileName> id=<id> format=<document format> options=<SkipImages, etc> Exports the current document to the desired format and returns a download URL - The id identifies the request on the client. + The id identifies the request on the client. id can take following values: + * 'print': When request for download is basically for print purposes + * 'slideshow': When request for download is for showing slideshow + * 'export': Just a simple download getchildid _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits