From 34f4edfc7f5c428c12425c2227c39de43b4fa9a5 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 af9067d6f827fedd71d059cf81e8cf6e21ea8771 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 when download is hidden MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Printing with the Print button from the toolbar as well as through Ctrl|Meta+P 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 not needed to disable them explicity. Signed-off-by: Daniel Calviño Sánchez --- js/workersrc.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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 35997bf079750784e921444d20ded6823123c986 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 cd7eedd05b4f96376551c86821cc25b4616894bb 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 ad3b338..5f7646d 100644 --- a/js/previewplugin.js +++ b/js/previewplugin.js @@ -97,6 +97,7 @@ var hideDownload = $('#hideDownload').val(); if (hideDownload === 'true') { iframe.find('.download').addClass('hidden'); + iframe.find('.pdfViewer').addClass('disabledTextSelection') } }); -- cgit v1.2.3