[Libreoffice-commits] online.git: loleaflet/src wsd/LOOLWSD.cpp

Pranav Kant pranavk at collabora.co.uk
Wed May 30 13:14:20 UTC 2018


 loleaflet/src/control/Control.AlertDialog.js |   13 -------------
 loleaflet/src/layer/tile/TileLayer.js        |    5 ++++-
 wsd/LOOLWSD.cpp                              |    6 +++++-
 3 files changed, 9 insertions(+), 15 deletions(-)

New commits:
commit 2e21cf5dcdf97d81223711ecae34022f5cabbbd5
Author: Pranav Kant <pranavk at collabora.co.uk>
Date:   Mon May 28 16:33:04 2018 +0530

    loleaflet: Open pdf file in new tab instead of asking to download
    
    new parameter to download POST requests, ?attachment=0 to instruct wsd
    to not set the Content-Disposition header.
    
    Change-Id: Id7694d940e1b4d616263ad720d29f1474164eb68
    Reviewed-on: https://gerrit.libreoffice.org/54918
    Reviewed-by: Jan Holesovsky <kendy at collabora.com>
    Tested-by: Jan Holesovsky <kendy at collabora.com>

diff --git a/loleaflet/src/control/Control.AlertDialog.js b/loleaflet/src/control/Control.AlertDialog.js
index 1d9b9e48c..a87b494f3 100644
--- a/loleaflet/src/control/Control.AlertDialog.js
+++ b/loleaflet/src/control/Control.AlertDialog.js
@@ -8,7 +8,6 @@ L.Control.AlertDialog = L.Control.extend({
 		// TODO: Better distinction between warnings and errors
 		map.on('error', this._onError, this);
 		map.on('warn', this._onError, this);
-		map.on('print', this._onPrint, this);
 	},
 
 	_onError: function(e) {
@@ -33,18 +32,6 @@ L.Control.AlertDialog = L.Control.extend({
 
 		// Remember the current dialog ID to close it later.
 		vex.dialogID = vex.globalID - 1;
-	},
-
-	_onPrint: function (e) {
-		var url = e.url;
-		vex.dialog.confirm({
-			message: _('Download PDF export?'),
-			callback: L.bind(function (value) {
-				if (value) {
-					this._map._fileDownloader.src = url;
-				}
-			}, this)
-		});
 	}
 });
 
diff --git a/loleaflet/src/layer/tile/TileLayer.js b/loleaflet/src/layer/tile/TileLayer.js
index 4b04d1ebf..39586c155 100644
--- a/loleaflet/src/layer/tile/TileLayer.js
+++ b/loleaflet/src/layer/tile/TileLayer.js
@@ -572,7 +572,10 @@ L.TileLayer = L.GridLayer.extend({
 		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
-				this._map.fire('print', {url: url});
+				// due to a pdf.js issue - https://github.com/mozilla/pdf.js/issues/5397
+				// open the pdf file in a new tab so that that user can print it directly in the browser's
+				// pdf viewer
+				window.open(url + '?attachment=0', '_blank');
 			}
 			else {
 				this._map.fire('filedownloadready', {url: url});
diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index d7cb6a473..3bc6d73e6 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -2215,11 +2215,15 @@ private:
             LOG_INF("HTTP request for: " << filePath.toString());
             if (filePath.isAbsolute() && File(filePath).exists())
             {
+                int serveAsAttachment = 1;
+                if (tokens.count() >= 7)
+                    getTokenInteger(tokens[6], "attachment", serveAsAttachment);
+
                 // Instruct browsers to download the file, not display it
                 // with the exception of SVG where we need the browser to
                 // actually show it.
                 std::string contentType = getContentType(fileName);
-                if (contentType != "image/svg+xml")
+                if (serveAsAttachment != 0 && contentType != "image/svg+xml")
                     response.set("Content-Disposition", "attachment; filename=\"" + fileName + "\"");
 
                 try


More information about the Libreoffice-commits mailing list