summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAshod Nakashian <ashod.nakashian@collabora.co.uk>2021-09-01 20:47:30 -0400
committerMichael Meeks <michael.meeks@collabora.com>2021-09-07 10:23:15 +0100
commit642150dfabeb95a6ffaed2e4e703c413e5648c98 (patch)
treecd8dd450421774ad98151c114ee70cae51daa32a
parentwsd: throw when an invalid URL is used to create an http session (diff)
downloadonline-642150dfabeb95a6ffaed2e4e703c413e5648c98.tar.gz
online-642150dfabeb95a6ffaed2e4e703c413e5648c98.zip
leaflet: move wopiSrc into window and central URL maker
Change-Id: I4e6cda1d4edb192af01977cd4b847ebd01ba3599 Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk>
-rw-r--r--loleaflet/js/global.js23
-rw-r--r--loleaflet/src/core/Socket.js4
-rw-r--r--loleaflet/src/layer/tile/TileLayer.js1
-rw-r--r--loleaflet/src/map/handler/Map.FileInserter.js1
4 files changed, 23 insertions, 6 deletions
diff --git a/loleaflet/js/global.js b/loleaflet/js/global.js
index 53c0442c7d..1c3cce4fc9 100644
--- a/loleaflet/js/global.js
+++ b/loleaflet/js/global.js
@@ -768,10 +768,9 @@ window.app = { // Shouldn't have any functions defined.
var docParams, wopiParams;
var filePath = global.getParameterByName('file_path');
- var wopiSrc = global.getParameterByName('WOPISrc');
- if (wopiSrc != '') {
- global.docURL = decodeURIComponent(wopiSrc);
- wopiSrc = '?WOPISrc=' + wopiSrc + '&compat=';
+ global.wopiSrc = global.getParameterByName('WOPISrc');
+ if (global.wopiSrc != '') {
+ global.docURL = decodeURIComponent(global.wopiSrc);
if (global.accessToken !== '') {
wopiParams = { 'access_token': global.accessToken, 'access_token_ttl': global.accessTokenTTL };
}
@@ -803,6 +802,20 @@ window.app = { // Shouldn't have any functions defined.
return global.host + global.serviceRoot + path;
};
+ // Form a valid WS URL to the host with the given path.
+ global.makeWsUrlWopiSrc = function (path, docUrlParams) {
+ var websocketURI = global.makeWsUrl(path);
+ var wopiSrc = '';
+ if (global.wopiSrc != '') {
+ wopiSrc = '?WOPISrc=' + global.wopiSrc + '&compat=';
+ }
+
+ var encodedDocUrl = encodeURIComponent(docUrlParams) + '/ws' + wopiSrc;
+ if (global.hexifyUrl)
+ encodedDocUrl = global.hexEncode(encodedDocUrl);
+ return websocketURI + encodedDocUrl + '/ws';
+ };
+
// Form a valid HTTP URL to the host with the given path.
global.makeHttpUrl = function (path) {
console.assert(global.webserver.startsWith('http'), 'webserver is not http: ' + global.webserver);
@@ -837,7 +850,7 @@ window.app = { // Shouldn't have any functions defined.
// The URL may already contain a query (e.g., 'http://server.tld/foo/wopi/files/bar?desktop=baz') - then just append more params
var docParamsPart = docParams ? ((global.docURL.indexOf('?') >= 0) ? '&' : '?') + docParams : '';
var websocketURI = global.makeWsUrl('/lool/');
- var encodedDocUrl = encodeURIComponent(global.docURL + docParamsPart) + '/ws' + wopiSrc;
+ var encodedDocUrl = encodeURIComponent(global.docURL + docParamsPart) + '/ws' + '?WOPISrc=' + global.wopiSrc + '&compat=';
if (global.hexifyUrl)
encodedDocUrl = global.hexEncode(encodedDocUrl);
diff --git a/loleaflet/src/core/Socket.js b/loleaflet/src/core/Socket.js
index d58a308363..23707eb466 100644
--- a/loleaflet/src/core/Socket.js
+++ b/loleaflet/src/core/Socket.js
@@ -490,6 +490,7 @@ app.definitions.Socket = L.Class.extend({
oldId = this.WSDServer.Id;
oldVersion = this.WSDServer.Version;
+ console.assert(map.options.wopiSrc === window.wopiSrc, 'wopiSrc mismatch!: ' + map.options.wopiSrc + ' != ' + window.wopiSrc);
// If another file is opened, we will not refresh the page.
if (this._map.options.previousWopiSrc && this._map.options.wopiSrc) {
if (this._map.options.previousWopiSrc !== this._map.options.wopiSrc)
@@ -524,7 +525,6 @@ app.definitions.Socket = L.Class.extend({
if (!window.ThisIsAMobileApp) {
var idUri = window.makeHttpUrl('/hosting/discovery');
- console.assert(idUri.startsWith('http'), 'Invalid URL from makeHttpUrl: ' + idUri);
$('#loolwsd-id').html(_('Served by:') + ' <a target="_blank" href="' + idUri + '">' + this.WSDServer.Id + '</a>');
}
@@ -1139,6 +1139,8 @@ app.definitions.Socket = L.Class.extend({
this._map.options.doc = docUrl;
this._map.options.previousWopiSrc = this._map.options.wopiSrc; // After save-as op, we may connect to another server, then code will think that server has restarted. In this case, we don't want to reload the page (detect the file name is different).
this._map.options.wopiSrc = encodeURIComponent(docUrl);
+ window.wopiSrc = this._map.options.wopiSrc;
+ window.docURL = this._map.options.doc;
if (textMsg.startsWith('renamefile:')) {
this._map.fire('postMessage', {
diff --git a/loleaflet/src/layer/tile/TileLayer.js b/loleaflet/src/layer/tile/TileLayer.js
index cdb0d6b346..515fe3a111 100644
--- a/loleaflet/src/layer/tile/TileLayer.js
+++ b/loleaflet/src/layer/tile/TileLayer.js
@@ -1128,6 +1128,7 @@ L.TileLayer = L.GridLayer.extend({
parser.href = window.host;
var wopiSrc = '';
+ console.assert(this._map.options.wopiSrc === window.wopiSrc, 'wopiSrc mismatch!: ' + this._map.options.wopiSrc + ' != ' + window.wopiSrc);
if (this._map.options.wopiSrc != '') {
wopiSrc = '?WOPISrc=' + this._map.options.wopiSrc;
}
diff --git a/loleaflet/src/map/handler/Map.FileInserter.js b/loleaflet/src/map/handler/Map.FileInserter.js
index 318fdfbe5c..a9c5f5e865 100644
--- a/loleaflet/src/map/handler/Map.FileInserter.js
+++ b/loleaflet/src/map/handler/Map.FileInserter.js
@@ -23,6 +23,7 @@ L.Map.FileInserter = L.Handler.extend({
getWopiUrl: function (map) {
var wopiSrc = '';
+ console.assert(map.options.wopiSrc === window.wopiSrc, 'wopiSrc mismatch!: ' + map.options.wopiSrc + ' != ' + window.wopiSrc);
if (map.options.wopiSrc != '') {
wopiSrc = '?WOPISrc=' + map.options.wopiSrc;
}