@@ -34,6 +34,13 @@ window.addEventListener('DOMContentLoaded', function() {
3434		isSecureViewerAvailable : isSecureViewerAvailable ( ) , 
3535	} ) 
3636
37+ 	// If we display a folder, we don't have anything more to do here 
38+ 	if  ( isPublicPage ( )  &&  ! isPdf ( ) )  { 
39+ 		logger . debug ( 'But this is not a single pdf share' ) 
40+ 		return 
41+ 	} 
42+ 
43+ 	// If we display a single PDF and we don't use the richdocument secureViewer 
3744	if  ( isPublicPage ( )  &&  isPdf ( )  &&  ! isSecureViewerAvailable ( ) )  { 
3845		const  page  =  location . hash . split ( 'page=' ) [ 1 ]  ||  0 
3946		const  contentElmt  =  document . getElementById ( 'files-public-content' ) 
@@ -42,7 +49,11 @@ window.addEventListener('DOMContentLoaded', function() {
4249
4350		const  sharingToken  =  sharingTokenElmt . value 
4451		const  downloadUrl  =  generateUrl ( '/s/{token}/download' ,  {  token : sharingToken  } ) 
45- 		const  viewerUrl  =  generateUrl ( '/apps/files_pdfviewer/?file={downloadUrl}#page={page}' ,  {  downloadUrl,  page } ) 
52+ 		const  viewerUrl  =  generateUrl ( '/apps/files_pdfviewer/?file={downloadUrl}&canDownload={canDownload}#page={page}' ,  { 
53+ 			canDownload : canDownload ( )  ? 1  : 0 , 
54+ 			downloadUrl, 
55+ 			page, 
56+ 		} ) 
4657
4758		// Create viewer frame 
4859		const  viewerNode  =  document . createElement ( 'iframe' ) 
@@ -59,46 +70,6 @@ window.addEventListener('DOMContentLoaded', function() {
5970		}  else  { 
6071			logger . error ( 'Unable to inject the PDF Viewer' ) 
6172		} 
62- 
63- 		// When pdf viewer is loaded 
64- 		addEventListener ( 'load' ,  function ( )  { 
65- 			// If we forbid download, prevent interaction 
66- 			if  ( ! canDownload ( ) )  { 
67- 				const  pdfViewer  =  viewerNode . contentDocument . querySelector ( '.pdfViewer' ) 
68- 				const  PDFViewerApplication  =  viewerNode . contentWindow . PDFViewerApplication 
69- 
70- 				if  ( pdfViewer )  { 
71- 					pdfViewer . classList . add ( 'disabledTextSelection' ) 
72- 				} 
73- 
74- 				if  ( PDFViewerApplication )  { 
75- 					// Disable download function when downloads are hidden, as even if the 
76- 					// buttons in the UI are hidden the download could still be triggered 
77- 					// with Ctrl|Meta+S. 
78- 					PDFViewerApplication . download  =  function ( )  { 
79- 					} 
80- 
81- 					// Disable printing service when downloads are hidden, as even if the 
82- 					// buttons in the UI are hidden the printing could still be triggered 
83- 					// with Ctrl|Meta+P. 
84- 					// Abuse the "supportsPrinting" parameter, which signals that the 
85- 					// browser does not fully support printing, to make PDFViewer disable 
86- 					// the printing service. 
87- 					// "supportsPrinting" is a getter function, so it needs to be deleted 
88- 					// before replacing it with a simple value. 
89- 					delete  PDFViewerApplication . supportsPrinting 
90- 					PDFViewerApplication . supportsPrinting  =  false 
91- 
92- 					// When printing is not supported a warning is shown by the default 
93- 					// "beforePrint" function when trying to print. That function needs to 
94- 					// be replaced with an empty one to prevent that warning to be shown. 
95- 					PDFViewerApplication . beforePrint  =  function ( )  { 
96- 					} 
97- 				} 
98- 
99- 				logger . info ( 'Download, printing and user interaction disabled' ) 
100- 			} 
101- 		} ) 
10273	}  else  { 
10374		logger . error ( 'But this does not appear to be a public page' ) 
10475	} 
0 commit comments