Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable18] Prevent download, printing and text selection when download is hidden #181

Merged
merged 5 commits into from
May 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions css/viewer.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
5 changes: 1 addition & 4 deletions js/previewplugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -105,6 +101,7 @@ var isSecureViewerAvailable = function () {
var hideDownload = $('#hideDownload').val();
if (hideDownload === 'true') {
iframe.find('.download').addClass('hidden');
iframe.find('.pdfViewer').addClass('disabledTextSelection')
}
});

Expand Down
25 changes: 25 additions & 0 deletions js/workersrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);