[Libreoffice-commits] online.git: 5 commits - loleaflet/reference.html loleaflet/src wsd/ClientSession.cpp wsd/DocumentBroker.cpp wsd/DocumentBroker.hpp wsd/protocol.txt

Pranav Kant pranavk at collabora.co.uk
Thu Feb 8 07:04:35 UTC 2018


 loleaflet/reference.html              |   66 +++++++++++++++++++++++++++++-----
 loleaflet/src/control/Styles.js       |   20 ----------
 loleaflet/src/core/Socket.js          |   12 ++++++
 loleaflet/src/map/Map.js              |    2 -
 loleaflet/src/map/handler/Map.WOPI.js |   15 +++++++
 wsd/ClientSession.cpp                 |    8 ++++
 wsd/DocumentBroker.cpp                |   11 ++---
 wsd/DocumentBroker.hpp                |    3 +
 wsd/protocol.txt                      |   18 +++++++++
 9 files changed, 116 insertions(+), 39 deletions(-)

New commits:
commit 1fabfd9fe34815cab54c1417cfc7e541adb6a341
Author: Pranav Kant <pranavk at collabora.co.uk>
Date:   Fri Feb 2 11:35:29 2018 +0530

    Version restore states
    
    See documentation
    
    Change-Id: Ica3cd3744643157c5a2c6c1e42e0858ad641da16

diff --git a/loleaflet/reference.html b/loleaflet/reference.html
index 7894f2a7..51516b44 100644
--- a/loleaflet/reference.html
+++ b/loleaflet/reference.html
@@ -33,7 +33,7 @@
 <h2>API Reference</h2>
 
 <div id="toc" class="clearfix">
-	<div class="toc-col map-col">
+    <div class="toc-col map-col">
 		<h4>Map</h4>
 		<ul>
 			<li><a href="#map-usage">Usage example</a></li>
@@ -2759,17 +2759,20 @@ Editor to WOPI host
 		<td><code>
 		    <nobr>Status: <String></nobr>
 		    <nobr>DocumentLoadedTime: <Timestamp></nobr>
-		</code></td>
-		<td>If Status is Frame_Ready, loleaflet frame is loaded and UI
-		can be shown. <br/>
-		When Status is Document_Loaded, document has been completely
-		loaded and host can also start sending document-specific query
-		messages using post message API such as Get_Views,
-		Get_Export_Formats etc. DocumentLoadedTime is specified
-		only in this case.
+		    <nobr>Features: <Dict></nobr>
+		</code></td>
+		<td>If Status is <i>Frame_Ready</i>, loleaflet frame is loaded and UI
+		    can be shown. <br/>
+		    Accompanying keys: <i>Features</i>: This client's capabilities.
+		    Supported values are: <i>VersionStates</i>. Tells the host that client supports different version states. See <a href="#loleaflet-postmessage-versioning">Version Restore</a> for more details.<br/>
+		    When Status is Document_Loaded, document has been completely
+		    loaded and host can also start using PostMessage API.<br/>
+		    Accompanying keys:
+		    <i>DocumentLoadedTime</i>
 		</td>
 	</tr>
 </table>
+
 WOPI host to editor
 <table data-id='postmessage-initialization-to-editor'>
 	<tr>
@@ -2986,6 +2989,51 @@ Actions response
 	</tr>
 </table>
 
+<h3 id="loleaflet-postmessage-versioning">Version Restore</h3>
+WOPI host to editor
+<table data-id="postmessage-versioning-to-editor">
+    <tr>
+	<th>MessageId</th>
+	<th>Values</th>
+	<th>Description</th>
+    </tr>
+    <tr>
+	<td><code><b>Host_VersionRestore</b></code></td>
+	<td><code>
+	    <nobr>Status: <string></nobr>
+	</code></td>
+	<td>
+	    Only possible value of Status (for now) is <code>Pre_Restore</code>.
+	    This message is sent by the host <b>before</b> actually restoring the document
+	    and <b>after</b> user showed the intent to restore the document. This is so such
+	    that if there are any unsaved changes, Online can save them to storage before
+	    document is restored.
+	</td>
+    </tr>
+</table>
+Editor to WOPI host
+<table data-id="postmessage-versioning-to-host">
+    <tr>
+	<th>MessageId</th>
+	<th>Values</th>
+	<th>Description</th>
+    </tr>
+    <tr>
+	<td><code><b>App_VersionRestore</b></code></td>
+	<td><code>
+	    <nobr>Status: <string></nobr>
+	</code></td>
+	<td>
+	    This is the reply for the Host_VersionRestore message. Possible values for <code>Status</code>
+	    (for now) is: <code>Pre_Restore_Ack</code>. It means that host can go ahead with restoring the
+	    document to an earlier revision.
+	</td>
+    </tr>
+</table>
+
+<h4>Note</h4>
+<p>These messages are only emitted if <i>App_LoadingStatus</i> contains <i>VersionStates</i> in <i>Features</i>. Otherwise, host can immediately restore the version to earlier revision.</p>
+
 <h3 id='loleaflet-postmessage-misc'>Miscellaneous</h3>
 WOPI host to editor
 <table data-id='postmessage-misc-to-editor'>
