mirror of
https://github.com/zen-browser/pdf.js.git
synced 2025-07-08 01:10:08 +02:00
[editor] Support disabling of editing when pdfjs.enablePermissions
is set (issue 15049)
For encrypted PDF documents without the required permissions set, this patch adds support for disabling of Annotation-editing. However, please note that it also requires that the `pdfjs.enablePermissions` preference is set to `true` (since PDF document permissions could be seen as user hostile).[1] As I started looking at the issue, it soon became clear that *only* trying to fix the issue without slightly re-factor the surrounding code would be somewhat difficult. The following is an overview of the changes in this patch; sorry about the size/scope of this! - Use a new `AnnotationEditorUIManager`-instance *for each* PDF document opened in the GENERIC viewer, to prevent user-added Annotations from "leaking" from one document into the next. - Re-factor the `BaseViewer.#initializePermissions`-method, to simplify handling of temporarily disabled modes (e.g. for both Annotation-rendering and Annotation-editing). - When editing is enabled, let the Editor-buttons be `disabled` until the document has loaded. This way we avoid the buttons becoming clickable temporarily, for PDF documents that use permissions. - Slightly re-factor how the Editor-buttons are shown/hidden in the viewer, and reset the toolbar-state when a new PDF document is opened. - Flip the order of the Editor-buttons and the pre-exising toolbarButtons in the "toolbarViewerRight"-div. (To help reduce the size, a little bit, for the PR that adds new Editor-toolbars.) - Enable editing by default in the development viewer, i.e. `gulp server`, since having to (repeatedly) do that manually becomes annoying after a while. - Finally, support disabling of editing when `pdfjs.enablePermissions` is set; fixes issue 15049. --- [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
6ee538e0ba
commit
35a6a508ee
6 changed files with 102 additions and 73 deletions
|
@ -141,7 +141,9 @@ class Toolbar {
|
|||
this.pageScale = DEFAULT_SCALE;
|
||||
this._updateUIState(true);
|
||||
this.updateLoadingIndicatorState();
|
||||
this.updateEditorModeButtonsState();
|
||||
|
||||
// Reset the Editor buttons too, since they're document specific.
|
||||
this.eventBus.dispatch("toolbarreset", { source: this });
|
||||
}
|
||||
|
||||
_bindListeners(options) {
|
||||
|
@ -212,7 +214,7 @@ class Toolbar {
|
|||
editorFreeTextButton,
|
||||
editorInkButton,
|
||||
}) {
|
||||
this.eventBus._on("annotationeditormodechanged", evt => {
|
||||
const editorModeChanged = (evt, disableButtons = false) => {
|
||||
const editorButtons = [
|
||||
[AnnotationEditorType.NONE, editorNoneButton],
|
||||
[AnnotationEditorType.FREETEXT, editorFreeTextButton],
|
||||
|
@ -223,6 +225,17 @@ class Toolbar {
|
|||
const checked = mode === evt.mode;
|
||||
button.classList.toggle("toggled", checked);
|
||||
button.setAttribute("aria-checked", checked);
|
||||
button.disabled = disableButtons;
|
||||
}
|
||||
};
|
||||
this.eventBus._on("annotationeditormodechanged", editorModeChanged);
|
||||
|
||||
this.eventBus._on("toolbarreset", evt => {
|
||||
if (evt.source === this) {
|
||||
editorModeChanged(
|
||||
{ mode: AnnotationEditorType.NONE },
|
||||
/* disableButtons = */ true
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -286,15 +299,6 @@ class Toolbar {
|
|||
pageNumber.classList.toggle(PAGE_NUMBER_LOADING_INDICATOR, loading);
|
||||
}
|
||||
|
||||
updateEditorModeButtonsState(disabled = false) {
|
||||
const { editorNoneButton, editorFreeTextButton, editorInkButton } =
|
||||
this.items;
|
||||
|
||||
editorNoneButton.disabled = disabled;
|
||||
editorFreeTextButton.disabled = disabled;
|
||||
editorInkButton.disabled = disabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Increase the width of the zoom dropdown DOM element if, and only if, it's
|
||||
* too narrow to fit the *longest* of the localized strings.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue