Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/files_pdfviewer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoeland Jago Douma <rullzer@users.noreply.github.com>2020-05-20 13:44:48 +0300
committerGitHub <noreply@github.com>2020-05-20 13:44:48 +0300
commite877ebb10547a1ff59f39b15fcf4ab1eff18eb92 (patch)
treecdfbb1e8b9628a690e638cf2bcc452be54e519b2
parent3473004843eb0da94f6c8cd30038e13fde897285 (diff)
parent4dae7f8ccef373f9ca03afdec0faae9761f50075 (diff)
Merge pull request #180 from nextcloud/backport/179/stable19v19.0.0RC3v19.0.0
[stable19] Prevent download, printing and text selection when download is hidden
-rw-r--r--css/viewer.css21
-rw-r--r--js/previewplugin.js5
-rw-r--r--js/workersrc.js25
3 files changed, 47 insertions, 4 deletions
diff --git a/css/viewer.css b/css/viewer.css
index eca5f53..9d4594c 100644
--- a/css/viewer.css
+++ b/css/viewer.css
@@ -21,3 +21,24 @@ 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;
+ }
+}
+
+/* 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 eb82a16..67835fe 100644
--- a/js/previewplugin.js
+++ b/js/previewplugin.js
@@ -81,10 +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()
- iframe.find('.toolbarButton.print').hide()
- }
if ($('#fileList').length)
{
iframe.find('#secondaryToolbarClose').click(function() {
@@ -105,6 +101,7 @@ var isSecureViewerAvailable = function () {
var hideDownload = $('#hideDownload').val();
if (hideDownload === 'true') {
iframe.find('.download').addClass('hidden');
+ iframe.find('.pdfViewer').addClass('disabledTextSelection')
}
});
diff --git a/js/workersrc.js b/js/workersrc.js
index 1c9b4f0..b9c8e2c 100644
--- a/js/workersrc.js
+++ b/js/workersrc.js
@@ -70,6 +70,31 @@ 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() {
+ }
+
+ // 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() {
+ }
+ }
}
document.addEventListener('webviewerloaded', initializeCustomPDFViewerApplication, true);