common/Session.cpp | 8 +++++++- common/Session.hpp | 7 +++++++ kit/ChildSession.cpp | 5 +---- kit/ChildSession.hpp | 9 +-------- kit/Kit.cpp | 40 +++++++++++++++------------------------- loolwsd.xml.in | 4 ++++ test/WhiteBoxTests.cpp | 10 ++-------- wsd/ClientSession.cpp | 9 +++++---- wsd/LOOLWSD.hpp | 2 +- 9 files changed, 43 insertions(+), 51 deletions(-)
New commits: commit f384b8a414d9ce5a7ac78e7c20b6f33d9ba03f12 Author: Michael Meeks <[email protected]> AuthorDate: Mon Aug 26 16:23:04 2019 -0400 Commit: Michael Meeks <[email protected]> CommitDate: Mon Aug 26 16:29:12 2019 -0400 Add watermark opacity setting. Change-Id: I839e8aef91acfed40d4afd8c1b50176ed54c670a diff --git a/common/Session.cpp b/common/Session.cpp index 5c8d11568..116d2786f 100644 --- a/common/Session.cpp +++ b/common/Session.cpp @@ -55,7 +55,8 @@ Session::Session(const std::string& name, const std::string& id, bool readOnly) _isReadOnly(readOnly), _docPassword(""), _haveDocPassword(false), - _isDocPasswordProtected(false) + _isDocPasswordProtected(false), + _watermarkOpacity(0.2) { } @@ -156,6 +157,11 @@ void Session::parseDocOptions(const std::vector<std::string>& tokens, int& part, Poco::URI::decode(value, _watermarkText); ++offset; } + else if (name == "watermarkOpacity") + { + _watermarkOpacity = std::stod(value); + ++offset; + } else if (name == "timestamp") { timestamp = value; diff --git a/common/Session.hpp b/common/Session.hpp index ddee50d55..6955b1e66 100644 --- a/common/Session.hpp +++ b/common/Session.hpp @@ -102,8 +102,12 @@ public: const std::string& getDocOptions() const { return _docOptions; } + bool hasWatermark() const { return !_watermarkText.empty() && _watermarkOpacity > 0.0; } + const std::string& getWatermarkText() const { return _watermarkText; } + double getWatermarkOpacity() const { return _watermarkOpacity; } + const std::string& getLang() const { return _lang; } bool getHaveDocPassword() const { return _haveDocPassword; } @@ -203,6 +207,9 @@ private: /// In case a watermark has to be rendered on each tile. std::string _watermarkText; + /// Opacity in case a watermark has to be rendered on each tile. + double _watermarkOpacity; + /// Language for the document based on what the user has in the UI. std::string _lang; }; diff --git a/kit/Kit.cpp b/kit/Kit.cpp index 3569a5ffb..ad20beb86 100644 --- a/kit/Kit.cpp +++ b/kit/Kit.cpp @@ -593,7 +593,7 @@ public: , _font("Liberation Sans") , _width(0) , _height(0) - , _alphaLevel(0.2) + , _alphaLevel(session->getWatermarkOpacity()) { } diff --git a/loolwsd.xml.in b/loolwsd.xml.in index 8475a23d3..8ae1c9bdd 100644 --- a/loolwsd.xml.in +++ b/loolwsd.xml.in @@ -107,6 +107,10 @@ <capabilities desc="Should we require capabilities to isolate processes into chroot jails" type="bool" default="true">true</capabilities> </security> + <watermark> + <opacity desc="Opacity of on-screen watermark from 0.0 to 1.0" type="double" default="0.2"></opacity> + </watermark> + <storage desc="Backend storage"> <filesystem allow="false" /> <wopi desc="Allow/deny wopi storage. Mutually exclusive with webdav." allow="true"> diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp index cdd442fb7..69e67681f 100644 --- a/wsd/ClientSession.cpp +++ b/wsd/ClientSession.cpp @@ -773,6 +773,7 @@ bool ClientSession::loadDocument(const char* /*buffer*/, int /*length*/, std::string encodedWatermarkText; Poco::URI::encode(getWatermarkText(), "", encodedWatermarkText); oss << " watermarkText=" << encodedWatermarkText; + oss << " watermarkOpacity=" << LOOLWSD::getConfigValue<double>("watermark.opacity", 0.2); } if (!getDocOptions().empty()) commit 327869fffe67761988a97475a5d17214aa0fac10 Author: Michael Meeks <[email protected]> AuthorDate: Mon Aug 26 16:22:01 2019 -0400 Commit: Michael Meeks <[email protected]> CommitDate: Mon Aug 26 16:29:12 2019 -0400 re-factor childsession onLoad callback to cleanup parameter clutter. Change-Id: I0665db05845a910abf1cc56e13d2f9845cc5c373 diff --git a/kit/ChildSession.cpp b/kit/ChildSession.cpp index 6d7751fdc..0d2c0ad7a 100644 --- a/kit/ChildSession.cpp +++ b/kit/ChildSession.cpp @@ -579,10 +579,7 @@ bool ChildSession::loadDocument(const char * /*buffer*/, int /*length*/, const s std::unique_lock<std::recursive_mutex> lock(Mutex); - const bool loaded = _docManager->onLoad(getId(), getJailedFilePath(), getJailedFilePathAnonym(), - getUserName(), getUserNameAnonym(), - getDocPassword(), renderOpts, getHaveDocPassword(), - getLang(), getWatermarkText(), doctemplate); + const bool loaded = _docManager->onLoad(getId(), getJailedFilePathAnonym(), renderOpts, doctemplate); if (!loaded || _viewId < 0) { LOG_ERR("Failed to get LoKitDocument instance for [" << getJailedFilePathAnonym() << "]."); diff --git a/kit/ChildSession.hpp b/kit/ChildSession.hpp index 4880bc4dc..bd0d12a1c 100644 --- a/kit/ChildSession.hpp +++ b/kit/ChildSession.hpp @@ -38,15 +38,8 @@ class DocumentManagerInterface public: /// Reqest loading a document, or a new view, if one exists. virtual bool onLoad(const std::string& sessionId, - const std::string& jailedFilePath, - const std::string& jailedFilePathAnonym, - const std::string& userName, - const std::string& userNameAnonym, - const std::string& docPassword, + const std::string& uriAnonym, const std::string& renderOpts, - const bool haveDocPassword, - const std::string& lang, - const std::string& watermarkText, const std::string& docTemplate) = 0; /// Unload a client session, which unloads the document diff --git a/kit/Kit.cpp b/kit/Kit.cpp index 40fe64ff9..3569a5ffb 100644 --- a/kit/Kit.cpp +++ b/kit/Kit.cpp @@ -586,9 +586,10 @@ public: class Watermark { public: - Watermark(const std::shared_ptr<lok::Document>& loKitDoc, const std::string& text) + Watermark(const std::shared_ptr<lok::Document>& loKitDoc, + const std::shared_ptr<ChildSession> & session) : _loKitDoc(loKitDoc) - , _text(text) + , _text(session->getWatermarkText()) , _font("Liberation Sans") , _width(0) , _height(0) @@ -1459,15 +1460,8 @@ private: /// Load a document (or view) and register callbacks. bool onLoad(const std::string& sessionId, - const std::string& uri, const std::string& uriAnonym, - const std::string& userName, - const std::string& userNameAnonym, - const std::string& docPassword, const std::string& renderOpts, - const bool haveDocPassword, - const std::string& lang, - const std::string& watermarkText, const std::string& docTemplate) override { std::unique_lock<std::mutex> lock(_mutex); @@ -1477,9 +1471,7 @@ private: " sessions. Another load in progress: " << _isLoading); while (_isLoading) - { _cvLoading.wait(lock); - } // This shouldn't happen, but for sanity. const auto it = _sessions.find(sessionId); @@ -1497,10 +1489,8 @@ private: try { - if (!load(session, uri, uriAnonym, userName, userNameAnonym, docPassword, renderOpts, haveDocPassword, lang, watermarkText, docTemplate)) - { + if (!load(session, renderOpts, docTemplate)) return false; - } } catch (const std::exception& exc) { @@ -1737,19 +1727,19 @@ private: } std::shared_ptr<lok::Document> load(const std::shared_ptr<ChildSession>& session, - const std::string& uri, - const std::string& uriAnonym, - const std::string& userName, - const std::string& userNameAnonym, - const std::string& docPassword, const std::string& renderOpts, - const bool haveDocPassword, - const std::string& lang, - const std::string& watermarkText, const std::string& docTemplate) { const std::string sessionId = session->getId(); + const std::string& uri = session->getJailedFilePath(); + const std::string& uriAnonym = session->getJailedFilePathAnonym(); + const std::string& userName = session->getUserName(); + const std::string& userNameAnonym = session->getUserNameAnonym(); + const std::string& docPassword = session->getDocPassword(); + const bool haveDocPassword = session->getHaveDocPassword(); + const std::string& lang = session->getLang(); + std::string options; if (!lang.empty()) options = "Language=" + lang; @@ -1816,8 +1806,8 @@ private: // No support for changing them after opening a document. _renderOpts = renderOpts; - if (!watermarkText.empty()) - _docWatermark.reset(new Watermark(_loKitDocument, watermarkText)); + if (session->hasWatermark()) + _docWatermark.reset(new Watermark(_loKitDocument, session)); } else { diff --git a/test/WhiteBoxTests.cpp b/test/WhiteBoxTests.cpp index fddf5e7bd..3f5f028cf 100644 --- a/test/WhiteBoxTests.cpp +++ b/test/WhiteBoxTests.cpp @@ -491,16 +491,10 @@ public: : _tileQueue(new TileQueue()) { } + bool onLoad(const std::string& /*sessionId*/, - const std::string& /*jailedFilePath*/, - const std::string& /*jailedFilePathAnonym*/, - const std::string& /*userName*/, - const std::string& /*userNameAnonym*/, - const std::string& /*docPassword*/, + const std::string& /*uriAnonym*/, const std::string& /*renderOpts*/, - const bool /*haveDocPassword*/, - const std::string& /*lang*/, - const std::string& /*watermarkText*/, const std::string& /*docTemplate*/) override { return false; diff --git a/wsd/LOOLWSD.hpp b/wsd/LOOLWSD.hpp index 7c4103e3b..f8708b63d 100644 --- a/wsd/LOOLWSD.hpp +++ b/wsd/LOOLWSD.hpp @@ -122,7 +122,7 @@ public: } /// Returns the value of the specified application configuration, - /// of the default, if one doesn't exist. + /// or the default, if one doesn't exist. template<typename T> static T getConfigValue(const std::string& name, const T def) commit 7850c944e204c3a7d62029b2b319eb836c4c06d3 Author: DarkByt31 <[email protected]> AuthorDate: Fri Aug 23 23:27:24 2019 +0530 Commit: Michael Meeks <[email protected]> CommitDate: Mon Aug 26 16:29:12 2019 -0400 tdf#107038 Poco::Timestamp replacement with std::chrono Change-Id: I85e041a778f14071e55fa6bd05b7b145f7887c57 diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp index 00ca2d506..cdd442fb7 100644 --- a/wsd/ClientSession.cpp +++ b/wsd/ClientSession.cpp @@ -243,7 +243,7 @@ void ClientSession::handleClipboardRequest(DocumentBroker::ClipboardRequest { std::ostringstream oss; oss << "HTTP/1.1 400 Bad Request\r\n" - << "Date: " << Poco::DateTimeFormatter::format(Poco::Timestamp(), Poco::DateTimeFormat::HTTP_FORMAT) << "\r\n" + << "Date: " << Util::getHttpTimeNow() << "\r\n" << "User-Agent: " << WOPI_AGENT_STRING << "\r\n" << "Content-Length: 0\r\n" << "\r\n"; @@ -278,7 +278,7 @@ void ClientSession::handleClipboardRequest(DocumentBroker::ClipboardRequest // FIXME: work harder for error detection ? std::ostringstream oss; oss << "HTTP/1.1 200 OK\r\n" - << "Date: " << Poco::DateTimeFormatter::format(Poco::Timestamp(), Poco::DateTimeFormat::HTTP_FORMAT) << "\r\n" + << "Date: " << Util::getHttpTimeNow() << "\r\n" << "User-Agent: " << WOPI_AGENT_STRING << "\r\n" << "Content-Length: 0\r\n" << "\r\n"; @@ -289,7 +289,7 @@ void ClientSession::handleClipboardRequest(DocumentBroker::ClipboardRequest { std::ostringstream oss; oss << "HTTP/1.1 400 Bad Request\r\n" - << "Date: " << Poco::DateTimeFormatter::format(Poco::Timestamp(), Poco::DateTimeFormat::HTTP_FORMAT) << "\r\n" + << "Date: " << Util::getHttpTimeNow() << "\r\n" << "User-Agent: " << WOPI_AGENT_STRING << "\r\n" << "Content-Length: 0\r\n" << "\r\n"; @@ -1296,7 +1296,7 @@ bool ClientSession::handleKitToClientMessage(const char* buffer, const int lengt { std::ostringstream oss; oss << "HTTP/1.1 200 OK\r\n" - << "Last-Modified: " << Poco::DateTimeFormatter::format(Poco::Timestamp(), Poco::DateTimeFormat::HTTP_FORMAT) << "\r\n" + << "Last-Modified: " << Util::getHttpTimeNow() << "\r\n" << "User-Agent: " << WOPI_AGENT_STRING << "\r\n" << "Content-Length: " << (empty ? 0 : (payload->size() - header)) << "\r\n" << "Content-Type: application/octet-stream\r\n" _______________________________________________ Libreoffice-commits mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
