From c892ed6da40a4dbc53886d5f7873d458b7c99e94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Calvi=C3=B1o=20S=C3=A1nchez?= Date: Wed, 9 Jun 2021 21:15:42 +0200 Subject: [PATCH] Disable content copy for PDF files that specify it MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In v2.5.207 pdf.js added the "enablePermissions" option to disable copying in the viewer for the PDF files that specify it. The option is off by default, so it needs to be explicitly enabled. Note that the content copy is prevented just by disabling selection through CSS. The "selection disabled" flag in a PDF document is not a strong security measure and can be easily circumvented (for example, just downloading the file and opening it in a PDF reader that does not honour the flag), so disabling the selection through CSS was deemed good enough for pdf.js. Signed-off-by: Daniel Calviño Sánchez Signed-off-by: npmbuildbot-nextcloud[bot] --- js/files_pdfviewer-workersrc.js | 4 ++-- js/files_pdfviewer-workersrc.js.map | 2 +- src/workersrc.js | 1 + 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/js/files_pdfviewer-workersrc.js b/js/files_pdfviewer-workersrc.js index 72c5beab..ef06716f 100644 --- a/js/files_pdfviewer-workersrc.js +++ b/js/files_pdfviewer-workersrc.js @@ -19,7 +19,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . * - */window.location===window.parent.location&&(window.location.href="/"),document.addEventListener("DOMContentLoaded",(function(){if(PDFViewerApplicationOptions.set("disablePreferences",!0),PDFViewerApplicationOptions.set("externalLinkTarget",pdfjsLib.LinkTarget.BLANK),PDFViewerApplicationOptions.set("isEvalSupported",!1),PDFViewerApplicationOptions.set("workerSrc",document.getElementsByTagName("head")[0].getAttribute("data-workersrc")),PDFViewerApplicationOptions.set("cMapUrl",document.getElementsByTagName("head")[0].getAttribute("data-cmapurl")),console.debug("Initialized files_pdfviewer",PDFViewerApplicationOptions.getAll()),PDFViewerApplication.download=function(){function e(e){for(var t=0,n=e.length;t1&&void 0!==arguments[1]?arguments[1]:"document.pdf";if(e(t))return console.warn('getPDFFileNameFromURL: ignoring "data:" URL for performance reasons.'),n;var o=/^(?:(?:[^:]+:)?\/\/[^/]+)?([^?#]*)(\?[^#]*)?(#.*)?$/,r=/[^/?#=]+\.pdf\b(?!.*\.pdf\b)/i,i=o.exec(t),a=r.exec(i[1])||r.exec(i[2])||r.exec(i[3]);if(a&&-1!==(a=a[0]).indexOf("%"))try{a=r.exec(decodeURIComponent(a))[0]}catch(e){console.debug(e)}return a||n}(t))},!Object(o.a)()){PDFViewerApplication.download=function(){};var e=document.getElementById("toolbarViewerRight").querySelector("button.download");e&&(e.style.display="none"),delete PDFViewerApplication.supportsPrinting,PDFViewerApplication.supportsPrinting=!1,PDFViewerApplication.beforePrint=function(){},document.getElementById("viewer").classList.add("disabledTextSelection"),console.debug("Files_PDFViewer, download and print disabled")}}),!0)},22:function(e,t,n){"use strict"; + */window.location===window.parent.location&&(window.location.href="/"),document.addEventListener("DOMContentLoaded",(function(){if(PDFViewerApplicationOptions.set("disablePreferences",!0),PDFViewerApplicationOptions.set("externalLinkTarget",pdfjsLib.LinkTarget.BLANK),PDFViewerApplicationOptions.set("isEvalSupported",!1),PDFViewerApplicationOptions.set("workerSrc",document.getElementsByTagName("head")[0].getAttribute("data-workersrc")),PDFViewerApplicationOptions.set("cMapUrl",document.getElementsByTagName("head")[0].getAttribute("data-cmapurl")),PDFViewerApplicationOptions.set("enablePermissions",!0),console.debug("Initialized files_pdfviewer",PDFViewerApplicationOptions.getAll()),PDFViewerApplication.download=function(){function e(e){for(var t=0,n=e.length;t1&&void 0!==arguments[1]?arguments[1]:"document.pdf";if(e(t))return console.warn('getPDFFileNameFromURL: ignoring "data:" URL for performance reasons.'),n;var o=/^(?:(?:[^:]+:)?\/\/[^/]+)?([^?#]*)(\?[^#]*)?(#.*)?$/,r=/[^/?#=]+\.pdf\b(?!.*\.pdf\b)/i,i=o.exec(t),a=r.exec(i[1])||r.exec(i[2])||r.exec(i[3]);if(a&&-1!==(a=a[0]).indexOf("%"))try{a=r.exec(decodeURIComponent(a))[0]}catch(e){console.debug(e)}return a||n}(t))},!Object(o.a)()){PDFViewerApplication.download=function(){};var e=document.getElementById("toolbarViewerRight").querySelector("button.download");e&&(e.style.display="none"),delete PDFViewerApplication.supportsPrinting,PDFViewerApplication.supportsPrinting=!1,PDFViewerApplication.beforePrint=function(){},document.getElementById("viewer").classList.add("disabledTextSelection"),console.debug("Files_PDFViewer, download and print disabled")}}),!0)},22:function(e,t,n){"use strict"; /** * @copyright Copyright (c) 2020 John Molakvoæ * @@ -41,4 +41,4 @@ * along with this program. If not, see . * */var o=document.getElementById("hideDownload");t.a=function(){return!o||o&&"true"!==o.value}}}); -//# sourceMappingURL=files_pdfviewer-workersrc.js.map?v=e6cc7c02ddda75eb37c6 \ No newline at end of file +//# sourceMappingURL=files_pdfviewer-workersrc.js.map?v=5f5df98e3227ce31efa8 \ No newline at end of file diff --git a/js/files_pdfviewer-workersrc.js.map b/js/files_pdfviewer-workersrc.js.map index 9fa303c5..4965d195 100644 --- a/js/files_pdfviewer-workersrc.js.map +++ b/js/files_pdfviewer-workersrc.js.map @@ -1 +1 @@ -{"version":3,"sources":["webpack:///webpack/bootstrap","webpack:///./src/utils/redirectIfNotIframe.js","webpack:///./src/workersrc.js","webpack:///./src/utils/canDownload.js"],"names":["installedModules","__webpack_require__","moduleId","exports","module","i","l","modules","call","m","c","d","name","getter","o","Object","defineProperty","enumerable","get","r","Symbol","toStringTag","value","t","mode","__esModule","ns","create","key","bind","n","object","property","prototype","hasOwnProperty","p","s","window","location","parent","href","document","addEventListener","PDFViewerApplicationOptions","set","pdfjsLib","LinkTarget","BLANK","getElementsByTagName","getAttribute","console","debug","getAll","PDFViewerApplication","download","isDataSchema","url","ii","length","trim","substr","toLowerCase","decodeURIComponent","search","this","downloadManager","downloadUrl","defaultFilename","arguments","undefined","warn","reURI","reFilename","splitURI","exec","suggestedFilename","indexOf","e","getPDFFileNameFromURL","canDownload","downloadButton","getElementById","querySelector","style","display","supportsPrinting","beforePrint","classList","add","h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EAAoBA,EAAkB,IAChBC,QAAQ,KAC7B,IACCD,EAAoBH,EAAWE,KAAKZ,mBAAmBa,IAAoB,GAC1E,MAAOE,GACR3B,QAAQC,MAAM0B,GAIjB,OAAOF,GAAqBR,EAKSW,CAAsBtB,MAGxDuB,cAAe,CAInB1B,qBAAqBC,SAAW,aAEhC,IAAM0B,EAAiBvC,SAASwC,eAAe,sBAAsBC,cAAc,mBAC/EF,IACHA,EAAeG,MAAMC,QAAU,eAWzB/B,qBAAqBgC,iBAC5BhC,qBAAqBgC,kBAAmB,EAKxChC,qBAAqBiC,YAAc,aAInC7C,SAASwC,eAAe,UAAUM,UAAUC,IAAI,yBAEhDtC,QAAQC,MAAM,oDAIoE,I;;;;;;;;;;;;;;;;;;;;;GC5GpF,IAAMsC,EAAmBhD,SAASwC,eAAe,gBAElC,sBAAOQ,GAAqBA,GAA+C,SAA3BA,EAAiBnE","file":"files_pdfviewer-workersrc.js?v=e6cc7c02ddda75eb37c6","sourcesContent":[" \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"/js/\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 141);\n","/**\n * @copyright Copyright (c) 2020 John Molakvoæ \n *\n * @author John Molakvoæ \n *\n * @license GNU AGPL version 3 or any later version\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU Affero General Public License as\n * published by the Free Software Foundation, either version 3 of the\n * License, or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU Affero General Public License for more details.\n *\n * You should have received a copy of the GNU Affero General Public License\n * along with this program. If not, see .\n *\n */\nexport default function() {\n\t// Not within iframe\n\tif (window.location !== window.parent.location) {\n\t\treturn\n\t}\n\n\twindow.location.href = '/'\n}\n","\n/**\n * @copyright Copyright (c) 2020 Daniel Calviño Sánchez \n *\n * @author Daniel Calviño Sánchez \n * @author John Molakvoæ \n *\n * @license GNU AGPL version 3 or any later version\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU Affero General Public License as\n * published by the Free Software Foundation, either version 3 of the\n * License, or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU Affero General Public License for more details.\n *\n * You should have received a copy of the GNU Affero General Public License\n * along with this program. If not, see .\n *\n */\n\nimport canDownload from './utils/canDownload'\nimport redirectIfNotIframe from './utils/redirectIfNotIframe'\n\n/**\n * Checks if the page is displayed in an iframe. If not redirect to /.\n **/\nredirectIfNotIframe()\n\n// When \"PDFViewerApplication.webViewerInitialized\" is executed (once\n// \"PDFViewerApplication.initialize\" is done) it opens the PDF file via URL,\n// which requires the PDFViewerApplication to be properly configured, so the\n// custom initialization has to be executed before that. This can be done by\n// listening to the \"webviewerloaded\" event, which is emitted after\n// \"PDFViewerApplication\" and \"PDFViewerApplicationOptions\" are globally set and\n// before \"PDFViewerApplication.initialize\" is executed.\nfunction initializeCustomPDFViewerApplication() {\n\n\t// Preferences override options, so they must be disabled for\n\t// \"externalLinkTarget\" to take effect.\n\tPDFViewerApplicationOptions.set('disablePreferences', true)\n\tPDFViewerApplicationOptions.set('externalLinkTarget', pdfjsLib.LinkTarget.BLANK)\n\tPDFViewerApplicationOptions.set('isEvalSupported', false)\n\tPDFViewerApplicationOptions.set('workerSrc', document.getElementsByTagName('head')[0].getAttribute('data-workersrc'))\n\tPDFViewerApplicationOptions.set('cMapUrl', document.getElementsByTagName('head')[0].getAttribute('data-cmapurl'))\n\n\tconsole.debug('Initialized files_pdfviewer', PDFViewerApplicationOptions.getAll())\n\n\t// The download has to be forced to use the URL of the file; by default\n\t// \"PDFViewerApplication.download\" uses a blob, but this causes a CSP error\n\t// (at least, in Firefox) when trying to download it.\n\tPDFViewerApplication.download = function() {\n\t\t// \"isDataSchema()\" and \"getPDFFileNameFromURL()\" are copied from\n\t\t// \"vendor/pdfjs/web/viewer.js\", as the functions defined in that file\n\t\t// can not be accessed from the outside.\n\t\tfunction isDataSchema(url) {\n\t\t\tlet i = 0\n\t\t\tconst ii = url.length\n\t\t\twhile (i < ii && url[i].trim() === '') {\n\t\t\t\ti++\n\t\t\t}\n\t\t\treturn url.substr(i, 5).toLowerCase() === 'data:'\n\t\t}\n\n\t\tfunction getPDFFileNameFromURL(url) {\n\t\t\tconst defaultFilename = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'document.pdf'\n\n\t\t\tif (isDataSchema(url)) {\n\t\t\t\tconsole.warn('getPDFFileNameFromURL: ' + 'ignoring \"data:\" URL for performance reasons.')\n\t\t\t\treturn defaultFilename\n\t\t\t}\n\t\t\tconst reURI = /^(?:(?:[^:]+:)?\\/\\/[^/]+)?([^?#]*)(\\?[^#]*)?(#.*)?$/\n\t\t\tconst reFilename = /[^/?#=]+\\.pdf\\b(?!.*\\.pdf\\b)/i\n\t\t\tconst splitURI = reURI.exec(url)\n\t\t\tlet suggestedFilename = reFilename.exec(splitURI[1]) || reFilename.exec(splitURI[2]) || reFilename.exec(splitURI[3])\n\t\t\tif (suggestedFilename) {\n\t\t\t\tsuggestedFilename = suggestedFilename[0]\n\t\t\t\tif (suggestedFilename.indexOf('%') !== -1) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tsuggestedFilename = reFilename.exec(decodeURIComponent(suggestedFilename))[0]\n\t\t\t\t\t} catch (e) {\n\t\t\t\t\t\tconsole.debug(e)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn suggestedFilename || defaultFilename\n\t\t}\n\n\t\tconst url = decodeURIComponent(window.location.search.substr(6))\n\n\t\tthis.downloadManager.downloadUrl(url, getPDFFileNameFromURL(url))\n\t}\n\n\tif (!canDownload()) {\n\t\t// Disable download function when downloads are hidden, as even if the\n\t\t// buttons in the UI are hidden the download could still be triggered\n\t\t// with Ctrl|Meta+S.\n\t\tPDFViewerApplication.download = function() {\n\t\t}\n\t\tconst downloadButton = document.getElementById('toolbarViewerRight').querySelector('button.download')\n\t\tif (downloadButton) {\n\t\t\tdownloadButton.style.display = 'none'\n\t\t}\n\n\t\t// Disable printing service when downloads are hidden, as even if the\n\t\t// buttons in the UI are hidden the printing could still be triggered\n\t\t// with Ctrl|Meta+P.\n\t\t// Abuse the \"supportsPrinting\" parameter, which signals that the\n\t\t// browser does not fully support printing, to make PDFViewer disable\n\t\t// the printing service.\n\t\t// \"supportsPrinting\" is a getter function, so it needs to be deleted\n\t\t// before replacing it with a simple value.\n\t\tdelete PDFViewerApplication.supportsPrinting\n\t\tPDFViewerApplication.supportsPrinting = false\n\n\t\t// When printing is not supported a warning is shown by the default\n\t\t// \"beforePrint\" function when trying to print. That function needs to\n\t\t// be replaced with an empty one to prevent that warning to be shown.\n\t\tPDFViewerApplication.beforePrint = function() {\n\t\t}\n\n\t\t// For css properties\n\t\tdocument.getElementById('viewer').classList.add('disabledTextSelection')\n\n\t\tconsole.debug('Files_PDFViewer, download and print disabled')\n\t}\n}\n\ndocument.addEventListener('DOMContentLoaded', initializeCustomPDFViewerApplication, true)\n","\n/**\n * @copyright Copyright (c) 2020 John Molakvoæ \n *\n * @author John Molakvoæ \n *\n * @license GNU AGPL version 3 or any later version\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU Affero General Public License as\n * published by the Free Software Foundation, either version 3 of the\n * License, or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU Affero General Public License for more details.\n *\n * You should have received a copy of the GNU Affero General Public License\n * along with this program. If not, see .\n *\n */\n\nconst hideDownloadElmt = document.getElementById('hideDownload')\n// true = hidden download\nexport default () => !hideDownloadElmt || (hideDownloadElmt && hideDownloadElmt.value !== 'true')\n"],"sourceRoot":""} \ No newline at end of file +{"version":3,"sources":["webpack:///webpack/bootstrap","webpack:///./src/utils/redirectIfNotIframe.js","webpack:///./src/workersrc.js","webpack:///./src/utils/canDownload.js"],"names":["installedModules","__webpack_require__","moduleId","exports","module","i","l","modules","call","m","c","d","name","getter","o","Object","defineProperty","enumerable","get","r","Symbol","toStringTag","value","t","mode","__esModule","ns","create","key","bind","n","object","property","prototype","hasOwnProperty","p","s","window","location","parent","href","document","addEventListener","PDFViewerApplicationOptions","set","pdfjsLib","LinkTarget","BLANK","getElementsByTagName","getAttribute","console","debug","getAll","PDFViewerApplication","download","isDataSchema","url","ii","length","trim","substr","toLowerCase","decodeURIComponent","search","this","downloadManager","downloadUrl","defaultFilename","arguments","undefined","warn","reURI","reFilename","splitURI","exec","suggestedFilename","indexOf","e","getPDFFileNameFromURL","canDownload","downloadButton","getElementById","querySelector","style","display","supportsPrinting","beforePrint","classList","add","hideDownloadElmt"],"mappings":"aACE,IAAIA,EAAmB,GAGvB,SAASC,EAAoBC,GAG5B,GAAGF,EAAiBE,GACnB,OAAOF,EAAiBE,GAAUC,QAGnC,IAAIC,EAASJ,EAAiBE,GAAY,CACzCG,EAAGH,EACHI,GAAG,EACHH,QAAS,IAUV,OANAI,EAAQL,GAAUM,KAAKJ,EAAOD,QAASC,EAAQA,EAAOD,QAASF,GAG/DG,EAAOE,GAAI,EAGJF,EAAOD,QAKfF,EAAoBQ,EAAIF,EAGxBN,EAAoBS,EAAIV,EAGxBC,EAAoBU,EAAI,SAASR,EAASS,EAAMC,GAC3CZ,EAAoBa,EAAEX,EAASS,IAClCG,OA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AUM,UAAUC,IAAI,yBAEhDtC,QAAQC,MAAM,oDAIoE,I;;;;;;;;;;;;;;;;;;;;;GC7GpF,IAAMsC,EAAmBhD,SAASwC,eAAe,gBAElC,sBAAOQ,GAAqBA,GAA+C,SAA3BA,EAAiBnE","file":"files_pdfviewer-workersrc.js?v=5f5df98e3227ce31efa8","sourcesContent":[" \t// The module cache\n \tvar installedModules = {};\n\n \t// The require function\n \tfunction __webpack_require__(moduleId) {\n\n \t\t// Check if module is in cache\n \t\tif(installedModules[moduleId]) {\n \t\t\treturn installedModules[moduleId].exports;\n \t\t}\n \t\t// Create a new module (and put it into the cache)\n \t\tvar module = installedModules[moduleId] = {\n \t\t\ti: moduleId,\n \t\t\tl: false,\n \t\t\texports: {}\n \t\t};\n\n \t\t// Execute the module function\n \t\tmodules[moduleId].call(module.exports, module, module.exports, __webpack_require__);\n\n \t\t// Flag the module as loaded\n \t\tmodule.l = true;\n\n \t\t// Return the exports of the module\n \t\treturn module.exports;\n \t}\n\n\n \t// expose the modules object (__webpack_modules__)\n \t__webpack_require__.m = modules;\n\n \t// expose the module cache\n \t__webpack_require__.c = installedModules;\n\n \t// define getter function for harmony exports\n \t__webpack_require__.d = function(exports, name, getter) {\n \t\tif(!__webpack_require__.o(exports, name)) {\n \t\t\tObject.defineProperty(exports, name, { enumerable: true, get: getter });\n \t\t}\n \t};\n\n \t// define __esModule on exports\n \t__webpack_require__.r = function(exports) {\n \t\tif(typeof Symbol !== 'undefined' && Symbol.toStringTag) {\n \t\t\tObject.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });\n \t\t}\n \t\tObject.defineProperty(exports, '__esModule', { value: true });\n \t};\n\n \t// create a fake namespace object\n \t// mode & 1: value is a module id, require it\n \t// mode & 2: merge all properties of value into the ns\n \t// mode & 4: return value when already ns object\n \t// mode & 8|1: behave like require\n \t__webpack_require__.t = function(value, mode) {\n \t\tif(mode & 1) value = __webpack_require__(value);\n \t\tif(mode & 8) return value;\n \t\tif((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;\n \t\tvar ns = Object.create(null);\n \t\t__webpack_require__.r(ns);\n \t\tObject.defineProperty(ns, 'default', { enumerable: true, value: value });\n \t\tif(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));\n \t\treturn ns;\n \t};\n\n \t// getDefaultExport function for compatibility with non-harmony modules\n \t__webpack_require__.n = function(module) {\n \t\tvar getter = module && module.__esModule ?\n \t\t\tfunction getDefault() { return module['default']; } :\n \t\t\tfunction getModuleExports() { return module; };\n \t\t__webpack_require__.d(getter, 'a', getter);\n \t\treturn getter;\n \t};\n\n \t// Object.prototype.hasOwnProperty.call\n \t__webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };\n\n \t// __webpack_public_path__\n \t__webpack_require__.p = \"/js/\";\n\n\n \t// Load entry module and return exports\n \treturn __webpack_require__(__webpack_require__.s = 141);\n","/**\n * @copyright Copyright (c) 2020 John Molakvoæ \n *\n * @author John Molakvoæ \n *\n * @license GNU AGPL version 3 or any later version\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU Affero General Public License as\n * published by the Free Software Foundation, either version 3 of the\n * License, or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU Affero General Public License for more details.\n *\n * You should have received a copy of the GNU Affero General Public License\n * along with this program. If not, see .\n *\n */\nexport default function() {\n\t// Not within iframe\n\tif (window.location !== window.parent.location) {\n\t\treturn\n\t}\n\n\twindow.location.href = '/'\n}\n","\n/**\n * @copyright Copyright (c) 2020 Daniel Calviño Sánchez \n *\n * @author Daniel Calviño Sánchez \n * @author John Molakvoæ \n *\n * @license GNU AGPL version 3 or any later version\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU Affero General Public License as\n * published by the Free Software Foundation, either version 3 of the\n * License, or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU Affero General Public License for more details.\n *\n * You should have received a copy of the GNU Affero General Public License\n * along with this program. If not, see .\n *\n */\n\nimport canDownload from './utils/canDownload'\nimport redirectIfNotIframe from './utils/redirectIfNotIframe'\n\n/**\n * Checks if the page is displayed in an iframe. If not redirect to /.\n **/\nredirectIfNotIframe()\n\n// When \"PDFViewerApplication.webViewerInitialized\" is executed (once\n// \"PDFViewerApplication.initialize\" is done) it opens the PDF file via URL,\n// which requires the PDFViewerApplication to be properly configured, so the\n// custom initialization has to be executed before that. This can be done by\n// listening to the \"webviewerloaded\" event, which is emitted after\n// \"PDFViewerApplication\" and \"PDFViewerApplicationOptions\" are globally set and\n// before \"PDFViewerApplication.initialize\" is executed.\nfunction initializeCustomPDFViewerApplication() {\n\n\t// Preferences override options, so they must be disabled for\n\t// \"externalLinkTarget\" to take effect.\n\tPDFViewerApplicationOptions.set('disablePreferences', true)\n\tPDFViewerApplicationOptions.set('externalLinkTarget', pdfjsLib.LinkTarget.BLANK)\n\tPDFViewerApplicationOptions.set('isEvalSupported', false)\n\tPDFViewerApplicationOptions.set('workerSrc', document.getElementsByTagName('head')[0].getAttribute('data-workersrc'))\n\tPDFViewerApplicationOptions.set('cMapUrl', document.getElementsByTagName('head')[0].getAttribute('data-cmapurl'))\n\tPDFViewerApplicationOptions.set('enablePermissions', true)\n\n\tconsole.debug('Initialized files_pdfviewer', PDFViewerApplicationOptions.getAll())\n\n\t// The download has to be forced to use the URL of the file; by default\n\t// \"PDFViewerApplication.download\" uses a blob, but this causes a CSP error\n\t// (at least, in Firefox) when trying to download it.\n\tPDFViewerApplication.download = function() {\n\t\t// \"isDataSchema()\" and \"getPDFFileNameFromURL()\" are copied from\n\t\t// \"vendor/pdfjs/web/viewer.js\", as the functions defined in that file\n\t\t// can not be accessed from the outside.\n\t\tfunction isDataSchema(url) {\n\t\t\tlet i = 0\n\t\t\tconst ii = url.length\n\t\t\twhile (i < ii && url[i].trim() === '') {\n\t\t\t\ti++\n\t\t\t}\n\t\t\treturn url.substr(i, 5).toLowerCase() === 'data:'\n\t\t}\n\n\t\tfunction getPDFFileNameFromURL(url) {\n\t\t\tconst defaultFilename = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'document.pdf'\n\n\t\t\tif (isDataSchema(url)) {\n\t\t\t\tconsole.warn('getPDFFileNameFromURL: ' + 'ignoring \"data:\" URL for performance reasons.')\n\t\t\t\treturn defaultFilename\n\t\t\t}\n\t\t\tconst reURI = /^(?:(?:[^:]+:)?\\/\\/[^/]+)?([^?#]*)(\\?[^#]*)?(#.*)?$/\n\t\t\tconst reFilename = /[^/?#=]+\\.pdf\\b(?!.*\\.pdf\\b)/i\n\t\t\tconst splitURI = reURI.exec(url)\n\t\t\tlet suggestedFilename = reFilename.exec(splitURI[1]) || reFilename.exec(splitURI[2]) || reFilename.exec(splitURI[3])\n\t\t\tif (suggestedFilename) {\n\t\t\t\tsuggestedFilename = suggestedFilename[0]\n\t\t\t\tif (suggestedFilename.indexOf('%') !== -1) {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tsuggestedFilename = reFilename.exec(decodeURIComponent(suggestedFilename))[0]\n\t\t\t\t\t} catch (e) {\n\t\t\t\t\t\tconsole.debug(e)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn suggestedFilename || defaultFilename\n\t\t}\n\n\t\tconst url = decodeURIComponent(window.location.search.substr(6))\n\n\t\tthis.downloadManager.downloadUrl(url, getPDFFileNameFromURL(url))\n\t}\n\n\tif (!canDownload()) {\n\t\t// Disable download function when downloads are hidden, as even if the\n\t\t// buttons in the UI are hidden the download could still be triggered\n\t\t// with Ctrl|Meta+S.\n\t\tPDFViewerApplication.download = function() {\n\t\t}\n\t\tconst downloadButton = document.getElementById('toolbarViewerRight').querySelector('button.download')\n\t\tif (downloadButton) {\n\t\t\tdownloadButton.style.display = 'none'\n\t\t}\n\n\t\t// Disable printing service when downloads are hidden, as even if the\n\t\t// buttons in the UI are hidden the printing could still be triggered\n\t\t// with Ctrl|Meta+P.\n\t\t// Abuse the \"supportsPrinting\" parameter, which signals that the\n\t\t// browser does not fully support printing, to make PDFViewer disable\n\t\t// the printing service.\n\t\t// \"supportsPrinting\" is a getter function, so it needs to be deleted\n\t\t// before replacing it with a simple value.\n\t\tdelete PDFViewerApplication.supportsPrinting\n\t\tPDFViewerApplication.supportsPrinting = false\n\n\t\t// When printing is not supported a warning is shown by the default\n\t\t// \"beforePrint\" function when trying to print. That function needs to\n\t\t// be replaced with an empty one to prevent that warning to be shown.\n\t\tPDFViewerApplication.beforePrint = function() {\n\t\t}\n\n\t\t// For css properties\n\t\tdocument.getElementById('viewer').classList.add('disabledTextSelection')\n\n\t\tconsole.debug('Files_PDFViewer, download and print disabled')\n\t}\n}\n\ndocument.addEventListener('DOMContentLoaded', initializeCustomPDFViewerApplication, true)\n","\n/**\n * @copyright Copyright (c) 2020 John Molakvoæ \n *\n * @author John Molakvoæ \n *\n * @license GNU AGPL version 3 or any later version\n *\n * This program is free software: you can redistribute it and/or modify\n * it under the terms of the GNU Affero General Public License as\n * published by the Free Software Foundation, either version 3 of the\n * License, or (at your option) any later version.\n *\n * This program is distributed in the hope that it will be useful,\n * but WITHOUT ANY WARRANTY; without even the implied warranty of\n * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n * GNU Affero General Public License for more details.\n *\n * You should have received a copy of the GNU Affero General Public License\n * along with this program. If not, see .\n *\n */\n\nconst hideDownloadElmt = document.getElementById('hideDownload')\n// true = hidden download\nexport default () => !hideDownloadElmt || (hideDownloadElmt && hideDownloadElmt.value !== 'true')\n"],"sourceRoot":""} \ No newline at end of file diff --git a/src/workersrc.js b/src/workersrc.js index 98fda002..92bb2686 100644 --- a/src/workersrc.js +++ b/src/workersrc.js @@ -46,6 +46,7 @@ function initializeCustomPDFViewerApplication() { PDFViewerApplicationOptions.set('isEvalSupported', false) PDFViewerApplicationOptions.set('workerSrc', document.getElementsByTagName('head')[0].getAttribute('data-workersrc')) PDFViewerApplicationOptions.set('cMapUrl', document.getElementsByTagName('head')[0].getAttribute('data-cmapurl')) + PDFViewerApplicationOptions.set('enablePermissions', true) console.debug('Initialized files_pdfviewer', PDFViewerApplicationOptions.getAll())