[Libreoffice-commits] online.git: 3 commits - loleaflet/dist loleaflet/src loolwsd/DocumentBroker.cpp loolwsd/LOOLKit.cpp loolwsd/TileCache.hpp

Pranav Kant pranavk at collabora.com
Thu May 5 09:09:27 UTC 2016


 loleaflet/dist/spreadsheet.css        |    8 +++++++-
 loleaflet/src/control/Control.Tabs.js |   17 +++++++++++++++++
 loleaflet/src/layer/tile/TileLayer.js |    2 +-
 loolwsd/DocumentBroker.cpp            |   18 +++++++++++++++---
 loolwsd/LOOLKit.cpp                   |   21 ++++++++++++++++-----
 loolwsd/TileCache.hpp                 |    6 ++++--
 6 files changed, 60 insertions(+), 12 deletions(-)

New commits:
commit 3d02fb74975d967e0b59496d2b25afbe3c9256b8
Author: Pranav Kant <pranavk at collabora.com>
Date:   Thu May 5 14:26:40 2016 +0530

    loleaflet: Enable/disable spreadsheet tabs for edit/view mode
    
    Change-Id: I084f676e77fc161c109a5271dd1cad60a3e5474f

diff --git a/loleaflet/dist/spreadsheet.css b/loleaflet/dist/spreadsheet.css
index aabd15e..774a366 100644
--- a/loleaflet/dist/spreadsheet.css
+++ b/loleaflet/dist/spreadsheet.css
@@ -41,16 +41,22 @@
 	display: inline-block;
 	border: 1px solid darkgrey;
 	background-color: lightgrey;
+	color: black;
 	}
 
 .spreadsheet-context-menu-selected {
-	background: white;
+       background: white !important;
+       color: black !important;
 	border-top: 1px solid lightgrey;
 	border-left: 1px solid lightgrey;
 	border-right: 1px solid lightgrey;
 	border-bottom: 1px solid lightgrey;
 	}
 
+.spreadsheet-context-menu.context-menu-disabled {
+        color: grey;
+        }
+
 .spreadsheet-header-corner {
 	border-top: 1px solid darkgrey;
 	border-left: 1px solid darkgrey;
diff --git a/loleaflet/src/control/Control.Tabs.js b/loleaflet/src/control/Control.Tabs.js
index 4991083..8cd3be8 100644
--- a/loleaflet/src/control/Control.Tabs.js
+++ b/loleaflet/src/control/Control.Tabs.js
@@ -67,6 +67,15 @@ L.Control.Tabs = L.Control.extend({
 		});
 
 		map.on('updateparts', this._updateDisabled, this);
+		map.on('editlock', this._enableTabsContextMenu, this);
+	},
+
+	_enableTabsContextMenu: function(e) {
+		if (!e.value) {
+			$('.spreadsheet-context-menu').contextMenu(false);
+		} else {
+			$('.spreadsheet-context-menu').contextMenu(true);
+		}
 	},
 
 	_updateDisabled: function (e) {
@@ -115,11 +124,19 @@ L.Control.Tabs = L.Control.extend({
 				if (part === selectedPart) {
 					L.DomUtil.addClass(this._spreadsheetTabs[key], 'spreadsheet-context-menu-selected');
 				}
+
+				if (map._editlock) {
+					L.DomUtil.removeClass(this._spreadsheetTabs[key], 'context-menu-disabled');
+				} else {
+					L.DomUtil.addClass(this._spreadsheetTabs[key], 'context-menu-disabled');
+				}
 			}
 		}
 	},
 
 	_setPart: function (e) {
+		if (!map._editlock)
+			return;
 		var part =  e.target.id.match(/\d+/g)[0];
 		if (part !== null) {
 			this._map.setPart(parseInt(part));
commit 7734f2557a514115a0f15599662f3af4b6362155
Author: Pranav Kant <pranavk at collabora.com>
Date:   Thu May 5 12:07:40 2016 +0530

    loolwsd: Do not allow viewing sessions to change parts
    
    bccu#1433, bccu#1757 related.
    
    Piggyback editlock information to tile messages so that kit can
    use that information to allow changing parts only for messages
    with editlock.
    
    ... and decline tile render request for tile messages without editlock
    information
    
    Change-Id: I9cedb870cd977741375665cb258d04c818481a14

diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp
index 612becd..048e6a1 100644
--- a/loolwsd/DocumentBroker.cpp
+++ b/loolwsd/DocumentBroker.cpp
@@ -410,6 +410,10 @@ void DocumentBroker::handleTileRequest(int part, int width, int height, int tile
         oss << " id=" << id;
     }
 
+    // Piggyback editlock information to kit process.
+    // We do not allow requests without editlock to change document parts
+    oss << " editlock=" << (session->isEditLocked() ? "1" : "0");
+
     std::string tileMsg = oss.str();
 
     std::unique_lock<std::mutex> lock(_mutex);
@@ -472,10 +476,18 @@ void DocumentBroker::handleTileResponse(const std::vector<char>& payload)
 
     const auto buffer = payload.data();
     const auto length = payload.size();
-    assert(firstLine.size() < static_cast<std::string::size_type>(length));
-    tileCache().saveTile(part, width, height, tilePosX, tilePosY, tileWidth, tileHeight, buffer + firstLine.size() + 1, length - firstLine.size() - 1);
 
-    tileCache().notifyAndRemoveSubscribers(part, width, height, tilePosX, tilePosY, tileWidth, tileHeight);
+    if(firstLine.size() < static_cast<std::string::size_type>(length) - 1)
+    {
+        tileCache().saveTile(part, width, height, tilePosX, tilePosY, tileWidth, tileHeight, buffer + firstLine.size() + 1, length - firstLine.size() - 1);
+        tileCache().notifyAndRemoveSubscribers(part, width, height, tilePosX, tilePosY, tileWidth, tileHeight);
+    }
+    else
+    {
+        Log::debug() << "Render request declined for " << firstLine << Log::end;
+        std::unique_lock<std::mutex> tileBeingRenderedLock(tileCache().getTilesBeingRenderedLock());
+        tileCache().forgetTileBeingRendered(part, width, height, tilePosX, tilePosY, tileWidth, tileHeight);
+    }
 }
 
 bool DocumentBroker::canDestroy()
diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp
index 9cf8055..318ae60 100644
--- a/loolwsd/LOOLKit.cpp
+++ b/loolwsd/LOOLKit.cpp
@@ -576,16 +576,17 @@ public:
 
     void renderTile(StringTokenizer& tokens, const std::shared_ptr<Poco::Net::WebSocket>& ws)
     {
-        int part, width, height, tilePosX, tilePosY, tileWidth, tileHeight;
+        int part, width, height, tilePosX, tilePosY, tileWidth, tileHeight, editLock;
 
-        if (tokens.count() < 8 ||
+        if (tokens.count() < 9 ||
             !getTokenInteger(tokens[1], "part", part) ||
             !getTokenInteger(tokens[2], "width", width) ||
             !getTokenInteger(tokens[3], "height", height) ||
             !getTokenInteger(tokens[4], "tileposx", tilePosX) ||
             !getTokenInteger(tokens[5], "tileposy", tilePosY) ||
             !getTokenInteger(tokens[6], "tilewidth", tileWidth) ||
-            !getTokenInteger(tokens[7], "tileheight", tileHeight))
+            !getTokenInteger(tokens[7], "tileheight", tileHeight) ||
+            !getTokenInteger(tokens[8], "editlock", editLock))
         {
             //FIXME: Return error.
             //sendTextFrame("error: cmd=tile kind=syntax");
@@ -617,7 +618,7 @@ public:
         //if (_multiView)
             //_loKitDocument->pClass->setView(_loKitDocument, _viewId);
 
-        std::string response = "tile: " + Poco::cat(std::string(" "), tokens.begin() + 1, tokens.end());
+        std::string response = "tile: " + Poco::cat(std::string(" "), tokens.begin() + 1, tokens.end() - 1);
 
 #if ENABLE_DEBUG
         response += " renderid=" + Util::UniqueId();
@@ -634,7 +635,17 @@ public:
 
         if (part != _loKitDocument->pClass->getPart(_loKitDocument))
         {
-            _loKitDocument->pClass->setPart(_loKitDocument, part);
+            if (editLock)
+            {
+                _loKitDocument->pClass->setPart(_loKitDocument, part);
+            }
+            else
+            {
+                // Session without editlock cannot change part
+                Log::debug() << "Declining tile render request: " << response  << Log::end;
+                ws->sendFrame(response.data(), response.size());
+                return;
+            }
         }
 
         Timestamp timestamp;
diff --git a/loolwsd/TileCache.hpp b/loolwsd/TileCache.hpp
index 5f40eb4..6df3b39 100644
--- a/loolwsd/TileCache.hpp
+++ b/loolwsd/TileCache.hpp
@@ -67,6 +67,10 @@ public:
     /// Store the timestamp to modtime.txt.
     void saveLastModified(const Poco::Timestamp& timestamp);
 
+    std::unique_lock<std::mutex> getTilesBeingRenderedLock() { return std::unique_lock<std::mutex>(_tilesBeingRenderedMutex); }
+
+    void forgetTileBeingRendered(int part, int width, int height, int tilePosX, int tilePosY, int tileWidth, int tileHeight);
+
 private:
     void invalidateTiles(int part, int x, int y, int width, int height);
 
@@ -79,8 +83,6 @@ private:
     /// Extract location from fileName, and check if it intersects with [x, y, width, height].
     bool intersectsTile(const std::string& fileName, int part, int x, int y, int width, int height);
 
-    void forgetTileBeingRendered(int part, int width, int height, int tilePosX, int tilePosY, int tileWidth, int tileHeight);
-
     /// Load the timestamp from modtime.txt.
     Poco::Timestamp getLastModified();
 
commit 207f4b5fc9ba1cefb5bace54884e21161813087c
Author: Pranav Kant <pranavk at collabora.com>
Date:   Thu May 5 12:33:02 2016 +0530

    loleaflet: Emit 'editlock' only if changed
    
    Change-Id: I0d08241b82ad105902ad6ca03f015efd0eb9fb2e

diff --git a/loleaflet/src/layer/tile/TileLayer.js b/loleaflet/src/layer/tile/TileLayer.js
index 1b00baa..b5d0ecb 100644
--- a/loleaflet/src/layer/tile/TileLayer.js
+++ b/loleaflet/src/layer/tile/TileLayer.js
@@ -1267,7 +1267,7 @@ L.TileLayer = L.GridLayer.extend({
 
 	_onEditLock: function (textMsg) {
 		var val = parseInt(textMsg.split(' ')[1]);
-		if (!isNaN(val)) {
+		if (!isNaN(val) && val !== this._map._editlock) {
 			this._map._editlock = val;
 			this._map.fire('editlock', {value: val});
 


More information about the Libreoffice-commits mailing list