Support disabling of form editing when pdfjs.enablePermissions
is set (issue 14356)
For encrypted PDF documents without the required permissions set, this patch adds support for disabling of form editing. However, please note that it also requires that the `pdfjs.enablePermissions` preference is set to `true`[1] (since PDF document permissions could be seen as user hostile). Based on https://www.adobe.com/content/dam/acom/en/devnet/pdf/pdfs/PDF32000_2008.pdf#G6.1942134, this condition hopefully makes sense. --- [1] Either manually with `about:config`, or using e.g. a [Group Policy](https://github.com/mozilla/policy-templates).
This commit is contained in:
parent
b03281de18
commit
b1d3e7f121
@ -175,6 +175,10 @@ class PDFPageViewBuffer {
|
||||
class BaseViewer {
|
||||
#buffer = null;
|
||||
|
||||
#annotationMode = AnnotationMode.ENABLE_FORMS;
|
||||
|
||||
#previousAnnotationMode = null;
|
||||
|
||||
#enablePermissions = false;
|
||||
|
||||
#previousContainerHeight = 0;
|
||||
@ -225,7 +229,7 @@ class BaseViewer {
|
||||
this._scriptingManager = options.scriptingManager || null;
|
||||
this.removePageBorders = options.removePageBorders || false;
|
||||
this.textLayerMode = options.textLayerMode ?? TextLayerMode.ENABLE;
|
||||
this._annotationMode =
|
||||
this.#annotationMode =
|
||||
options.annotationMode ?? AnnotationMode.ENABLE_FORMS;
|
||||
this.imageResourcesPath = options.imageResourcesPath || "";
|
||||
this.enablePrintAutoRotate = options.enablePrintAutoRotate || false;
|
||||
@ -286,7 +290,7 @@ class BaseViewer {
|
||||
* @type {boolean}
|
||||
*/
|
||||
get renderForms() {
|
||||
return this._annotationMode === AnnotationMode.ENABLE_FORMS;
|
||||
return this.#annotationMode === AnnotationMode.ENABLE_FORMS;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -479,6 +483,9 @@ class BaseViewer {
|
||||
return this.pdfDocument ? this._pagesCapability.promise : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Currently only *some* permissions are supported.
|
||||
*/
|
||||
#initializePermissions(permissions, pdfDocument) {
|
||||
if (pdfDocument !== this.pdfDocument) {
|
||||
return; // The document was closed while the permissions resolved.
|
||||
@ -486,10 +493,20 @@ class BaseViewer {
|
||||
if (!permissions || !this.#enablePermissions) {
|
||||
return;
|
||||
}
|
||||
// Currently only the "copy"-permission is supported.
|
||||
|
||||
if (!permissions.includes(PermissionFlag.COPY)) {
|
||||
this.viewer.classList.add(ENABLE_PERMISSIONS_CLASS);
|
||||
}
|
||||
|
||||
if (
|
||||
!permissions.includes(PermissionFlag.MODIFY_ANNOTATIONS) &&
|
||||
!permissions.includes(PermissionFlag.FILL_INTERACTIVE_FORMS)
|
||||
) {
|
||||
if (this.#annotationMode === AnnotationMode.ENABLE_FORMS) {
|
||||
this.#previousAnnotationMode = this.#annotationMode; // Allow resetting.
|
||||
this.#annotationMode = AnnotationMode.ENABLE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#onePageRenderedOrForceFetch() {
|
||||
@ -599,7 +616,7 @@ class BaseViewer {
|
||||
? this
|
||||
: null;
|
||||
const annotationLayerFactory =
|
||||
this._annotationMode !== AnnotationMode.DISABLE ? this : null;
|
||||
this.#annotationMode !== AnnotationMode.DISABLE ? this : null;
|
||||
const xfaLayerFactory = isPureXfa ? this : null;
|
||||
|
||||
for (let pageNum = 1; pageNum <= pagesCount; ++pageNum) {
|
||||
@ -614,7 +631,7 @@ class BaseViewer {
|
||||
textLayerFactory,
|
||||
textLayerMode: this.textLayerMode,
|
||||
annotationLayerFactory,
|
||||
annotationMode: this._annotationMode,
|
||||
annotationMode: this.#annotationMode,
|
||||
xfaLayerFactory,
|
||||
textHighlighterFactory: this,
|
||||
structTreeLayerFactory: this,
|
||||
@ -772,6 +789,11 @@ class BaseViewer {
|
||||
|
||||
// Reset all PDF document permissions.
|
||||
this.viewer.classList.remove(ENABLE_PERMISSIONS_CLASS);
|
||||
|
||||
if (this.#previousAnnotationMode !== null) {
|
||||
this.#annotationMode = this.#previousAnnotationMode;
|
||||
this.#previousAnnotationMode = null;
|
||||
}
|
||||
}
|
||||
|
||||
#ensurePageViewVisible() {
|
||||
|
@ -76,6 +76,8 @@ const MAX_CANVAS_PIXELS = compatibilityParams.maxCanvasPixels || 16777216;
|
||||
* @implements {IRenderableView}
|
||||
*/
|
||||
class PDFPageView {
|
||||
#annotationMode = AnnotationMode.ENABLE_FORMS;
|
||||
|
||||
/**
|
||||
* @param {PDFPageViewOptions} options
|
||||
*/
|
||||
@ -96,7 +98,7 @@ class PDFPageView {
|
||||
options.optionalContentConfigPromise || null;
|
||||
this.hasRestrictedScaling = false;
|
||||
this.textLayerMode = options.textLayerMode ?? TextLayerMode.ENABLE;
|
||||
this._annotationMode =
|
||||
this.#annotationMode =
|
||||
options.annotationMode ?? AnnotationMode.ENABLE_FORMS;
|
||||
this.imageResourcesPath = options.imageResourcesPath || "";
|
||||
this.useOnlyCssZoom = options.useOnlyCssZoom || false;
|
||||
@ -597,7 +599,7 @@ class PDFPageView {
|
||||
this.textLayer = textLayer;
|
||||
|
||||
if (
|
||||
this._annotationMode !== AnnotationMode.DISABLE &&
|
||||
this.#annotationMode !== AnnotationMode.DISABLE &&
|
||||
this.annotationLayerFactory
|
||||
) {
|
||||
this._annotationCanvasMap ||= new Map();
|
||||
@ -607,7 +609,7 @@ class PDFPageView {
|
||||
pdfPage,
|
||||
/* annotationStorage = */ null,
|
||||
this.imageResourcesPath,
|
||||
this._annotationMode === AnnotationMode.ENABLE_FORMS,
|
||||
this.#annotationMode === AnnotationMode.ENABLE_FORMS,
|
||||
this.l10n,
|
||||
/* enableScripting = */ null,
|
||||
/* hasJSActionsPromise = */ null,
|
||||
@ -835,7 +837,7 @@ class PDFPageView {
|
||||
canvasContext: ctx,
|
||||
transform,
|
||||
viewport: this.viewport,
|
||||
annotationMode: this._annotationMode,
|
||||
annotationMode: this.#annotationMode,
|
||||
optionalContentConfigPromise: this._optionalContentConfigPromise,
|
||||
annotationCanvasMap: this._annotationCanvasMap,
|
||||
};
|
||||
@ -892,7 +894,7 @@ class PDFPageView {
|
||||
});
|
||||
const promise = pdfPage
|
||||
.getOperatorList({
|
||||
annotationMode: this._annotationMode,
|
||||
annotationMode: this.#annotationMode,
|
||||
})
|
||||
.then(opList => {
|
||||
ensureNotCancelled();
|
||||
|
Loading…
Reference in New Issue
Block a user