[Libreoffice-commits] online.git: loleaflet/reference.html loleaflet/src wsd/DocumentBroker.cpp wsd/reference.md wsd/Storage.cpp wsd/Storage.hpp

Jan Holesovsky (via logerrit) logerrit at kemper.freedesktop.org
Tue Jun 4 12:54:57 UTC 2019


 loleaflet/reference.html              |   18 ++++++++++++++++++
 loleaflet/src/layer/tile/TileLayer.js |    5 ++++-
 loleaflet/src/map/handler/Map.WOPI.js |    2 ++
 wsd/DocumentBroker.cpp                |    1 +
 wsd/Storage.cpp                       |    4 +++-
 wsd/Storage.hpp                       |    6 ++++++
 wsd/reference.md                      |    7 +++++++
 7 files changed, 41 insertions(+), 2 deletions(-)

New commits:
commit 3c45a0abab883dadc8d1733f24bff36150648c88
Author:     Jan Holesovsky <kendy at collabora.com>
AuthorDate: Tue Jun 4 13:57:53 2019 +0200
Commit:     Jan Holesovsky <kendy at collabora.com>
CommitDate: Tue Jun 4 14:54:36 2019 +0200

    Introduce Download_As postmessage & a CheckFileInfo entry to enables that.
    
    The Download_As is emitted when the user chooses 'Print' or 'Show
    slideshow' or 'Download As [some type'] and the integration indicates
    via DownloadAsPostMessage in the CheckFileInfo that it wants to handle
    the downloading of pdf for printing or svg for slideshows or experted
    document.
    
    This is particularly useful in situations when the integration cannot
    rely on browser's support for downloading like in mobile apps that use
    the Online in a WebView.
    
    Change-Id: Iefdf214937c0c0dafd7462340a1c5e88df94e716
    Reviewed-on: https://gerrit.libreoffice.org/73449
    Reviewed-by: Jan Holesovsky <kendy at collabora.com>
    Tested-by: Jan Holesovsky <kendy at collabora.com>

diff --git a/loleaflet/reference.html b/loleaflet/reference.html
index b0f62caaf..27f969bfd 100644
--- a/loleaflet/reference.html
+++ b/loleaflet/reference.html
@@ -3240,6 +3240,24 @@ Note that they usually don't change but there is no guarantee that they are stab
 		</td>
 	</tr>
 	<tr>
+		<td><code><b>Download_As</b></code></td>
+		<td><code>
+			<nobr>Type: 'print'|'slideshow'|'export'</nobr><br/>
+			<nobr>URL: <string></nobr><br/>
+		</code></td>
+		<td>
+		  This event is emitted when the user chooses 'Print' or 'Show
+		  slideshow' or 'Download As [some type'] and the integration
+		  indicates via DownloadAsPostMessage in the CheckFileInfo that it
+		  wants to handle the downloading of pdf for printing or svg for
+		  slideshows or experted document.
+
+		  This is in situations when the integration cannot rely on browser's
+		  support for downloading like in mobile apps that use the Online in
+		  a WebView.
+		</td>
+	</tr>
+	<tr>
 		<td><code><b>UI_CreateFile</b></code></td>
 		<td></td>
 		<td>
diff --git a/loleaflet/src/layer/tile/TileLayer.js b/loleaflet/src/layer/tile/TileLayer.js
index 6dc66544e..b936cad94 100644
--- a/loleaflet/src/layer/tile/TileLayer.js
+++ b/loleaflet/src/layer/tile/TileLayer.js
@@ -583,7 +583,10 @@ L.TileLayer = L.GridLayer.extend({
 		    encodeURIComponent(this._map.options.doc) + '/' + command.jail + '/' + command.dir + '/' + command.name + wopiSrc;
 
 		this._map.hideBusy();
-		if (command.id === 'print') {
+		if (this._map['wopi'].DownloadAsPostMessage) {
+			this._map.fire('postMessage', {msgId: 'Download_As', args: {Type: command.id, URL: url}});
+		}
+		else if (command.id === 'print') {
 			if (L.Browser.gecko || L.Browser.edge || this._map.options.print === false) {
 				// the print dialog doesn't work well on firefox
 				// due to a pdf.js issue - https://github.com/mozilla/pdf.js/issues/5397
diff --git a/loleaflet/src/map/handler/Map.WOPI.js b/loleaflet/src/map/handler/Map.WOPI.js
index bff0a062f..97b4c7176 100644
--- a/loleaflet/src/map/handler/Map.WOPI.js
+++ b/loleaflet/src/map/handler/Map.WOPI.js
@@ -19,6 +19,7 @@ L.Map.WOPI = L.Handler.extend({
 	DisableExport: false,
 	DisableCopy: false,
 	DisableInactiveMessages: false,
+	DownloadAsPostMessage: false,
 	UserCanNotWriteRelative: true,
 	EnableInsertRemoteImage: false,
 	EnableShare: false,
@@ -83,6 +84,7 @@ L.Map.WOPI = L.Handler.extend({
 		this.DisableExport = !!wopiInfo['DisableExport'];
 		this.DisableCopy = !!wopiInfo['DisableCopy'];
 		this.DisableInactiveMessages = !!wopiInfo['DisableInactiveMessages'];
+		this.DownloadAsPostMessage = !!wopiInfo['DownloadAsPostMessage'];
 		this.UserCanNotWriteRelative = !!wopiInfo['UserCanNotWriteRelative'];
 		this.EnableInsertRemoteImage = !!wopiInfo['EnableInsertRemoteImage'];
 		this.SupportsRename = !!wopiInfo['SupportsRename'];
diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index fefe15ccd..e45f6bff0 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -570,6 +570,7 @@ bool DocumentBroker::load(const std::shared_ptr<ClientSession>& session, const s
         wopiInfo->set("DisableExport", wopifileinfo->getDisableExport());
         wopiInfo->set("DisableCopy", wopifileinfo->getDisableCopy());
         wopiInfo->set("DisableInactiveMessages", wopifileinfo->getDisableInactiveMessages());
+        wopiInfo->set("DownloadAsPostMessage", wopifileinfo->getDownloadAsPostMessage());
         wopiInfo->set("UserCanNotWriteRelative", wopifileinfo->getUserCanNotWriteRelative());
         wopiInfo->set("EnableInsertRemoteImage", wopifileinfo->getEnableInsertRemoteImage());
         wopiInfo->set("EnableShare", wopifileinfo->getEnableShare());
diff --git a/wsd/Storage.cpp b/wsd/Storage.cpp
index d29bbaa63..4b914ca2a 100644
--- a/wsd/Storage.cpp
+++ b/wsd/Storage.cpp
@@ -495,6 +495,7 @@ std::unique_ptr<WopiStorage::WOPIFileInfo> WopiStorage::getWOPIFileInfo(const Au
     bool disableExport = false;
     bool disableCopy = false;
     bool disableInactiveMessages = false;
+    bool downloadAsPostMessage = false;
     std::string lastModifiedTime;
     bool userCanNotWriteRelative = true;
     bool enableInsertRemoteImage = false;
@@ -582,6 +583,7 @@ std::unique_ptr<WopiStorage::WOPIFileInfo> WopiStorage::getWOPIFileInfo(const Au
         JsonUtil::findJSONValue(object, "DisableExport", disableExport);
         JsonUtil::findJSONValue(object, "DisableCopy", disableCopy);
         JsonUtil::findJSONValue(object, "DisableInactiveMessages", disableInactiveMessages);
+        JsonUtil::findJSONValue(object, "DownloadAsPostMessage", downloadAsPostMessage);
         JsonUtil::findJSONValue(object, "LastModifiedTime", lastModifiedTime);
         JsonUtil::findJSONValue(object, "UserCanNotWriteRelative", userCanNotWriteRelative);
         JsonUtil::findJSONValue(object, "EnableInsertRemoteImage", enableInsertRemoteImage);
@@ -616,7 +618,7 @@ std::unique_ptr<WopiStorage::WOPIFileInfo> WopiStorage::getWOPIFileInfo(const Au
         {userId, obfuscatedUserId, userName, userExtraInfo, watermarkText, templateSaveAs, canWrite,
          postMessageOrigin, hidePrintOption, hideSaveOption, hideExportOption,
          enableOwnerTermination, disablePrint, disableExport, disableCopy,
-         disableInactiveMessages, userCanNotWriteRelative, enableInsertRemoteImage, enableShare,
+         disableInactiveMessages, downloadAsPostMessage, userCanNotWriteRelative, enableInsertRemoteImage, enableShare,
          hideUserList, disableChangeTrackingShow, disableChangeTrackingRecord,
          hideChangeTrackingControls, supportsRename, userCanRename, callDuration}));
 }
diff --git a/wsd/Storage.hpp b/wsd/Storage.hpp
index 02539b8f1..6bfac902a 100644
--- a/wsd/Storage.hpp
+++ b/wsd/Storage.hpp
@@ -322,6 +322,7 @@ public:
                      const bool disableExport,
                      const bool disableCopy,
                      const bool disableInactiveMessages,
+                     const bool downloadAsPostMessage,
                      const bool userCanNotWriteRelative,
                      const bool enableInsertRemoteImage,
                      const bool enableShare,
@@ -347,6 +348,7 @@ public:
               _disableExport(disableExport),
               _disableCopy(disableCopy),
               _disableInactiveMessages(disableInactiveMessages),
+              _downloadAsPostMessage(downloadAsPostMessage),
               _userCanNotWriteRelative(userCanNotWriteRelative),
               _enableInsertRemoteImage(enableInsertRemoteImage),
               _enableShare(enableShare),
@@ -395,6 +397,8 @@ public:
 
         bool getDisableInactiveMessages() const { return _disableInactiveMessages; }
 
+        bool getDownloadAsPostMessage() const { return _downloadAsPostMessage; }
+
         bool getUserCanNotWriteRelative() const { return _userCanNotWriteRelative; }
 
         bool getEnableInsertRemoteImage() const { return _enableInsertRemoteImage; }
@@ -448,6 +452,8 @@ public:
         bool _disableCopy;
         /// If WOPI host has allowed the loleaflet to show texts on the overlay informing about inactivity, or if the integration is handling that.
         bool _disableInactiveMessages;
+        /// For the (mobile) integrations, to indicate that the downloading for printing, exporting or slideshows should be intercepted and sent as a postMessage instead of handling directly.
+        bool _downloadAsPostMessage;
         /// If set to false, users can access the save-as functionality
         bool _userCanNotWriteRelative;
         /// If set to true, users can access the insert remote image functionality
diff --git a/wsd/reference.md b/wsd/reference.md
index fdcd0c121..a0163dd80 100644
--- a/wsd/reference.md
+++ b/wsd/reference.md
@@ -98,6 +98,13 @@ Disables copying from the document in libreoffice online backend. Pasting into t
 ### DisableInactiveMessages
 Disables displaying of the explanation text on the overlay when the document becomes inactive or killed.  With this, the JS integration must provide the user with appropriate message when it gets Session_Closed or User_Idle postMessage's.
 
+### DownloadAsPostMessage
+Indicate that the integration wants to handle the downloading of pdf for printing or svg for slideshows or experted document, because it cannot rely on browser's support for downloading.
+
+When this is set to true, the user's eg. Print action will trigger a postMessage called Download_As, with the following JSON in the Values:
+
+    { Type: 'print'|'slideshow'|'export', URL: ...url you use for the actual downloading... }
+
 ### EnableOwnerTermination
 If set to true, it allows the document owner (the one with OwnerId =UserId) to send a 'closedocument' message (see protocol.txt)
 


More information about the Libreoffice-commits mailing list