loleaflet/dist/loleaflet.html | 13 ++++++++ loleaflet/dist/toolbar/toolbar.js | 2 - loleaflet/main.js | 10 ++++-- loleaflet/src/control/Control.Menubar.js | 4 -- loleaflet/src/core/Socket.js | 12 +++++++ loleaflet/src/layer/tile/TileLayer.js | 6 +-- loleaflet/src/map/Map.js | 47 +++++++++++++++++++++++++++++-- loolwsd/DocumentBroker.cpp | 5 +++ loolwsd/Storage.cpp | 5 ++- loolwsd/Storage.hpp | 4 ++ 10 files changed, 95 insertions(+), 13 deletions(-)
New commits: commit e0e6a343dade6ffd33f07ca916b176aec019bd21 Author: Pranav Kant <pran...@collabora.co.uk> Date: Wed Oct 26 21:30:12 2016 +0530 tdf#103450: Implement session management postmessage API Change-Id: Id22759c5c103948078fb20943768a9ff6251dddf diff --git a/loleaflet/src/map/Map.js b/loleaflet/src/map/Map.js index d015765..2d6ceb6 100644 --- a/loleaflet/src/map/Map.js +++ b/loleaflet/src/map/Map.js @@ -137,12 +137,14 @@ L.Map = L.Evented.extend({ addView: function(viewid, userid, username, color) { this._viewInfo[viewid] = {'userid': userid, 'username': username, 'color': color}; this.fire('addview', {viewId: viewid, username: username}); + this.WOPIPostMessage('View_Added', {ViewId: viewid, UserId: userid, UserName: username, Color: color}); }, removeView: function(viewid) { var username = this._viewInfo[viewid].username; delete this._viewInfo[viewid]; this.fire('removeview', {viewId: viewid, username: username}); + this.WOPIPostMessage('View_Removed', {ViewId: viewid}); }, getViewName: function(viewid) { @@ -158,8 +160,24 @@ L.Map = L.Evented.extend({ }, _WOPIPostMessageListener: function(e) { - // TODO - //console.log(e); + if (!window.WOPIPostmessageReady) { + return; + } + + var msg = JSON.parse(e.data); + if (msg.MessageId === 'Get_Views') { + var getMembersRespVal = []; + for (var viewInfoIdx in this._viewInfo) { + getMembersRespVal.push({ + ViewId: viewInfoIdx, + UserName: this._viewInfo[viewInfoIdx].username, + UserId: this._viewInfo[viewInfoIdx].userid, + Color: this._viewInfo[viewInfoIdx].color + }); + } + + this.WOPIPostMessage('Get_Views_Resp', getMembersRespVal); + } }, WOPIPostMessage: function(msgId, values) { commit 56f6ee7a57acd299cf8a9a70e78fab4f82080db6 Author: Pranav Kant <pran...@collabora.co.uk> Date: Wed Oct 26 21:15:33 2016 +0530 loleaflet: Store userid in map Change-Id: Ia54516b52ace3f722ae27ee28b5a11897dedc479 diff --git a/loleaflet/src/layer/tile/TileLayer.js b/loleaflet/src/layer/tile/TileLayer.js index 90dcc34..22d7aa5 100644 --- a/loleaflet/src/layer/tile/TileLayer.js +++ b/loleaflet/src/layer/tile/TileLayer.js @@ -758,8 +758,8 @@ L.TileLayer = L.GridLayer.extend({ this._onUpdateViewCursor(viewId); }, - _addView: function(viewId, username, color) { - this._map.addView(viewId, username, color); + _addView: function(viewId, userid, username, color) { + this._map.addView(viewId, userid, username, color); //TODO: We can initialize color and other properties here. if (typeof this._viewCursors[viewId] !== 'undefined') { @@ -799,7 +799,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].username, viewInfo[viewInfoIdx].color); + this._addView(viewInfo[viewInfoIdx].id, viewInfo[viewInfoIdx].userid, viewInfo[viewInfoIdx].username, viewInfo[viewInfoIdx].color); } viewIds.push(viewInfo[viewInfoIdx].id); } diff --git a/loleaflet/src/map/Map.js b/loleaflet/src/map/Map.js index 87c0197..d015765 100644 --- a/loleaflet/src/map/Map.js +++ b/loleaflet/src/map/Map.js @@ -134,8 +134,8 @@ L.Map = L.Evented.extend({ // public methods that modify map state - addView: function(viewid, username, color) { - this._viewInfo[viewid] = {'username': username, 'color': color}; + addView: function(viewid, userid, username, color) { + this._viewInfo[viewid] = {'userid': userid, 'username': username, 'color': color}; this.fire('addview', {viewId: viewid, username: username}); }, commit 4987df6547bfea184c707a7f1239f8559cda09ee Author: Pranav Kant <pran...@collabora.co.uk> Date: Wed Oct 26 18:58:35 2016 +0530 tdf#103450: WOPI compliant message and new way to post message Use map's WOPIPostMessage which takes care of bunch of things according to WOPI Change-Id: Id559179d684fd6243d3afa488d4cddc9eb92f4d6 diff --git a/loleaflet/dist/toolbar/toolbar.js b/loleaflet/dist/toolbar/toolbar.js index 1de1a70..f5fc593 100644 --- a/loleaflet/dist/toolbar/toolbar.js +++ b/loleaflet/dist/toolbar/toolbar.js @@ -220,7 +220,7 @@ function onClick(id, item, subItem) { resizeToolbar(); } else if (id === 'close') { - window.parent.postMessage('close', '*'); + map.WOPIPostMessage('UI_Close'); map.remove(); } } diff --git a/loleaflet/src/control/Control.Menubar.js b/loleaflet/src/control/Control.Menubar.js index 6f8f71d..c08722c 100644 --- a/loleaflet/src/control/Control.Menubar.js +++ b/loleaflet/src/control/Control.Menubar.js @@ -321,9 +321,7 @@ L.Control.Menubar = L.Control.extend({ } else if (id === 'rev-history') { // if we are being loaded inside an iframe, ask // our host to show revision history mode - if (window.top !== window.self) { - window.parent.postMessage('rev-history', '*'); - } + map.WOPIPostMessage('rev-history'); } else if (id === 'repair') { map._socket.sendMessage('commandvalues command=.uno:DocumentRepair'); } commit cfcc6bdd94a658dd4a70da7daa4fe5658c101be6 Author: Pranav Kant <pran...@collabora.co.uk> Date: Tue Oct 25 12:43:00 2016 +0530 tdf#103450: Implement WOPI initialization postmessage API This includes support for Host_PostmessageReady and App_LoadingStatus Change-Id: Iaa0222dfa63c17b26a4fcb2236973bacdd61ee62 diff --git a/loleaflet/dist/loleaflet.html b/loleaflet/dist/loleaflet.html index ff3edca..084b710 100644 --- a/loleaflet/dist/loleaflet.html +++ b/loleaflet/dist/loleaflet.html @@ -6,6 +6,19 @@ <meta name="viewport" content="width=device-width, initial-scale=1.0"> +<script> + // Start listening for Host_PostmessageReady message and save the + // result for future + window.WOPIpostMessageReady = false; + var PostMessageReadyListener = function(e) { + var msg = JSON.parse(e.data); + if (msg.MessageId === 'Host_PostmessageReady') { + window.WOPIPostmessageReady = true; + window.removeEventListener('message', PostMessageReadyListener, false); + } + }; + window.addEventListener('message', PostMessageReadyListener, false); +</script> <link rel="stylesheet" href="/loleaflet/%VERSION%/branding.css"> <!-- add your logo here --> <link rel="localizations" href="/loleaflet/%VERSION%/l10n/localizations.json" type="application/vnd.oftn.l10n+json"/> <link rel="localizations" href="/loleaflet/%VERSION%/l10n/styles-localizations.json" type="application/vnd.oftn.l10n+json" /> diff --git a/loleaflet/main.js b/loleaflet/main.js index 3074bdf..3528ea9 100644 --- a/loleaflet/main.js +++ b/loleaflet/main.js @@ -78,12 +78,15 @@ global.revHistoryEnabled = revHistoryEnabled; global.title = title; global.errorMessages = errorMessages; var docURL, docParams; +var storageType; if (wopiSrc != '') { docURL = wopiSrc; - docParams = wopiParams; + docParams = wopiParams; + storageType = 'wopi'; } else { docURL = filePath; - docParams = {}; + docParams = {}; + storageType = 'local'; } document.title = title; @@ -94,7 +97,8 @@ var map = L.map('map', { permission: permission, timestamp: timestamp, documentContainer: 'document-container', - debug: debugMode + debug: debugMode, + storageType: storageType }); // toolbar.js (loaded in <script> tag accesses map as global variable, // so expose it diff --git a/loleaflet/src/core/Socket.js b/loleaflet/src/core/Socket.js index 488aeda..ba35050 100644 --- a/loleaflet/src/core/Socket.js +++ b/loleaflet/src/core/Socket.js @@ -167,6 +167,18 @@ L.Socket = L.Class.extend({ return; } + else if (textMsg.startsWith('wopi: ')) { + // Handle WOPI related messages + textMsg = textMsg.substring('wopi: '.length); + if (textMsg.startsWith('postmessageorigin ')) { + this._map._wopi['PostMessageOrigin'] = textMsg.substring('postmessageorigin '.length); + this._map._wopi['DocumentLoadedTime'] = Date.now(); + // Tell the host that we are ready now + this._map.WOPIPostMessage('App_LoadingStatus', {'DocumentLoadedTime': this._map._wopi['DocumentLoadedTime']}); + } + + return; + } else if (textMsg.startsWith('error:') && command.errorCmd === 'internal') { this._map._fatal = true; if (command.errorKind === 'diskfull') { diff --git a/loleaflet/src/map/Map.js b/loleaflet/src/map/Map.js index 70fc83b..87c0197 100644 --- a/loleaflet/src/map/Map.js +++ b/loleaflet/src/map/Map.js @@ -123,6 +123,12 @@ L.Map = L.Evented.extend({ // View color map this._viewColors = {}; + + // WOPI specific properties container + this._wopi = {}; + + // WOPI PostMessage Listener + L.DomEvent.on(window, 'message', this._WOPIPostMessageListener, this); }, @@ -151,6 +157,25 @@ L.Map = L.Evented.extend({ return this._viewInfo[viewid].color; }, + _WOPIPostMessageListener: function(e) { + // TODO + //console.log(e); + }, + + WOPIPostMessage: function(msgId, values) { + if (this.options.storageType === 'wopi' && this._wopiPostMessageOrigin !== '') { + if (window.top !== window.self) { + var msg = { + 'MessageId': msgId, + 'SendTime': Date.now(), + 'Values': values + }; + + window.parent.postMessage(JSON.stringify(msg), this._wopi['PostMessageOrigin']); + } + } + }, + // replaced by animation-powered implementation in Map.PanAnimation.js setView: function (center, zoom) { zoom = zoom === undefined ? this.getZoom() : zoom; diff --git a/loolwsd/DocumentBroker.cpp b/loolwsd/DocumentBroker.cpp index 5bc55ed..2e24c72 100644 --- a/loolwsd/DocumentBroker.cpp +++ b/loolwsd/DocumentBroker.cpp @@ -237,6 +237,11 @@ bool DocumentBroker::load(const std::string& sessionId, const std::string& jailI it->second->setReadOnly(); } + if (!wopifileinfo._postMessageOrigin.empty()) + { + it->second->sendTextFrame("wopi: postmessageorigin " + wopifileinfo._postMessageOrigin); + } + getInfoCallDuration = wopifileinfo._callDuration; } else if (dynamic_cast<LocalStorage*>(_storage.get()) != nullptr) diff --git a/loolwsd/Storage.cpp b/loolwsd/Storage.cpp index 451387e..4b3f31c 100644 --- a/loolwsd/Storage.cpp +++ b/loolwsd/Storage.cpp @@ -310,6 +310,7 @@ WopiStorage::WOPIFileInfo WopiStorage::getWOPIFileInfo(const Poco::URI& uriPubli std::string userId; std::string userName; bool canWrite = false; + std::string postMessageOrigin; std::string resMsg; Poco::StreamCopier::copyToString(rs, resMsg); @@ -332,6 +333,8 @@ WopiStorage::WOPIFileInfo WopiStorage::getWOPIFileInfo(const Poco::URI& uriPubli userName = (userNameVar.isString() ? userNameVar.toString() : "anonymous"); const auto canWriteVar = getOrWarn(object, "UserCanWrite"); canWrite = canWriteVar.isString() ? (canWriteVar.toString() == "true") : false; + const auto postMessageOriginVar = getOrWarn(object, "PostMessageOrigin"); + postMessageOrigin = postMessageOriginVar.isString() ? postMessageOriginVar.toString() : ""; } else Log::error("WOPI::CheckFileInfo is missing JSON payload"); @@ -342,7 +345,7 @@ WopiStorage::WOPIFileInfo WopiStorage::getWOPIFileInfo(const Poco::URI& uriPubli _fileInfo = FileInfo({filename, Poco::Timestamp(), size}); } - return WOPIFileInfo({userId, userName, canWrite, callDuration}); + return WOPIFileInfo({userId, userName, canWrite, postMessageOrigin, callDuration}); } /// uri format: http://server/<...>/wopi*/files/<id>/content diff --git a/loolwsd/Storage.hpp b/loolwsd/Storage.hpp index e9ed98c..b21b19e 100644 --- a/loolwsd/Storage.hpp +++ b/loolwsd/Storage.hpp @@ -166,10 +166,12 @@ public: WOPIFileInfo(const std::string& userid, const std::string& username, const bool userCanWrite, + const std::string& postMessageOrigin, const std::chrono::duration<double> callDuration) : _userid(userid), _username(username), _userCanWrite(userCanWrite), + _postMessageOrigin(postMessageOrigin), _callDuration(callDuration) { } @@ -180,6 +182,8 @@ public: std::string _username; /// If user accessing the file has write permission bool _userCanWrite; + /// WOPI Post message property + std::string _postMessageOrigin; /// Time it took to call WOPI's CheckFileInfo std::chrono::duration<double> _callDuration; }; _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits