Skip to content
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
5 changes: 5 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
module.exports = {
globals: {
PDFViewerApplicationOptions: true,
PDFViewerApplication: true,
pdfjsLib: true,
},
extends: [
'@nextcloud',
]
Expand Down
8 changes: 0 additions & 8 deletions css/viewer.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,6 @@
}
}

html .doorHangerRight:after {
right: 53px!important;
}

html .doorHangerRight:before {
right: 53px!important;
}

/* Prevent printing from the browser when the download of a share is hidden. */
@media print {
.pdfViewer.disabledTextSelection {
Expand Down
6 changes: 3 additions & 3 deletions js/files_pdfviewer-main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/files_pdfviewer-main.js.map

Large diffs are not rendered by default.

91 changes: 88 additions & 3 deletions js/files_pdfviewer-public.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/files_pdfviewer-public.js.map

Large diffs are not rendered by default.

46 changes: 44 additions & 2 deletions js/files_pdfviewer-workersrc.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion js/files_pdfviewer-workersrc.js.map

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
"@nextcloud/dialogs": "^1.4.0",
"@nextcloud/router": "^1.1.0",
"@nextcloud/vue": "^1.5.0",
"pdf.js": "git://github.com/mozilla/pdf.js.git#v2.4.456",
"pdfjs-dist": "^2.4.456",
"vue": "^2.6.11"
},
Expand Down
20 changes: 10 additions & 10 deletions src/public.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

/**
* @copyright Copyright (c) 2020 John Molakvoæ <skjnldsv@protonmail.com>
*
Expand All @@ -22,17 +21,18 @@
*/
import { generateUrl } from '@nextcloud/router'

const hideDownloadElmt = document.getElementById('hideDownload')
const isPublicElmt = document.getElementById('isPublic')
const mimetypeElmt = document.getElementById('mimetype')

const isSecureViewerAvailable = function() {
return hideDownloadElmt && hideDownloadElmt.value === 'true' && typeof OCA.RichDocuments !== 'undefined'
}
import canDownload from './utils/canDownload'
import isPublicPage from './utils/isPublicPage'
import isPdf from './utils/isPdf'
import isSecureViewerAvailable from './utils/isSecureViewerAvailable'

window.addEventListener('DOMContentLoaded', function() {
if (isPublicElmt && isPublicElmt.value && mimetypeElmt && mimetypeElmt.value === 'application/pdf' && !isSecureViewerAvailable()) {
console.debug('Files_PDFViewer initiamized for public page')
if (isPublicPage() && isPdf() && !isSecureViewerAvailable()) {
console.debug('Files_PDFViewer initialized for public page', {
isPublicPage: isPublicPage(),
canDownload: canDownload(),
isSecureViewerAvailable: isSecureViewerAvailable(),
})

const page = location.hash.split('page=')[1] || 0
const contentElmt = document.getElementById('files-public-content')
Expand Down
26 changes: 26 additions & 0 deletions src/utils/canDownload.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

/**
* @copyright Copyright (c) 2020 John Molakvoæ <skjnldsv@protonmail.com>
*
* @author John Molakvoæ <skjnldsv@protonmail.com>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

const hideDownloadElmt = document.getElementById('hideDownload')
// true = hidden download
export default () => hideDownloadElmt && hideDownloadElmt.value !== 'true'
25 changes: 25 additions & 0 deletions src/utils/isPdf.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

/**
* @copyright Copyright (c) 2020 John Molakvoæ <skjnldsv@protonmail.com>
*
* @author John Molakvoæ <skjnldsv@protonmail.com>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

const mimetypeElmt = document.getElementById('mimetype')
export default () => mimetypeElmt && mimetypeElmt.value === 'application/pdf'
25 changes: 25 additions & 0 deletions src/utils/isPublicPage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

/**
* @copyright Copyright (c) 2020 John Molakvoæ <skjnldsv@protonmail.com>
*
* @author John Molakvoæ <skjnldsv@protonmail.com>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

const isPublicElmt = document.getElementById('isPublic')
export default () => isPublicElmt && isPublicElmt.value === '1'
25 changes: 25 additions & 0 deletions src/utils/isSecureViewerAvailable.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

/**
* @copyright Copyright (c) 2020 John Molakvoæ <skjnldsv@protonmail.com>
*
* @author John Molakvoæ <skjnldsv@protonmail.com>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
import canDownload from './canDownload'

export default () => canDownload() && typeof OCA.RichDocuments !== 'undefined'
29 changes: 29 additions & 0 deletions src/utils/redirectIfNotIframe.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* @copyright Copyright (c) 2020 John Molakvoæ <skjnldsv@protonmail.com>
*
* @author John Molakvoæ <skjnldsv@protonmail.com>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
export default function() {
// Not within iframe
if (window.location !== window.parent.location) {
return
}

window.location.href = '/'
}
54 changes: 39 additions & 15 deletions src/workersrc.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,34 @@
/* eslint-disable no-undef */

/**
* @copyright Copyright (c) 2020 Daniel Calviño Sánchez <danxuliu@gmail.com>
*
* @author Daniel Calviño Sánchez <danxuliu@gmail.com>
* @author John Molakvoæ <skjnldsv@protonmail.com>
*
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

import canDownload from './utils/canDownload'
import redirectIfNotIframe from './utils/redirectIfNotIframe'

/**
* Checks if the page is displayed in an iframe. If not redirect to /.
**/
function redirectIfNotDisplayedInFrame() {
try {
if (window.frameElement) {
return
}
} catch (e) {
console.debug(e)
}

window.location.href = '/'
}
redirectIfNotDisplayedInFrame()
redirectIfNotIframe()

// When "PDFViewerApplication.webViewerInitialized" is executed (once
// "PDFViewerApplication.initialize" is done) it opens the PDF file via URL,
Expand Down Expand Up @@ -76,13 +91,16 @@ function initializeCustomPDFViewerApplication() {
this.downloadManager.downloadUrl(url, getPDFFileNameFromURL(url))
}

const hideDownload = window.parent.document.getElementById('hideDownload').value === 'true'
if (hideDownload) {
if (!canDownload()) {
// 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() {
}
const downloadButton = document.getElementById('toolbarViewerRight').querySelector('button.download')
if (downloadButton) {
downloadButton.style.display = 'none'
}

// Disable printing service when downloads are hidden, as even if the
// buttons in the UI are hidden the printing could still be triggered
Expand All @@ -94,11 +112,17 @@ function initializeCustomPDFViewerApplication() {
// 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() {
}

// For css properties
document.getElementById('viewer').classList.add('disabledTextSelection')

console.debug('Files_PDFViewer, download and print disabled')
}
}

Expand Down