diff --git a/loleaflet/src/core/Socket.js b/loleaflet/src/core/Socket.js
index 6a0cdf17..9cb99c23 100644
--- a/loleaflet/src/core/Socket.js
+++ b/loleaflet/src/core/Socket.js
@@ -258,6 +258,7 @@ L.Socket = L.Class.extend({
 			textMsg = textMsg.substring('close: '.length);
 			msg = '';
 			var postMsgData = {};
+			var showMsgAndReload = false;
 			// This is due to document owner terminating the session
 			if (textMsg === 'ownertermination') {
 				msg = _('Session terminated by document owner');
@@ -311,7 +312,18 @@ L.Socket = L.Class.extend({
 			}
 			else if (textMsg.startsWith('documentconflict')) {
 				msg = _('Document has changed in storage. Loading the new document. Your version is available as revision.');
+				showMsgAndReload = true;
+			}
+			else if (textMsg.startsWith('versionrestore:')) {
+				textMsg = textMsg.substring('versionrestore:'.length).trim();
+				if (textMsg === 'prerestore_ack') {
+					msg = _('Restoring older revision. Any unsaved changes will be available in version history');
+					this._map.fire('postMessage', {msgId: 'App_VersionRestore', args: {Status: 'Pre_Restore_Ack'}});
+					showMsgAndReload = true;
+				}
+			}
 
+			if (showMsgAndReload) {
 				if (this._map._docLayer) {
 					this._map._docLayer.removeAllViews();
 				}
diff --git a/loleaflet/src/map/handler/Map.WOPI.js b/loleaflet/src/map/handler/Map.WOPI.js
index 67495fb7..6b4395f8 100644
--- a/loleaflet/src/map/handler/Map.WOPI.js
+++ b/loleaflet/src/map/handler/Map.WOPI.js
@@ -72,7 +72,15 @@ L.Map.WOPI = L.Handler.extend({
 		this.DisableInactiveMessages = !!wopiInfo['DisableInactiveMessages'];
 		this.UserCanNotWriteRelative = !!wopiInfo['UserCanNotWriteRelative'];
 
-		this._map.fire('postMessage', {msgId: 'App_LoadingStatus', args: {Status: 'Frame_Ready'}});
+		this._map.fire('postMessage', {
+			msgId: 'App_LoadingStatus',
+			args: {
+				Status: 'Frame_Ready',
+				Features: {
+					VersionStates: true
+				}
+			}
+		});
 	},
 
 	resetAppLoaded: function() {
@@ -231,6 +239,11 @@ L.Map.WOPI = L.Handler.extend({
 				}
 			}
 		}
+		else if (msg.MessageId === 'Host_VersionRestore') {
+			if (msg.Values.Status === 'Pre_Restore') {
+				this._map._socket.sendMessage('versionrestore prerestore');
+			}
+		}
 	},
 
 	_postMessage: function(e) {
diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index d94a8467..1b98b4ec 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -129,6 +129,7 @@ bool ClientSession::_handleInput(const char *buffer, int length)
              tokens[0] != "outlinestate" &&
              tokens[0] != "commandvalues" &&
              tokens[0] != "closedocument" &&
+             tokens[0] != "versionrestore" &&
              tokens[0] != "downloadas" &&
              tokens[0] != "getchildid" &&
              tokens[0] != "gettextselection" &&
@@ -195,6 +196,13 @@ bool ClientSession::_handleInput(const char *buffer, int length)
 
         return true;
     }
+    else if (tokens[0] == "versionrestore") {
+        if (tokens[1] == "prerestore") {
+            // green signal to WOPI host to restore the version *after* saving
+            // any unsaved changes, if any, to the storage
+            docBroker->closeDocument("versionrestore: prerestore_ack");
+        }
+    }
     else if (tokens[0] == "partpagerectangles")
     {
         // We don't support partpagerectangles any more, will be removed in the
diff --git a/wsd/protocol.txt b/wsd/protocol.txt
index bb871d81..1f5f2bb9 100644
--- a/wsd/protocol.txt
+++ b/wsd/protocol.txt
@@ -204,6 +204,14 @@ closedocument
     having that document opened. This functionality is enabled only in case WOPI
     host mentions 'EnableOwnerTermination' flag in its CheckFileInfo response
 
+versionrestore <action>
+
+    Version restore related messages.
+
+    <action> can take following values:
+    - prerestore: The storage is about restore the document to an earlier
+    revision.
+
 server -> client
 ================
 
@@ -292,6 +300,9 @@ close: <reason>
     because file was changed in storage and we want to load the new document
     from the storage.
 
+    * versionrestore payload - Version restore message is also sent as part of
+      the close frame. See `versionrestore:` message for details.
+
 getchildid: id=<id>
 
     Returns the child id
@@ -444,6 +455,13 @@ wopi: <JSON>
      + HideExportOption: (boolean): If loleaflet should hide the export options
        this implies 'Download as' options in file menu
 
+versionrestore: <action>
+
+     Possible values for <action>:
+
+     - prerestore_ack: The host can go ahead with restoring the document to an
+       earlier revision.
+
 child -> parent
 ===============
 
commit d189ed90cceb10620e881310ce5e4c4ea5382509
Author: Pranav Kant <pranavk at collabora.co.uk>
Date:   Fri Feb 2 13:17:45 2018 +0530

    Document stop() vs closeDocument()
    
    Change-Id: I52483c0300d1d4c5b1def80b71ccd0661590bfab

diff --git a/wsd/DocumentBroker.hpp b/wsd/DocumentBroker.hpp
index a5345f67..443d8ab5 100644
--- a/wsd/DocumentBroker.hpp
+++ b/wsd/DocumentBroker.hpp
@@ -226,7 +226,7 @@ public:
     /// Start processing events
     void startThread();
 
-    /// Flag for termination.
+    /// Flag for termination. Note that this doesn't save any unsaved changes in the document
     void stop(const std::string& reason);
 
     /// Thread safe termination of this broker if it has a lingering thread
@@ -321,6 +321,7 @@ public:
 
     int getRenderedTileCount() { return _debugRenderedTileCount; }
 
+    /// Ask the document broker to close. Makes sure that the document is saved.
     void closeDocument(const std::string& reason);
 
     /// Called by the ChildProcess object to notify
commit 595ed1c6b1340ac4f89fc073ab3aaa8b24f51ca9
Author: Pranav Kant <pranavk at collabora.co.uk>
Date:   Thu Feb 1 22:43:47 2018 +0530

    wsd: DocumentBroker: Don't initiate the document close
    
    Just broadcast the message and let clients deal with it. This is similar
    to how we do it when we find the document conflict via CheckFileInfo
    
    Change-Id: I52855fcb96a359b3915afe71d481321f79b4554b

diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index 81470f6d..beafe29e 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -839,14 +839,11 @@ bool DocumentBroker::saveToStorageInternal(const std::string& sessionId,
     {
         LOG_ERR("PutFile says that Document changed in storage");
         _documentChangedInStorage = true;
+        std::string message = "close: documentconflict";
         if (_isModified)
-        {
-            broadcastMessage("error: cmd=storage kind=documentconflict");
-        }
-        else
-        {
-            closeDocument("documentconflict");
-        }
+            message = "error: cmd=storage kind=documentconflict";
+
+        broadcastMessage(message);
     }
 
     return false;
commit 23b12ce60d5653f33127dc5b82fc8903e109bb32
Author: Pranav Kant <pranavk at collabora.co.uk>
Date:   Fri Feb 2 18:38:48 2018 +0530

    Unused object definition
    
    Change-Id: Idacd860d7d48a555863601a06cd1a2533b93b508

diff --git a/loleaflet/src/control/Styles.js b/loleaflet/src/control/Styles.js
index a53c5685..632dfee4 100644
--- a/loleaflet/src/control/Styles.js
+++ b/loleaflet/src/control/Styles.js
@@ -279,26 +279,6 @@ L.Styles = {
 		'List 5':'List 5'
 	},
 
-	// For impress documents, LOK STATE_CHANGED callback return these internal names
-	// which are different from what is returned by initial .uno:StyleApply.
-	// Convert these names to our stored internal names before processing
-	impressMapping : {
-		'Titel':'title',
-		'Untertitel':'subtitle',
-		'Gliederung 1':'outline1',
-		'Gliederung 2':'outline2',
-		'Gliederung 3':'outline3',
-		'Gliederung 4':'outline4',
-		'Gliederung 5':'outline5',
-		'Gliederung 6':'outline6',
-		'Gliederung 7':'outline7',
-		'Gliederung 8':'outline8',
-		'Gliederung 9':'outline9',
-		'Hintergrund':'background',
-		'Hintergrundobjekte':'backgroundobjects',
-		'Notizen':'notes'
-	},
-
 	impressLayout : [
 		{id: 0, text: 'Title Slide'},
 		{id: 1, text: 'Title, Content'},
commit e7a6258cafbecf733409f2bfceac8310c818bf60
Author: Pranav Kant <pranavk at collabora.co.uk>
Date:   Fri Feb 2 18:20:10 2018 +0530

    Guard this
    
    Sometimes doc layer might not be available.
    
    Change-Id: I8f5824e16ed734a5ed7ae8ad42c1107be2c8a9d2

diff --git a/loleaflet/src/map/Map.js b/loleaflet/src/map/Map.js
index 17d033cc..f2b31925 100644
--- a/loleaflet/src/map/Map.js
+++ b/loleaflet/src/map/Map.js
@@ -166,7 +166,7 @@ L.Map = L.Evented.extend({
 				} else {
 					this._activate();
 				}
-			} else {
+			} else if (this._docLayer) {
 				// remove the comments and changes
 				this._docLayer.clearAnnotations();
 			}


More information about the Libreoffice-commits mailing list