From 7401deff5c7ecd6ee1a50b65dd673ca4b49b2a63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Calvi=C3=B1o=20S=C3=A1nchez?= Date: Fri, 15 May 2020 00:49:46 +0200 Subject: Prevent download through shortcuts when download is hidden MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Even if the Download buttons are hidden in the toolbars it was still possible to trigger the download by using Ctrl|Meta+S. This directly calls the "PDFViewerApplication.download" function, so when downloads are hidden that function is now replaced with an empty function. Signed-off-by: Daniel Calviño Sánchez --- js/workersrc.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/js/workersrc.js b/js/workersrc.js index 1c9b4f0..4c089f9 100644 --- a/js/workersrc.js +++ b/js/workersrc.js @@ -70,6 +70,15 @@ function initializeCustomPDFViewerApplication() { this.downloadManager.downloadUrl(url, getPDFFileNameFromURL(url)); }; + + var hideDownload = window.parent.document.getElementById('hideDownload').value === 'true'; + if (hideDownload) { + // Disable download function when downloads are hidden, as even if the + // buttons in the UI are hidden the download could still be triggered + // with Ctrl|Meta+S. + PDFViewerApplication.download = function() { + } + } } document.addEventListener('webviewerloaded', initializeCustomPDFViewerApplication, true); -- cgit v1.2.3 From de48b5726dcec9f4508e6f94af8d9b5edb462927 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Calvi=C3=B1o=20S=C3=A1nchez?= Date: Fri, 15 May 2020 01:03:33 +0200 Subject: Prevent printing through shortcuts when download is hidden MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Even if the Print button was hidden in the toolbar it was still possible to trigger the printing by using Ctrl|Meta+P. This uses the print service from PDFViewer, so when the download is hidden the print service is now disabled. When printing is flagged as not supported in the PDFViewerApplication initialization the Print buttons are disabled, so it is no longer needed to disable them explicity. Moreover, this also fixes the Print button being disabled only in the toolbar, but not in the secondary toolbar (which is shown in smaller screens). Signed-off-by: Daniel Calviño Sánchez --- js/previewplugin.js | 1 - js/workersrc.js | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/js/previewplugin.js b/js/previewplugin.js index eb82a16..74a1d7c 100644 --- a/js/previewplugin.js +++ b/js/previewplugin.js @@ -83,7 +83,6 @@ var isSecureViewerAvailable = function () { var iframe = $('#pdframe').contents(); if ($('#hideDownload').val() === 'true') { iframe.find('.toolbarButton.download').hide() - iframe.find('.toolbarButton.print').hide() } if ($('#fileList').length) { diff --git a/js/workersrc.js b/js/workersrc.js index 4c089f9..b9c8e2c 100644 --- a/js/workersrc.js +++ b/js/workersrc.js @@ -78,6 +78,22 @@ function initializeCustomPDFViewerApplication() { // with Ctrl|Meta+S. PDFViewerApplication.download = function() { } + + // Disable printing service when downloads are hidden, as even if the + // buttons in the UI are hidden the printing could still be triggered + // with Ctrl|Meta+P. + // Abuse the "supportsPrinting" parameter, which signals that the + // browser does not fully support printing, to make PDFViewer disable + // the printing service. + // "supportsPrinting" is a getter function, so it needs to be deleted + // before replacing it with a simple value. + delete PDFViewerApplication.supportsPrinting; + PDFViewerApplication.supportsPrinting = false; + // When printing is not supported a warning is shown by the default + // "beforePrint" function when trying to print. That function needs to + // be replaced with an empty one to prevent that warning to be shown. + PDFViewerApplication.beforePrint = function() { + } } } -- cgit v1.2.3 From 1c74c078f33525814a97e2e8598921956e5cad06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Calvi=C3=B1o=20S=C3=A1nchez?= Date: Fri, 15 May 2020 01:16:35 +0200 Subject: Remove redundant code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The Download button is hidden in both the toolbar and the secondary toolbar later, so it is not needed to hide it only for the toolbar first. Signed-off-by: Daniel Calviño Sánchez --- js/previewplugin.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/js/previewplugin.js b/js/previewplugin.js index 74a1d7c..8e56124 100644 --- a/js/previewplugin.js +++ b/js/previewplugin.js @@ -81,9 +81,6 @@ var isSecureViewerAvailable = function () { // if a filelist is present, the PDF viewer can be closed to go back there $('#pdframe').load(function(){ var iframe = $('#pdframe').contents(); - if ($('#hideDownload').val() === 'true') { - iframe.find('.toolbarButton.download').hide() - } if ($('#fileList').length) { iframe.find('#secondaryToolbarClose').click(function() { -- cgit v1.2.3 From b6dd29615ea021af91c8c47adf1c63d010f588e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Calvi=C3=B1o=20S=C3=A1nchez?= Date: Wed, 13 May 2020 21:39:33 +0200 Subject: Prevent printing from the browser when download is hidden MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Even if printing was not possible using the PDFViewer printing services it was still possible to print the PDF document by printing the web page from the browser. As that can not be really prevented the best that can be done is hide all the content in the printed media using CSS. Signed-off-by: Daniel Calviño Sánchez --- css/viewer.css | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/css/viewer.css b/css/viewer.css index eca5f53..297a8a7 100644 --- a/css/viewer.css +++ b/css/viewer.css @@ -21,3 +21,11 @@ html .doorHangerRight:after { html .doorHangerRight:before { right: 53px!important; } + +/* Prevent printing from the browser when the download of a share is hidden. */ +@media print { + .pdfViewer.disabledTextSelection { + visibility: hidden; + display: none; + } +} -- cgit v1.2.3 From 4100a2900a9d0aa683606bbeed0f779dbf5add15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Calvi=C3=B1o=20S=C3=A1nchez?= Date: Wed, 13 May 2020 21:25:47 +0200 Subject: Prevent text selection when download is hidden MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When the PDF is rendered PDFViewer creates canvases with the contents of the pages and, in front of them, it creates too a layer with HTML text elements that makes possible to select it. That text layer is used too by the search function to highlight the results, so it can not be removed. Instead of that the selection of the text is prevented using CSS. Signed-off-by: Daniel Calviño Sánchez --- css/viewer.css | 13 +++++++++++++ js/previewplugin.js | 1 + 2 files changed, 14 insertions(+) diff --git a/css/viewer.css b/css/viewer.css index 297a8a7..9d4594c 100644 --- a/css/viewer.css +++ b/css/viewer.css @@ -29,3 +29,16 @@ html .doorHangerRight:before { display: none; } } + +/* Prevent text selection when the download of a share is hidden. */ +.pdfViewer.disabledTextSelection .textLayer { + user-select: none; + -moz-user-select: none; + -webkit-user-select: none; + -ms-user-select: none; +} + +/* Override text cursor in descendants. */ +.pdfViewer.disabledTextSelection .textLayer * { + cursor: default; +} diff --git a/js/previewplugin.js b/js/previewplugin.js index 8e56124..67835fe 100644 --- a/js/previewplugin.js +++ b/js/previewplugin.js @@ -101,6 +101,7 @@ var isSecureViewerAvailable = function () { var hideDownload = $('#hideDownload').val(); if (hideDownload === 'true') { iframe.find('.download').addClass('hidden'); + iframe.find('.pdfViewer').addClass('disabledTextSelection') } }); -- cgit v1.2.3