Merge pull request #11789 from Snuffleupagus/bug-792816
Add a new `pdfjs.enablePermissions` preference, off by default, to allow the PDF documents to disable copying in the viewer (bug 792816)
This commit is contained in:
commit
12aba0f91a
@ -151,6 +151,10 @@
|
|||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"default": false
|
"default": false
|
||||||
},
|
},
|
||||||
|
"enablePermissions": {
|
||||||
|
"type": "boolean",
|
||||||
|
"default": false
|
||||||
|
},
|
||||||
"historyUpdateUrl": {
|
"historyUpdateUrl": {
|
||||||
"type": "boolean",
|
"type": "boolean",
|
||||||
"default": false
|
"default": false
|
||||||
|
34
web/app.js
34
web/app.js
@ -48,6 +48,7 @@ import {
|
|||||||
MissingPDFException,
|
MissingPDFException,
|
||||||
OPS,
|
OPS,
|
||||||
PDFWorker,
|
PDFWorker,
|
||||||
|
PermissionFlag,
|
||||||
shadow,
|
shadow,
|
||||||
UnexpectedResponseException,
|
UnexpectedResponseException,
|
||||||
UNSUPPORTED_FEATURES,
|
UNSUPPORTED_FEATURES,
|
||||||
@ -77,6 +78,7 @@ const DEFAULT_SCALE_DELTA = 1.1;
|
|||||||
const DISABLE_AUTO_FETCH_LOADING_BAR_TIMEOUT = 5000; // ms
|
const DISABLE_AUTO_FETCH_LOADING_BAR_TIMEOUT = 5000; // ms
|
||||||
const FORCE_PAGES_LOADED_TIMEOUT = 10000; // ms
|
const FORCE_PAGES_LOADED_TIMEOUT = 10000; // ms
|
||||||
const WHEEL_ZOOM_DISABLED_TIMEOUT = 1000; // ms
|
const WHEEL_ZOOM_DISABLED_TIMEOUT = 1000; // ms
|
||||||
|
const ENABLE_PERMISSIONS_CLASS = "enablePermissions";
|
||||||
|
|
||||||
const ViewOnLoad = {
|
const ViewOnLoad = {
|
||||||
UNKNOWN: -1,
|
UNKNOWN: -1,
|
||||||
@ -679,6 +681,7 @@ const PDFViewerApplication = {
|
|||||||
this.pdfLinkService.setDocument(null);
|
this.pdfLinkService.setDocument(null);
|
||||||
this.pdfDocumentProperties.setDocument(null);
|
this.pdfDocumentProperties.setDocument(null);
|
||||||
}
|
}
|
||||||
|
webViewerResetPermissions();
|
||||||
this.store = null;
|
this.store = null;
|
||||||
this.isInitialViewSet = false;
|
this.isInitialViewSet = false;
|
||||||
this.downloadComplete = false;
|
this.downloadComplete = false;
|
||||||
@ -1149,6 +1152,10 @@ const PDFViewerApplication = {
|
|||||||
pdfViewer.focus();
|
pdfViewer.focus();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Currently only the "copy"-permission is supported, hence we delay
|
||||||
|
// the `getPermissions` API call until *after* rendering has started.
|
||||||
|
this._initializePermissions(pdfDocument);
|
||||||
|
|
||||||
// For documents with different page sizes, once all pages are
|
// For documents with different page sizes, once all pages are
|
||||||
// resolved, ensure that the correct location becomes visible on load.
|
// resolved, ensure that the correct location becomes visible on load.
|
||||||
// (To reduce the risk, in very large and/or slow loading documents,
|
// (To reduce the risk, in very large and/or slow loading documents,
|
||||||
@ -1467,6 +1474,24 @@ const PDFViewerApplication = {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @private
|
||||||
|
*/
|
||||||
|
async _initializePermissions(pdfDocument) {
|
||||||
|
const permissions = await pdfDocument.getPermissions();
|
||||||
|
|
||||||
|
if (pdfDocument !== this.pdfDocument) {
|
||||||
|
return; // The document was closed while the permissions resolved.
|
||||||
|
}
|
||||||
|
if (!permissions || !AppOptions.get("enablePermissions")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Currently only the "copy"-permission is supported.
|
||||||
|
if (!permissions.includes(PermissionFlag.COPY)) {
|
||||||
|
this.appConfig.viewerContainer.classList.add(ENABLE_PERMISSIONS_CLASS);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
setInitialView(
|
setInitialView(
|
||||||
storedHash,
|
storedHash,
|
||||||
{ rotation, sidebarView, scrollMode, spreadMode } = {}
|
{ rotation, sidebarView, scrollMode, spreadMode } = {}
|
||||||
@ -1979,6 +2004,15 @@ if (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function webViewerResetPermissions() {
|
||||||
|
const { appConfig } = PDFViewerApplication;
|
||||||
|
if (!appConfig) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Currently only the "copy"-permission is supported.
|
||||||
|
appConfig.viewerContainer.classList.remove(ENABLE_PERMISSIONS_CLASS);
|
||||||
|
}
|
||||||
|
|
||||||
function webViewerPageRendered(evt) {
|
function webViewerPageRendered(evt) {
|
||||||
const pageNumber = evt.pageNumber;
|
const pageNumber = evt.pageNumber;
|
||||||
const pageIndex = pageNumber - 1;
|
const pageIndex = pageNumber - 1;
|
||||||
|
@ -53,6 +53,11 @@ const defaultOptions = {
|
|||||||
value: false,
|
value: false,
|
||||||
kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
|
kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
|
||||||
},
|
},
|
||||||
|
enablePermissions: {
|
||||||
|
/** @type {boolean} */
|
||||||
|
value: false,
|
||||||
|
kind: OptionKind.VIEWER + OptionKind.PREFERENCE,
|
||||||
|
},
|
||||||
/**
|
/**
|
||||||
* The `disablePreferences` is, conditionally, defined below.
|
* The `disablePreferences` is, conditionally, defined below.
|
||||||
*/
|
*/
|
||||||
|
@ -55,6 +55,11 @@ select {
|
|||||||
display: none !important;
|
display: none !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.pdfViewer.enablePermissions .textLayer > span {
|
||||||
|
user-select: none !important;
|
||||||
|
cursor: not-allowed;
|
||||||
|
}
|
||||||
|
|
||||||
#viewerContainer.pdfPresentationMode:-ms-fullscreen {
|
#viewerContainer.pdfPresentationMode:-ms-fullscreen {
|
||||||
top: 0px !important;
|
top: 0px !important;
|
||||||
overflow: hidden !important;
|
overflow: hidden !important;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user