summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPranav Kant <pranavk@collabora.co.uk>2016-11-15 13:48:18 +0530
committerPranav Kant <pranavk@collabora.co.uk>2016-11-15 18:23:40 +0530
commitd8a202bf1cc2a4cc343833348f08dcfdadbdd409 (patch)
treed1f9de038a6ed9a5c1538e386eba697b6574a287
parent72a5f35f30d2e9250795abf910a1456d7b62b78e (diff)
tdf#103641: Split App_LoadedStatus - Frame_Ready, Document_Loaded
Post App_LoadingStatus with 'Status' field as Frame_Ready when we are ready to show the UI. Post Document_Loaded when document is completely loaded after which loleaflet is ready to respond to more document specific queries through post message API. Change-Id: I60a4e9b75e115c748fcee8d449bc8c2d4ffa34a9
-rw-r--r--loleaflet/reference.html17
-rw-r--r--loleaflet/src/core/Socket.js16
-rw-r--r--loleaflet/src/layer/tile/TileLayer.js1
-rw-r--r--loleaflet/src/map/handler/Map.WOPI.js61
4 files changed, 77 insertions, 18 deletions
diff --git a/loleaflet/reference.html b/loleaflet/reference.html
index 529728ae1..e8bb801d6 100644
--- a/loleaflet/reference.html
+++ b/loleaflet/reference.html
@@ -2769,12 +2769,17 @@ Editor to WOPI host
<tr>
<td><code><b>App_LoadingStatus</b></code></td>
<td><code>
- <nobr>DocumentLoadedTime: &lt;Number&gt;</nobr>
- </code></td>
- <td>When loleaflet frame is completely ready. Host can start
- sending other messages using post message API.
- DocumentLoadedTime is timestamp when frame is
- ready/loaded.</td>
+ <nobr>Status: &lt;String&gt;</nobr>
+ <nobr>DocumentLoadedTime: &lt;Timestamp&gt;</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.
+ </td>
</tr>
</table>
WOPI host to editor
diff --git a/loleaflet/src/core/Socket.js b/loleaflet/src/core/Socket.js
index d504ba6cb..e8b342bf9 100644
--- a/loleaflet/src/core/Socket.js
+++ b/loleaflet/src/core/Socket.js
@@ -180,18 +180,7 @@ L.Socket = L.Class.extend({
else if (textMsg.startsWith('wopi: ')) {
// Handle WOPI related messages
var wopiInfo = JSON.parse(textMsg.substring(textMsg.indexOf('{')));
- // Store postmessageorigin property in our WOPI handler, if it exists
- if (this._map['wopi'] && !!wopiInfo['PostMessageOrigin']) {
- this._map['wopi'].PostMessageOrigin = wopiInfo['PostMessageOrigin'];
- this._map['wopi'].DocumentLoadedTime = Date.now();
- // Tell the host that we are ready now
- this._map.fire('postMessage', {msgId: 'App_LoadingStatus', args: {'DocumentLoadedTime': this._map['wopi'].DocumentLoadedTime}});
- }
-
- this._map['wopi'].HidePrintOption = !!wopiInfo['HidePrintOption'];
- this._map['wopi'].HideSaveOption = !!wopiInfo['HideSaveOption'];
- this._map['wopi'].HideExportOption = !!wopiInfo['HideExportOption'];
-
+ this._map.fire('wopiprops', wopiInfo);
return;
}
else if (textMsg.startsWith('close: ')) {
@@ -412,6 +401,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
+ this._map['wopi'].resetAppLoaded();
},
parseServerCmd: function (msg) {
diff --git a/loleaflet/src/layer/tile/TileLayer.js b/loleaflet/src/layer/tile/TileLayer.js
index 40ad0a317..5e2c3a05f 100644
--- a/loleaflet/src/layer/tile/TileLayer.js
+++ b/loleaflet/src/layer/tile/TileLayer.js
@@ -820,6 +820,7 @@ L.TileLayer = L.GridLayer.extend({
_onViewInfoMsg: function(textMsg) {
textMsg = textMsg.substring('viewinfo: '.length);
var viewInfo = JSON.parse(textMsg);
+ this._map.fire('viewinfo', viewInfo);
// A new view
var viewIds = [];
diff --git a/loleaflet/src/map/handler/Map.WOPI.js b/loleaflet/src/map/handler/Map.WOPI.js
index 766db04d7..a47fc09ba 100644
--- a/loleaflet/src/map/handler/Map.WOPI.js
+++ b/loleaflet/src/map/handler/Map.WOPI.js
@@ -11,20 +11,81 @@ L.Map.WOPI = L.Handler.extend({
HideSaveOption: false,
HideExportOption: false,
+ _appLoadedConditions: {
+ doclayerinit: false,
+ updatepermission: false,
+ viewinfo: false /* Whether view information has already arrived */
+ },
+
+ _appLoaded: false,
+
initialize: function(map) {
this._map = map;
},
addHooks: function() {
this._map.on('postMessage', this._postMessage, this);
+
+ // init messages
+ this._map.on('doclayerinit', 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);
+
+ this._map.on('wopiprops', this._setWopiProps, this);
L.DomEvent.on(window, 'message', this._postMessageListener, this);
},
removeHooks: function() {
this._map.off('postMessage', this._postMessage, this);
+
+ // init messages
+ this._map.off('doclayerinit', this._postLoaded, this);
+ this._map.off('updatepermission', this._postLoaded, this);
+ this._map.off('viewinfo', this._postLoaded, this);
+
+ this._map.off('wopiprops', this._setWopiProps, this);
L.DomEvent.off(window, 'message', this._postMessageListener, this);
},
+ _setWopiProps: function(wopiInfo) {
+ // Store postmessageorigin property, if it exists
+ if (!!wopiInfo['PostMessageOrigin']) {
+ this.PostMessageOrigin = wopiInfo['PostMessageOrigin'];
+ }
+
+ this.HidePrintOption = !!wopiInfo['HidePrintOption'];
+ this.HideSaveOption = !!wopiInfo['HideSaveOption'];
+ this.HideExportOption = !!wopiInfo['HideExportOption'];
+
+ this._map.fire('postMessage', {msgId: 'App_LoadingStatus', args: {Status: 'Frame_Ready'}});
+ },
+
+ resetAppLoaded: function() {
+ this._appLoaded = false;
+ for (var key in this._appLoadedConditions) {
+ this._appLoadedConditions[key] = false;
+ }
+ },
+
+ _postLoaded: function(e) {
+ if (this._appLoaded) {
+ return;
+ }
+
+ if (e.type === 'doclayerinit') {
+ this.DocumentLoadedTime = Date.now();
+ }
+ this._appLoadedConditions[e.type] = true;
+ for (var key in this._appLoadedConditions) {
+ if (!this._appLoadedConditions[key])
+ return;
+ }
+
+ this._appLoaded = true;
+ this._map.fire('postMessage', {msgId: 'App_LoadingStatus', args: {Status: 'Document_Loaded', DocumentLoadedTime: this.DocumentLoadedTime}});
+ },
+
_postMessageListener: function(e) {
if (!window.WOPIPostmessageReady) {
return;