diff options
author | Rash419 <rashesh.padia@collabora.com> | 2022-10-11 16:07:46 +0530 |
---|---|---|
committer | Andras Timar <andras.timar@collabora.com> | 2022-10-11 16:02:34 +0200 |
commit | 0e2c5eed2f57220ac4b4a8f37ae2d69626767761 (patch) | |
tree | b65982445710c0f79d9017d39ffe21cc6c0118ae | |
parent | Fix multiple line list within feature_lock dialog (diff) | |
download | online-0e2c5eed2f57220ac4b4a8f37ae2d69626767761.tar.gz online-0e2c5eed2f57220ac4b4a8f37ae2d69626767761.zip |
overriding checkfileinfo using hidden input field
cp-21.11.7-1
wopi host can add following input field to their html to override checkfileinfo, right now only
DownloadAsPostMessage is supported
<input name="checkfileinfo_override" value="DownloadAsPostMessage=true" type="hidden"/>
This can be usefull when same html is used to load collabora online in both desktop browser and mobile webview
Signed-off-by: Rash419 <rashesh.padia@collabora.com>
Change-Id: I8ff122f2824694d451724a832d992e08161fb448
-rw-r--r-- | browser/html/cool.html.m4 | 6 | ||||
-rw-r--r-- | browser/src/map/handler/Map.WOPI.js | 4 | ||||
-rw-r--r-- | wsd/FileServer.cpp | 4 | ||||
-rw-r--r-- | wsd/FileServer.hpp | 2 | ||||
-rw-r--r-- | wsd/FileServerUtil.cpp | 29 |
5 files changed, 42 insertions, 3 deletions
diff --git a/browser/html/cool.html.m4 b/browser/html/cool.html.m4 index ea8269db8f..15e0584faa 100644 --- a/browser/html/cool.html.m4 +++ b/browser/html/cool.html.m4 @@ -312,7 +312,8 @@ m4_ifelse(MOBILEAPP,[true], window.socketProxy = false; window.tileSize = 256; window.uiDefaults = {}; - window.useIntegrationTheme = 'false';], + window.useIntegrationTheme = 'false'; + window.checkFileInfoOverride = {};], [window.host = '%HOST%'; window.serviceRoot = '%SERVICE_ROOT%'; window.hexifyUrl = %HEXIFY_URL%; @@ -336,7 +337,8 @@ m4_ifelse(MOBILEAPP,[true], window.socketProxy = %SOCKET_PROXY%; window.tileSize = 256; window.groupDownloadAsForNb = %GROUP_DOWNLOAD_AS%; - window.uiDefaults = %UI_DEFAULTS%;]) + window.uiDefaults = %UI_DEFAULTS%; + window.checkFileInfoOverride = %CHECK_FILE_INFO_OVERRIDE%;]) // This is GLOBAL_JS: m4_syscmd([cat ]GLOBAL_JS)m4_dnl diff --git a/browser/src/map/handler/Map.WOPI.js b/browser/src/map/handler/Map.WOPI.js index 97d056a148..85b8269453 100644 --- a/browser/src/map/handler/Map.WOPI.js +++ b/browser/src/map/handler/Map.WOPI.js @@ -93,6 +93,7 @@ L.Map.WOPI = L.Handler.extend({ }, _setWopiProps: function(wopiInfo) { + var overridenFileInfo = window.checkFileInfoOverride; // Store postmessageorigin property, if it exists if (wopiInfo['PostMessageOrigin']) { this.PostMessageOrigin = wopiInfo['PostMessageOrigin']; @@ -110,7 +111,8 @@ L.Map.WOPI = L.Handler.extend({ this.DisableExport = !!wopiInfo['DisableExport']; this.DisableCopy = !!wopiInfo['DisableCopy']; this.DisableInactiveMessages = !!wopiInfo['DisableInactiveMessages']; - this.DownloadAsPostMessage = !!wopiInfo['DownloadAsPostMessage']; + this.DownloadAsPostMessage = Object.prototype.hasOwnProperty.call(overridenFileInfo, 'DownloadAsPostMessage') ? + overridenFileInfo.DownloadAsPostMessage : !!wopiInfo['DownloadAsPostMessage']; this.UserCanNotWriteRelative = !!wopiInfo['UserCanNotWriteRelative']; this.EnableInsertRemoteImage = !!wopiInfo['EnableInsertRemoteImage']; this.SupportsRename = !!wopiInfo['SupportsRename']; diff --git a/wsd/FileServer.cpp b/wsd/FileServer.cpp index 546447fe62..05af744c54 100644 --- a/wsd/FileServer.cpp +++ b/wsd/FileServer.cpp @@ -897,6 +897,8 @@ void FileServerRequestHandler::preprocessFile(const HTTPRequest& request, LOG_TRC("postmessage_origin" << postMessageOrigin); const std::string theme = form.get("theme", ""); LOG_TRC("theme=" << theme); + const std::string checkfileinfo_override = form.get("checkfileinfo_override", ""); + LOG_TRC("checkfileinfo_override=" << checkfileinfo_override); // Escape bad characters in access token. // This is placed directly in javascript in cool.html, we need to make sure @@ -943,6 +945,8 @@ void FileServerRequestHandler::preprocessFile(const HTTPRequest& request, Poco::replaceInPlace(preprocess, std::string("%SERVICE_ROOT%"), responseRoot); Poco::replaceInPlace(preprocess, std::string("%UI_DEFAULTS%"), uiDefaultsToJSON(uiDefaults, userInterfaceMode)); Poco::replaceInPlace(preprocess, std::string("%POSTMESSAGE_ORIGIN%"), escapedPostmessageOrigin); + Poco::replaceInPlace(preprocess, std::string("%CHECK_FILE_INFO_OVERRIDE%"), + checkFileInfoToJSON(checkfileinfo_override)); const auto& config = Application::instance().config(); diff --git a/wsd/FileServer.hpp b/wsd/FileServer.hpp index 4a46cdd4e2..5f362a3d69 100644 --- a/wsd/FileServer.hpp +++ b/wsd/FileServer.hpp @@ -39,6 +39,8 @@ class FileServerRequestHandler /// Also returns the UIMode from uiDefaults in uiMode output param static std::string uiDefaultsToJSON(const std::string& uiDefaults, std::string& uiMode); + static std::string checkFileInfoToJSON(const std::string& checkfileFileInfo); + static std::string cssVarsToStyle(const std::string& cssVars); static std::string stringifyBoolFromConfig(const Poco::Util::LayeredConfiguration& config, diff --git a/wsd/FileServerUtil.cpp b/wsd/FileServerUtil.cpp index 559e0cc238..57e33ff949 100644 --- a/wsd/FileServerUtil.cpp +++ b/wsd/FileServerUtil.cpp @@ -124,6 +124,35 @@ std::string FileServerRequestHandler::uiDefaultsToJSON(const std::string& uiDefa return previousJSON; } +std::string FileServerRequestHandler::checkFileInfoToJSON(const std::string& checkfileInfo) +{ + static std::string previousCheckFileInfo; + static std::string previousCheckFileInfoJSON("{}"); + + // early exit if we are serving the same thing + if (checkfileInfo == previousCheckFileInfo) + return previousCheckFileInfoJSON; + + Poco::JSON::Object json; + StringVector tokens(StringVector::tokenize(checkfileInfo, ';')); + for (const auto& token : tokens) + { + StringVector keyValue(StringVector::tokenize(tokens.getParam(token), '=')); + if (keyValue.equals(0, "DownloadAsPostMessage")) + { + bool value(false); + if (keyValue.equals(1, "true") || keyValue.equals(1, "True") || keyValue.equals(1, "1")) + value = true; + json.set(keyValue[0], value); + } + } + std::ostringstream oss; + Poco::JSON::Stringifier::stringify(json, oss); + previousCheckFileInfo = checkfileInfo; + previousCheckFileInfoJSON = oss.str(); + return previousCheckFileInfoJSON; +} + namespace { bool isValidCss(const std::string& token) |