[Libreoffice-commits] online.git: Branch 'distro/collabora/collabora-online-3' - loleaflet/src wsd/LOOLWSD.cpp

2018-06-28 Thread Pranav Kant
 loleaflet/src/layer/tile/TileLayer.js |4 +++-
 wsd/LOOLWSD.cpp   |   16 
 2 files changed, 15 insertions(+), 5 deletions(-)

New commits:
commit 2faf8f590b2e1d394188d035ab713ac021473da6
Author: Pranav Kant 
Date:   Wed Jun 27 19:53:25 2018 +0530

wsd: in case of multiple query param, handle = correctly

In case of integration with OC/NC, we have WOPISrc= as query param used
for load balancing. So, the earlier approach failed with integration.

Change-Id: Ib73f4f18eaec870dd53b67886b1b6016416a2e78
Reviewed-on: https://gerrit.libreoffice.org/56533
Reviewed-by: Jan Holesovsky 
Tested-by: Jan Holesovsky 

diff --git a/loleaflet/src/layer/tile/TileLayer.js 
b/loleaflet/src/layer/tile/TileLayer.js
index 711eb2ef9..35d33fd1d 100644
--- a/loleaflet/src/layer/tile/TileLayer.js
+++ b/loleaflet/src/layer/tile/TileLayer.js
@@ -566,7 +566,9 @@ L.TileLayer = L.GridLayer.extend({
// 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');
+   var param = wopiSrc !== '' ? '&' : '?';
+   param += 'attachment=0';
+   window.open(url + param, '_blank');
}
else {
this._map.fire('filedownloadready', {url: url});
diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index 48e915ab8..ee4f83b2a 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -2163,15 +2163,23 @@ 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);
+const Poco::URI postRequestUri(request.getURI());
+const Poco::URI::QueryParameters postRequestQueryParams = 
postRequestUri.getQueryParameters();
+
+bool serveAsAttachment = true;
+const auto attachmentIt = 
std::find_if(postRequestQueryParams.begin(),
+   
postRequestQueryParams.end(),
+   [](const 
std::pair& element) {
+   return 
element.first == "attachment";
+   });
+if (attachmentIt != postRequestQueryParams.end())
+serveAsAttachment = attachmentIt->second != "0";
 
 // 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 (serveAsAttachment != 0 && contentType != "image/svg+xml")
+if (serveAsAttachment && contentType != "image/svg+xml")
 response.set("Content-Disposition", "attachment; 
filename=\"" + fileName + "\"");
 
 try
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits


[Libreoffice-commits] online.git: Branch 'distro/collabora/collabora-online-3' - loleaflet/src wsd/LOOLWSD.cpp

2018-05-29 Thread Pranav Kant
 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 309e53cba404301407ef5b1851c52090565fd7f2
Author: Pranav Kant 
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/54919
Reviewed-by: Jan Holesovsky 
Tested-by: Jan Holesovsky 

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 49aa853c6..ebf953302 100644
--- a/loleaflet/src/layer/tile/TileLayer.js
+++ b/loleaflet/src/layer/tile/TileLayer.js
@@ -560,7 +560,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 4831aea33..3b645fe8f 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -2166,11 +2166,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
___
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits