leaflet: support hexifying the body of the lool URI
Signed-off-by: Ashod Nakashian <ashod.nakashian@collabora.co.uk> (cherry picked from commit cfa7972289e9c71b56c81722aedc14189f842475) Change-Id: Iebf214a1bba76dd44fe2c160a0749675aa5b140a
This commit is contained in:
parent
81eb4cdbe4
commit
e363273e22
3 changed files with 30 additions and 2 deletions
|
@ -260,6 +260,7 @@ m4_ifelse(MOBILEAPP,[true],
|
|||
m4_ifelse(MOBILEAPP,[true],
|
||||
[window.host = '';
|
||||
window.serviceRoot = '';
|
||||
window.hexifyUrl = false;
|
||||
window.versionPath = '%VERSION%';
|
||||
window.accessToken = '';
|
||||
window.accessTokenTTL = '';
|
||||
|
@ -278,6 +279,7 @@ m4_ifelse(MOBILEAPP,[true],
|
|||
window.uiDefaults = {};],
|
||||
[window.host = '%HOST%';
|
||||
window.serviceRoot = '%SERVICE_ROOT%';
|
||||
window.hexifyUrl = %HEXIFY_URL%;
|
||||
window.versionPath = '%VERSION%';
|
||||
window.accessToken = '%ACCESS_TOKEN%';
|
||||
window.accessTokenTTL = '%ACCESS_TOKEN_TTL%';
|
||||
|
|
|
@ -771,7 +771,7 @@ window.app = { // Shouldn't have any functions defined.
|
|||
var wopiSrc = global.getParameterByName('WOPISrc');
|
||||
if (wopiSrc != '') {
|
||||
global.docURL = decodeURIComponent(wopiSrc);
|
||||
wopiSrc = '?WOPISrc=' + wopiSrc + '&compat=/ws';
|
||||
wopiSrc = '?WOPISrc=' + wopiSrc + '&compat=';
|
||||
if (global.accessToken !== '') {
|
||||
wopiParams = { 'access_token': global.accessToken, 'access_token_ttl': global.accessTokenTTL };
|
||||
}
|
||||
|
@ -802,14 +802,39 @@ window.app = { // Shouldn't have any functions defined.
|
|||
return global.webserver + global.serviceRoot + path;
|
||||
};
|
||||
|
||||
// Encode a string to hex.
|
||||
global.hexEncode = function (string) {
|
||||
var bytes = new TextEncoder().encode(string);
|
||||
var hex = '0x';
|
||||
for (i = 0; i < bytes.length; ++i) {
|
||||
hex += bytes[i].toString(16);
|
||||
}
|
||||
return hex;
|
||||
};
|
||||
|
||||
// Decode hexified string back to plain text.
|
||||
global.hexDecode = function (hex) {
|
||||
if (hex.startsWith('0x'))
|
||||
hex = hex.substr(2);
|
||||
var bytes = new Uint8Array(hex.length / 2);
|
||||
for (i = 0; i < bytes.length; i++) {
|
||||
bytes[i] = parseInt(hex.substr(i * 2, 2), 16);
|
||||
}
|
||||
return new TextDecoder().decode(bytes);
|
||||
};
|
||||
|
||||
if (window.ThisIsAMobileApp) {
|
||||
global.socket = new global.FakeWebSocket();
|
||||
window.TheFakeWebSocket = global.socket;
|
||||
} else {
|
||||
// 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.includes('?') ? '&' : '?') + docParams : '';
|
||||
var websocketURI = global.host + global.serviceRoot + '/lool/' + encodeURIComponent(global.docURL + docParamsPart) + '/ws' + wopiSrc;
|
||||
var websocketURI = global.host + global.serviceRoot + '/lool/';
|
||||
var encodedDocUrl = encodeURIComponent(global.docURL + docParamsPart) + '/ws' + wopiSrc;
|
||||
if (global.hexifyUrl)
|
||||
encodedDocUrl = global.hexEncode(encodedDocUrl);
|
||||
|
||||
websocketURI += encodedDocUrl + '/ws';
|
||||
try {
|
||||
global.socket = global.createWebSocket(websocketURI);
|
||||
} catch (err) {
|
||||
|
|
|
@ -714,6 +714,7 @@ void FileServerRequestHandler::preprocessFile(const HTTPRequest& request,
|
|||
Poco::replaceInPlace(preprocess, std::string("%ACCESS_TOKEN_TTL%"), std::to_string(tokenTtl));
|
||||
Poco::replaceInPlace(preprocess, std::string("%ACCESS_HEADER%"), escapedAccessHeader);
|
||||
Poco::replaceInPlace(preprocess, std::string("%HOST%"), cnxDetails.getWebSocketUrl());
|
||||
Poco::replaceInPlace(preprocess, std::string("%HEXIFY_URL%"), std::string("false"));
|
||||
Poco::replaceInPlace(preprocess, std::string("%VERSION%"), std::string(LOOLWSD_VERSION_HASH));
|
||||
Poco::replaceInPlace(preprocess, std::string("%SERVICE_ROOT%"), responseRoot);
|
||||
Poco::replaceInPlace(preprocess, std::string("%UI_DEFAULTS%"), uiDefaultsToJSON(uiDefaults, userInterfaceMode));
|
||||
|
|
Loading…
Reference in a new issue