common/Session.cpp | 8 +++++++- common/Session.hpp | 8 +++++++- kit/ChildSession.cpp | 2 +- kit/Kit.cpp | 4 +++- kit/Kit.hpp | 1 + loleaflet/reference.html | 3 ++- loleaflet/src/layer/tile/TileLayer.js | 18 +++++++++--------- loleaflet/src/map/Map.js | 12 ++++++++---- wsd/ClientSession.cpp | 10 +++++----- wsd/ClientSession.hpp | 6 +----- 10 files changed, 44 insertions(+), 28 deletions(-)
New commits: commit bc9823111902ec99aba7b3725e87dfc22a64b3d1 Author: Pranav Kant <pran...@collabora.co.uk> Date: Fri Mar 31 12:08:58 2017 +0530 loleaflet: Store and hide readonly view cursors Change-Id: Ib2bec3158275e77d883308e25f1984491309234f diff --git a/loleaflet/reference.html b/loleaflet/reference.html index 57d329c5..0db570d3 100644 --- a/loleaflet/reference.html +++ b/loleaflet/reference.html @@ -2865,11 +2865,12 @@ Editor to WOPI Host <nobr>UserId: <String></nobr> <nobr>UserName: <String></nobr> <nobr>Color: <Number></nobr> + <nobr>ReadOnly: <Boolean></nobr> </code></td> <td>A new member is added. ViewId is unique integer identifying a session/view. UserId is user identity. UserName is display name of the user. Color is RGB color integer - value. + value. ReadOnly tells if the new view is opened as readonly. </td> </tr> <tr> diff --git a/loleaflet/src/layer/tile/TileLayer.js b/loleaflet/src/layer/tile/TileLayer.js index 05a6e504..a5ea4bcd 100644 --- a/loleaflet/src/layer/tile/TileLayer.js +++ b/loleaflet/src/layer/tile/TileLayer.js @@ -842,19 +842,19 @@ L.TileLayer = L.GridLayer.extend({ this._onUpdateViewCursor(viewId); }, - _addView: function(viewId, userid, username, color) { - if (color === 0 && this._map.getDocType() !== 'text') { - color = L.LOUtil.getViewIdColor(viewId); + _addView: function(viewInfo) { + if (viewInfo.color === 0 && this._map.getDocType() !== 'text') { + viewInfo.color = L.LOUtil.getViewIdColor(viewInfo.id); } - this._map.addView(viewId, userid, username, color); + this._map.addView(viewInfo); //TODO: We can initialize color and other properties here. - if (typeof this._viewCursors[viewId] !== 'undefined') { - this._viewCursors[viewId] = {}; + if (typeof this._viewCursors[viewInfo.id] !== 'undefined') { + this._viewCursors[viewInfo.id] = {}; } - this._onUpdateViewCursor(viewId); + this._onUpdateViewCursor(viewInfo.id); }, _removeView: function(viewId) { @@ -888,7 +888,7 @@ L.TileLayer = L.GridLayer.extend({ var viewIds = []; for (var viewInfoIdx in viewInfo) { if (!(parseInt(viewInfo[viewInfoIdx].id) in this._map._viewInfo)) { - this._addView(viewInfo[viewInfoIdx].id, viewInfo[viewInfoIdx].userid, viewInfo[viewInfoIdx].username, viewInfo[viewInfoIdx].color); + this._addView(viewInfo[viewInfoIdx]); } viewIds.push(viewInfo[viewInfoIdx].id); } @@ -1369,7 +1369,7 @@ L.TileLayer = L.GridLayer.extend({ var viewCursorVisible = this._viewCursors[viewId].visible; var viewPart = this._viewCursors[viewId].part; - if (viewCursorVisible && !this._isEmptyRectangle(this._viewCursors[viewId].bounds) && + if (!this._map.isViewReadOnly(viewId) && viewCursorVisible && !this._isEmptyRectangle(this._viewCursors[viewId].bounds) && (this._docType === 'text' || this._selectedPart === viewPart)) { if (!viewCursorMarker) { var viewCursorOptions = { diff --git a/loleaflet/src/map/Map.js b/loleaflet/src/map/Map.js index 3d86db2b..adeb8a83 100644 --- a/loleaflet/src/map/Map.js +++ b/loleaflet/src/map/Map.js @@ -148,12 +148,12 @@ L.Map = L.Evented.extend({ // public methods that modify map state - addView: function(viewid, userid, username, color) { - this._viewInfo[viewid] = {'userid': userid, 'username': username, 'color': color}; - this.fire('postMessage', {msgId: 'View_Added', args: {ViewId: viewid, UserId: userid, UserName: username, Color: color}}); + addView: function(viewInfo) { + this._viewInfo[viewInfo.id] = viewInfo; + this.fire('postMessage', {msgId: 'View_Added', args: {ViewId: viewInfo.id, UserId: viewInfo.userid, UserName: viewInfo.username, Color: viewInfo.color, ReadOnly: viewInfo.readonly}}); // Fire last, otherwise not all events are handled correctly. - this.fire('addview', {viewId: viewid, username: username}); + this.fire('addview', {viewId: viewInfo.id, username: viewInfo.username, readonly: this.isViewReadOnly(viewInfo.id)}); }, removeView: function(viewid) { @@ -412,6 +412,10 @@ L.Map = L.Evented.extend({ return this._viewInfo[viewid].color; }, + isViewReadOnly: function(viewid) { + return this._viewInfo[viewid].readonly !== '0'; + }, + getCenter: function () { // (Boolean) -> LatLng this._checkIfLoaded(); commit ce1084b74f7f336236649b47fc564a654dec5a95 Author: Pranav Kant <pran...@collabora.co.uk> Date: Thu Mar 30 20:29:59 2017 +0530 wsd: Send readonly info to clients With this every other client would be able to know about other client's permission i.e whether they have opened the document as readonly. This could be important eg: to hide the cursor overlay of readonly users in the UI or to mark these users as readonly in the userlist. Change-Id: I5dcb1b4e5a22c9b546d16b69b9216cc7653cff04 diff --git a/common/Session.cpp b/common/Session.cpp index d6a4eb8a..9dcb5329 100644 --- a/common/Session.cpp +++ b/common/Session.cpp @@ -44,13 +44,14 @@ using namespace LOOLProtocol; using Poco::Exception; -Session::Session(const std::string& name, const std::string& id) : +Session::Session(const std::string& name, const std::string& id, bool readOnly) : _id(id), _name(name), _disconnected(false), _isActive(true), _lastActivityTime(std::chrono::steady_clock::now()), _isCloseFrame(false), + _isReadOnly(readOnly), _docPassword(""), _haveDocPassword(false), _isDocPasswordProtected(false) @@ -108,6 +109,11 @@ void Session::parseDocOptions(const std::vector<std::string>& tokens, int& part, Poco::URI::decode(userName, _userName); ++offset; } + else if (tokens[i].find("readonly=") == 0) + { + _isReadOnly = tokens[i].substr(strlen("readonly=")) != "0"; + ++offset; + } else if (tokens[i].find("timestamp=") == 0) { timestamp = tokens[i].substr(strlen("timestamp=")); diff --git a/common/Session.hpp b/common/Session.hpp index 76d0d829..2b460d43 100644 --- a/common/Session.hpp +++ b/common/Session.hpp @@ -37,6 +37,9 @@ public: const std::string& getName() const { return _name; } bool isDisconnected() const { return _disconnected; } + virtual void setReadOnly() { _isReadOnly = true; } + bool isReadOnly() const { return _isReadOnly; } + virtual bool sendBinaryFrame(const char* buffer, int length); virtual bool sendTextFrame(const char* buffer, const int length); bool sendTextFrame(const std::string& text) @@ -80,7 +83,7 @@ public: bool isCloseFrame() const { return _isCloseFrame; } protected: - Session(const std::string& name, const std::string& id); + Session(const std::string& name, const std::string& id, bool readonly); virtual ~Session(); /// Parses the options of the "load" command, shared between MasterProcessSession::loadDocument() and ChildProcessSession::loadDocument(). @@ -119,6 +122,9 @@ private: std::mutex _mutex; + /// Whether the session is opened as readonly + bool _isReadOnly; + protected: /// The actual URL, also in the child, even if the child never accesses that. std::string _docURL; diff --git a/kit/ChildSession.cpp b/kit/ChildSession.cpp index f62fe306..e3aaa5dd 100644 --- a/kit/ChildSession.cpp +++ b/kit/ChildSession.cpp @@ -38,7 +38,7 @@ std::recursive_mutex ChildSession::Mutex; ChildSession::ChildSession(const std::string& id, const std::string& jailId, IDocumentManager& docManager) : - Session("ToMaster-" + id, id), + Session("ToMaster-" + id, id, false), _jailId(jailId), _docManager(docManager), _viewId(-1), diff --git a/kit/Kit.cpp b/kit/Kit.cpp index 58f79b28..6131ba40 100644 --- a/kit/Kit.cpp +++ b/kit/Kit.cpp @@ -1060,6 +1060,8 @@ private: oss << "\"userid\":\"" << itView->second.userid << "\","; const auto username = itView->second.username; oss << "\"username\":\"" << username << "\","; + const auto readonly = itView->second.isReadOnly; + oss << "\"readonly\":\"" << readonly << "\","; const auto it = viewColorsMap.find(username); if (it != viewColorsMap.end()) { @@ -1233,7 +1235,7 @@ private: const int viewId = _loKitDocument->getView(); session->setViewId(viewId); - _sessionUserInfo[viewId] = UserInfo({session->getViewUserId(), session->getViewUserName()}); + _sessionUserInfo[viewId] = UserInfo({session->getViewUserId(), session->getViewUserName(), session->isReadOnly()}); _viewIdToCallbackDescr.emplace(viewId, std::unique_ptr<CallbackDescriptor>(new CallbackDescriptor({ this, viewId }))); diff --git a/kit/Kit.hpp b/kit/Kit.hpp index a1b97c6f..6895bbdb 100644 --- a/kit/Kit.hpp +++ b/kit/Kit.hpp @@ -38,6 +38,7 @@ struct UserInfo { std::string userid; std::string username; + bool isReadOnly; }; /// Check the ForkCounter, and if non-zero, fork more of them accordingly. diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp index 9178dff7..af5a653b 100644 --- a/wsd/ClientSession.cpp +++ b/wsd/ClientSession.cpp @@ -33,10 +33,9 @@ ClientSession::ClientSession(const std::string& id, const std::shared_ptr<DocumentBroker>& docBroker, const Poco::URI& uriPublic, const bool readOnly) : - Session("ToClient-" + id, id), + Session("ToClient-" + id, id, readOnly), _docBroker(docBroker), _uriPublic(uriPublic), - _isReadOnly(readOnly), _isDocumentOwner(false), _isAttached(false), _stop(false) @@ -260,6 +259,8 @@ bool ClientSession::loadDocument(const char* /*buffer*/, int /*length*/, oss << " author=" + encodedUserName; } + oss << " readonly=" << isReadOnly(); + if (loadPart >= 0) { oss << " part=" << loadPart; @@ -440,12 +441,11 @@ bool ClientSession::filterMessage(const std::string& message) const void ClientSession::setReadOnly() { - _isReadOnly = true; + Session::setReadOnly(); // Also inform the client sendTextFrame("perm: readonly"); } - int ClientSession::getPollEvents(std::chrono::steady_clock::time_point /* now */, int & /* timeoutMaxMs */) { @@ -787,7 +787,7 @@ void ClientSession::dumpState(std::ostream& os) { Session::dumpState(os); - os << "\t\tisReadOnly: " << _isReadOnly + os << "\t\tisReadOnly: " << isReadOnly() << "\n\t\tisDocumentOwner: " << _isDocumentOwner << "\n\t\tisAttached: " << _isAttached << "\n\t\tstop: " <<_stop diff --git a/wsd/ClientSession.hpp b/wsd/ClientSession.hpp index 59f8b738..f3cecee9 100644 --- a/wsd/ClientSession.hpp +++ b/wsd/ClientSession.hpp @@ -32,8 +32,7 @@ public: SocketHandlerInterface::SocketOwnership handleIncomingMessage() override; - void setReadOnly(); - bool isReadOnly() const { return _isReadOnly; } + void setReadOnly() override; /// Returns true if a document is loaded (i.e. we got status message). bool isAttached() const { return _isAttached; } @@ -140,9 +139,6 @@ private: /// URI with which client made request to us const Poco::URI _uriPublic; - /// Whether the session is opened as readonly - bool _isReadOnly; - /// Whether this session is the owner of currently opened document bool _isDocumentOwner; _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits