[Libreoffice-commits] online.git: 3 commits - kit/ChildSession.cpp loleaflet/src wsd/DocumentBroker.cpp

Pranav Kant pranavk at collabora.co.uk
Fri Aug 11 17:57:52 UTC 2017


 kit/ChildSession.cpp                  |    7 --
 loleaflet/src/core/Socket.js          |  109 ++++++++++++++++++----------------
 loleaflet/src/map/Map.js              |   23 ++++++-
 loleaflet/src/map/handler/Map.WOPI.js |   12 ++-
 wsd/DocumentBroker.cpp                |    6 +
 5 files changed, 93 insertions(+), 64 deletions(-)

New commits:
commit ef54b6ea167471ba5dc50947bc071a4c5f58c43f
Author: Pranav Kant <pranavk at collabora.co.uk>
Date:   Fri Aug 11 23:10:34 2017 +0530

    wsd: Ignore useractive, userinactive when doc is not loaded
    
    Sometimes client sends a userinactive message while the document is
    already being loaded, which leads to the kit process skipping sending
    the result of LOK callbacks to the client.
    
    Handling this in child session is futile in the case when userinactive
    message is sent when the document is being loaded, since kit process
    handles the 'userinactive' message only after document is loaded (i.e
    isLoaded() returns true). Moving this handling to DocumentBroker will
    take care of both the cases - when 'userinactive' is sent before load
    starts, and during load of the document.
    
    Change-Id: I4ea3ac7b184d2ca373eb3ff4fb7b4ae394d454df

diff --git a/kit/ChildSession.cpp b/kit/ChildSession.cpp
index 0a4a59e4..49cfde06 100644
--- a/kit/ChildSession.cpp
+++ b/kit/ChildSession.cpp
@@ -183,13 +183,6 @@ bool ChildSession::_handleInput(const char *buffer, int length)
     }
     else if (!_isDocLoaded)
     {
-        // Be forgiving to these messages while we load.
-        if (tokens[0] == "useractive" ||
-            tokens[0] == "userinactive")
-        {
-            return true;
-        }
-
         sendTextFrame("error: cmd=" + tokens[0] + " kind=nodocloaded");
         return false;
     }
diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index 84fddd68..f697c663 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -1316,6 +1316,12 @@ bool DocumentBroker::forwardToChild(const std::string& viewId, const std::string
 {
     assertCorrectThread();
 
+    // Ignore userinactive, useractive message until document is loaded
+    if (!isLoaded() && (message == "userinactive" || message == "useractive"))
+    {
+        return true;
+    }
+
     LOG_TRC("Forwarding payload to child [" << viewId << "]: " << message);
 
     std::string msg = "child-" + viewId + ' ' + message;
commit 8c74d4a38d0fc13e859ea0e936fca0102a0e9d0d
Author: Pranav Kant <pranavk at collabora.co.uk>
Date:   Fri Aug 11 22:32:34 2017 +0530

    loleaflet: activate the inactivity timer after document load
    
    The timer is cancelled right after 'statusindicator' is received, so a
    document never really go to inactive mode after set inactivity time
    period (unless user refocuses the document). Call _activate() to ensure
    that timer is started after document is completely loaded.
    
    Also timer shouldn't really start when the document is not yet loaded.
    
    Change-Id: I58f5d7718c65cc37da9c3feb99ee6b16741a22a2

diff --git a/loleaflet/src/map/Map.js b/loleaflet/src/map/Map.js
index 07b78e1c..600621e9 100644
--- a/loleaflet/src/map/Map.js
+++ b/loleaflet/src/map/Map.js
@@ -152,14 +152,16 @@ L.Map = L.Evented.extend({
 		}, this);
 
 		this.on('docloaded', function(e) {
-			if (e.status) {
+			this._docLoaded = e.status;
+			if (this._docLoaded) {
 				// so that dim timer starts from now()
 				this.lastActiveTime = Date.now();
 				if (!document.hasFocus()) {
 					this._deactivate();
+				} else {
+					this._activate();
 				}
 			}
-			this._docLoaded = e.status;
 		}, this);
 	},
 
@@ -906,7 +908,7 @@ L.Map = L.Evented.extend({
 	},
 
 	_startInactiveTimer: function () {
-		if (this._serverRecycling || this._documentIdle) {
+		if (this._serverRecycling || this._documentIdle || !this._docLoaded) {
 			return;
 		}
 
commit d0be89bffa339e6cefc88cd3ca56ccd86ec1f517
Author: Pranav Kant <pranavk at collabora.co.uk>
Date:   Fri Aug 11 21:39:12 2017 +0530

    loleaflet: new event, docloaded, to sync. various things
    
    First, use the docloaded event to see whether we should be dimming the
    document (make it inactive) or not. There is no point in inactivating a
    document before document has completely loaded; so don't start the timer
    until after the document is completely loaded.
    
    It turns out that we were only emitting the WOPI's App_LoadingStatus
    with DocumentLoaded for the first document load, but not for subsequent
    reconnections. The problem here was that doclayerinit event is only
    emitted during first document load (when TileLayer is -actually-
    initialized), which was responsible for emitting this event. By
    bifurcating the document load from document layer initialization, we
    solve this problem.
    
    Change-Id: I0b7b97fc6244ba9ebd6318d68d78d3abef2c0c08

diff --git a/loleaflet/src/core/Socket.js b/loleaflet/src/core/Socket.js
index 8a18968a..4a91de77 100644
--- a/loleaflet/src/core/Socket.js
+++ b/loleaflet/src/core/Socket.js
@@ -62,6 +62,9 @@ L.Socket = L.Class.extend({
 		this.socket.onmessage = function () {};
 		this.socket.close();
 
+		// Reset wopi's app loaded so that reconnecting again informs outerframe about initialization
+		this._map['wopi'].resetAppLoaded();
+		this._map.fire('docloaded', {status: false});
 		clearTimeout(this._accessTokenExpireTimeout);
 	},
 
@@ -574,59 +577,64 @@ L.Socket = L.Class.extend({
 			var img = 'data:image/png;base64,' + window.btoa(strBytes);
 		}
 
-		if (textMsg.startsWith('status:') && !this._map._docLayer) {
-			// first status message, we need to create the document layer
-			var tileWidthTwips = this._map.options.tileWidthTwips;
-			var tileHeightTwips = this._map.options.tileHeightTwips;
-			if (this._map.options.zoom !== this._map.options.defaultZoom) {
-				var scale = this._map.options.crs.scale(this._map.options.defaultZoom - this._map.options.zoom);
-				tileWidthTwips = Math.round(tileWidthTwips * scale);
-				tileHeightTwips = Math.round(tileHeightTwips * scale);
-			}
+		if (textMsg.startsWith('status:')) {
+			if (!this._map._docLayer) {
+				// first status message, we need to create the document layer
+				var tileWidthTwips = this._map.options.tileWidthTwips;
+				var tileHeightTwips = this._map.options.tileHeightTwips;
+				if (this._map.options.zoom !== this._map.options.defaultZoom) {
+					var scale = this._map.options.crs.scale(this._map.options.defaultZoom - this._map.options.zoom);
+					tileWidthTwips = Math.round(tileWidthTwips * scale);
+					tileHeightTwips = Math.round(tileHeightTwips * scale);
+				}
 
-			var docLayer = null;
-			if (command.type === 'text') {
-				docLayer = new L.WriterTileLayer('', {
-					permission: this._map.options.permission,
-					tileWidthTwips: tileWidthTwips,
-					tileHeightTwips: tileHeightTwips,
-					docType: command.type
-				});
-			}
-			else if (command.type === 'spreadsheet') {
-				docLayer = new L.CalcTileLayer('', {
-					permission: this._map.options.permission,
-					tileWidthTwips: tileWidthTwips,
-					tileHeightTwips: tileHeightTwips,
-					docType: command.type
-				});
-			}
-			else {
-				if (command.type === 'presentation' &&
-						this._map.options.defaultZoom === this._map.options.zoom) {
-					// If we have a presentation document and the zoom level has not been set
-					// in the options, resize the document so that it fits the viewing area
-					var verticalTiles = this._map.getSize().y / 256;
-					tileWidthTwips = Math.round(command.height / verticalTiles);
-					tileHeightTwips = Math.round(command.height / verticalTiles);
+				var docLayer = null;
+				if (command.type === 'text') {
+					docLayer = new L.WriterTileLayer('', {
+						permission: this._map.options.permission,
+						tileWidthTwips: tileWidthTwips,
+						tileHeightTwips: tileHeightTwips,
+						docType: command.type
+					});
 				}
-				docLayer = new L.ImpressTileLayer('', {
-					permission: this._map.options.permission,
-					tileWidthTwips: tileWidthTwips,
-					tileHeightTwips: tileHeightTwips,
-					docType: command.type
-				});
+				else if (command.type === 'spreadsheet') {
+					docLayer = new L.CalcTileLayer('', {
+						permission: this._map.options.permission,
+						tileWidthTwips: tileWidthTwips,
+						tileHeightTwips: tileHeightTwips,
+						docType: command.type
+					});
+				}
+				else {
+					if (command.type === 'presentation' &&
+					    this._map.options.defaultZoom === this._map.options.zoom) {
+						// If we have a presentation document and the zoom level has not been set
+						// in the options, resize the document so that it fits the viewing area
+						var verticalTiles = this._map.getSize().y / 256;
+						tileWidthTwips = Math.round(command.height / verticalTiles);
+						tileHeightTwips = Math.round(command.height / verticalTiles);
+					}
+					docLayer = new L.ImpressTileLayer('', {
+						permission: this._map.options.permission,
+						tileWidthTwips: tileWidthTwips,
+						tileHeightTwips: tileHeightTwips,
+						docType: command.type
+					});
+				}
+
+				this._map._docLayer = docLayer;
+				this._map.addLayer(docLayer);
+				this._map.fire('doclayerinit');
+			}
+			else if (this._reconnecting) {
+				// we are reconnecting ...
+				this._reconnecting = false;
+				this._map._docLayer._onMessage('invalidatetiles: EMPTY', null);
+				this._map.fire('statusindicator', {statusType: 'reconnected'});
+				this._map.setPermission(this._map.options.permission);
 			}
 
-			this._map._docLayer = docLayer;
-			this._map.addLayer(docLayer);
-			this._map.fire('doclayerinit');
-		} else if (textMsg.startsWith('status:') && this._reconnecting) {
-			// we are reconnecting ...
-			this._reconnecting = false;
-			this._map._docLayer._onMessage('invalidatetiles: EMPTY', null);
-			this._map.fire('statusindicator', {statusType: 'reconnected'});
-			this._map.setPermission(this._map.options.permission);
+			this._map.fire('docloaded', {status: true});
 		}
 
 		// these can arrive very early during the startup
@@ -671,8 +679,9 @@ L.Socket = L.Class.extend({
 			this._map.fire('error', {msg: _('Well, this is embarrassing, we cannot connect to your document. Please try again.'), cmd: 'socket', kind: 'closed', id: 4});
 		}
 
-		// Reset wopi's app loaded so that reconnecting again informs outerframe about initialization again
+		// Reset wopi's app loaded so that reconnecting again informs outerframe about initialization
 		this._map['wopi'].resetAppLoaded();
+		this._map.fire('docloaded', {status: false});
 
 		if (!this._reconnecting) {
 			this._reconnecting = true;
diff --git a/loleaflet/src/map/Map.js b/loleaflet/src/map/Map.js
index acf67317..07b78e1c 100644
--- a/loleaflet/src/map/Map.js
+++ b/loleaflet/src/map/Map.js
@@ -143,10 +143,24 @@ L.Map = L.Evented.extend({
 		// This becomes true if document was ever modified by the user
 		this._everModified = false;
 
+		// Document is completely loaded or not
+		this._docLoaded = false;
+
 		this.on('commandstatechanged', function(e) {
 			if (e.commandName === '.uno:ModifiedStatus')
 				this._everModified = this._everModified || (e.state === 'true');
 		}, this);
+
+		this.on('docloaded', function(e) {
+			if (e.status) {
+				// so that dim timer starts from now()
+				this.lastActiveTime = Date.now();
+				if (!document.hasFocus()) {
+					this._deactivate();
+				}
+			}
+			this._docLoaded = e.status;
+		}, this);
 	},
 
 	// public methods that modify map state
@@ -883,7 +897,8 @@ L.Map = L.Evented.extend({
 
 	_dimIfInactive: function () {
 		console.debug('_dimIfInactive: diff=' + (Date.now() - this.lastActiveTime));
-		if ((Date.now() - this.lastActiveTime) >= this.options.idleTimeoutSecs * 1000) {
+		if (this._docLoaded && // don't dim if document hasn't been loaded yet
+		    (Date.now() - this.lastActiveTime) >= this.options.idleTimeoutSecs * 1000) {
 			this._dim();
 		} else {
 			this._startInactiveTimer();
@@ -904,7 +919,7 @@ L.Map = L.Evented.extend({
 	},
 
 	_deactivate: function () {
-		if (this._serverRecycling || this._documentIdle) {
+		if (this._serverRecycling || this._documentIdle || !this._docLoaded) {
 			return;
 		}
 
diff --git a/loleaflet/src/map/handler/Map.WOPI.js b/loleaflet/src/map/handler/Map.WOPI.js
index 8e96efcc..a2f3ddef 100644
--- a/loleaflet/src/map/handler/Map.WOPI.js
+++ b/loleaflet/src/map/handler/Map.WOPI.js
@@ -17,7 +17,7 @@ L.Map.WOPI = L.Handler.extend({
 	DisableCopy: false,
 
 	_appLoadedConditions: {
-		doclayerinit: false,
+		docloaded: false,
 		updatepermission: false,
 		viewinfo: false /* Whether view information has already arrived */
 	},
@@ -32,7 +32,7 @@ L.Map.WOPI = L.Handler.extend({
 		this._map.on('postMessage', this._postMessage, this);
 
 		// init messages
-		this._map.on('doclayerinit', this._postLoaded, this);
+		this._map.on('docloaded', this._postLoaded, this);
 		this._map.on('updatepermission', this._postLoaded, this);
 		// This indicates that 'viewinfo' message has already arrived
 		this._map.on('viewinfo', this._postLoaded, this);
@@ -45,7 +45,7 @@ L.Map.WOPI = L.Handler.extend({
 		this._map.off('postMessage', this._postMessage, this);
 
 		// init messages
-		this._map.off('doclayerinit', this._postLoaded, this);
+		this._map.off('docloaded', this._postLoaded, this);
 		this._map.off('updatepermission', this._postLoaded, this);
 		this._map.off('viewinfo', this._postLoaded, this);
 
@@ -81,7 +81,11 @@ L.Map.WOPI = L.Handler.extend({
 			return;
 		}
 
-		if (e.type === 'doclayerinit') {
+		if (e.type === 'docloaded') {
+			// doc unloaded
+			if (!e.status)
+				return;
+
 			this.DocumentLoadedTime = Date.now();
 		}
 		this._appLoadedConditions[e.type] = true;


More information about the Libreoffice-commits mailing list