Skip to content

Conversation

@danxuliu
Copy link
Member

@danxuliu danxuliu commented May 13, 2020

Please refer to the commit messages for details.

How to test

  • Open the files app
  • Create a public link share for a PDF file
  • Hide the download of the share
  • Open the link

Results with this pull request

It is not possible to download or print the file, and it is not possible to select the text (of course it is possible to do all that if you know how, but not with the "normal" ways).

Results with this pull request

It is possible to download the file using Ctrl+S, it is possible to print the file using Ctrl+P or making the window smaller so the Print button appears in the >> menu, it is possible to print the file by printing the full page or the frame from the browser, and it is possible to select the text of the PDF.

@danxuliu
Copy link
Member Author

/backport to stable19

@danxuliu
Copy link
Member Author

/backport to stable18

@danxuliu
Copy link
Member Author

/backport to stable17

@danxuliu danxuliu changed the title Prevent text selection when download is hidden Prevent text selection and printing from browser when download is hidden May 13, 2020
@danxuliu
Copy link
Member Author

Sorry, there is still a missing case (printing through Ctrl+P), please do not review yet :-)

danxuliu added 5 commits May 15, 2020 00:58
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 <danxuliu@gmail.com>
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 <danxuliu@gmail.com>
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 <danxuliu@gmail.com>
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 <danxuliu@gmail.com>
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 <danxuliu@gmail.com>
@danxuliu danxuliu force-pushed the prevent-text-selection-when-download-is-hidden branch from 999d885 to 041a36c Compare May 14, 2020 23:38
@danxuliu danxuliu changed the title Prevent text selection and printing from browser when download is hidden Prevent download, printing and text selection when download is hidden May 14, 2020
@danxuliu
Copy link
Member Author

Ready for review! :-)

@timm2k
Copy link

timm2k commented May 15, 2020

Can confirm that these changes work like expected with Nextcloud 18.0.4.
(Some more work is needed to disable keyboard shortcuts.)

@danxuliu
Copy link
Member Author

(Some more work is needed to disable keyboard shortcuts.)

Downloading with Ctrl+S and printing with Ctrl+P should already be prevented in the latest version of this patch. Are there other shortcuts that need to be prevented too? Or do they still work in a specific browser?

Thanks for the information :-)

@timm2k
Copy link

timm2k commented May 20, 2020

Sorry, I have not seen your changes to workersrc.js when I accessed this PR first time. Everything is fine now!

@danxuliu
Copy link
Member Author

Sorry, I have not seen your changes to workersrc.js when I accessed this PR first time. Everything is fine now!

Thanks for the confirmation :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants