Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some hasJSActions, and general annotation-code, related cleanup in the viewer and API #12622

Merged
merged 1 commit into from
Nov 14, 2020
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
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"parserOptions": {
"ecmaVersion": 2020,
"ecmaVersion": 2021,
"sourceType": "module",
},

Expand Down
2 changes: 1 addition & 1 deletion external/builder/preprocessor2.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var path = require("path");

var PDFJS_PREPROCESSOR_NAME = "PDFJSDev";
var ROOT_PREFIX = "$ROOT/";
const ACORN_ECMA_VERSION = 2020;
const ACORN_ECMA_VERSION = 2021;

function isLiteral(obj, value) {
return obj.type === "Literal" && obj.value === value;
Expand Down
3 changes: 3 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,7 @@ function createWebpackConfig(defines, output) {
options: {
presets: skipBabel ? undefined : ["@babel/preset-env"],
plugins: [
"@babel/plugin-proposal-logical-assignment-operators",
"@babel/plugin-transform-modules-commonjs",
[
"@babel/plugin-transform-runtime",
Expand Down Expand Up @@ -570,6 +571,7 @@ gulp.task("default_preferences-pre", function () {
sourceType: "module",
presets: undefined, // SKIP_BABEL
plugins: [
"@babel/plugin-proposal-logical-assignment-operators",
"@babel/plugin-transform-modules-commonjs",
babelPluginReplaceNonWebPackRequire,
],
Expand Down Expand Up @@ -1234,6 +1236,7 @@ function buildLib(defines, dir) {
sourceType: "module",
presets: skipBabel ? undefined : ["@babel/preset-env"],
plugins: [
"@babel/plugin-proposal-logical-assignment-operators",
"@babel/plugin-transform-modules-commonjs",
[
"@babel/plugin-transform-runtime",
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"version": "2.0.0",
"devDependencies": {
"@babel/core": "^7.12.3",
"@babel/plugin-proposal-logical-assignment-operators": "^7.12.1",
"@babel/plugin-transform-modules-commonjs": "^7.12.1",
"@babel/plugin-transform-runtime": "^7.12.1",
"@babel/preset-env": "^7.12.1",
Expand Down
11 changes: 9 additions & 2 deletions src/display/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -905,7 +905,7 @@ class PDFDocumentProxy {

/**
* @returns {Promise<boolean>} A promise that is resolved with `true`
* if some /AcroForm fields have JavaScript actions.
* if some /AcroForm fields have JavaScript actions.
*/
hasJSActions() {
return this._transport.hasJSActions();
Expand Down Expand Up @@ -2128,7 +2128,10 @@ class WorkerTransport {
const terminated = this.messageHandler.sendWithPromise("Terminate", null);
waitOn.push(terminated);
Promise.all(waitOn).then(() => {
this.commonObjs.clear();
this.fontLoader.clear();
this._hasJSActionsPromise = null;

if (this._networkStream) {
this._networkStream.cancelAllRequests(
new AbortException("Worker was terminated.")
Expand Down Expand Up @@ -2577,7 +2580,10 @@ class WorkerTransport {
}

hasJSActions() {
return this.messageHandler.sendWithPromise("HasJSActions", null);
return (this._hasJSActionsPromise ||= this.messageHandler.sendWithPromise(
"HasJSActions",
null
));
}

getCalculationOrderIds() {
Expand Down Expand Up @@ -2679,6 +2685,7 @@ class WorkerTransport {
}
this.commonObjs.clear();
this.fontLoader.clear();
this._hasJSActionsPromise = null;
});
}

Expand Down
4 changes: 2 additions & 2 deletions web/annotation_layer_builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ class DefaultAnnotationLayerFactory {
* for annotation icons. Include trailing slash.
* @param {boolean} renderInteractiveForms
* @param {IL10n} l10n
* @param {boolean} enableScripting
* @param {Promise<boolean>} hasJSActionsPromise
* @param {boolean} [enableScripting]
* @param {Promise<boolean>} [hasJSActionsPromise]
* @returns {AnnotationLayerBuilder}
*/
createAnnotationLayerBuilder(
Expand Down
18 changes: 10 additions & 8 deletions web/base_viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -469,8 +469,7 @@ class BaseViewer {
}
const pagesCount = pdfDocument.numPages;
const firstPagePromise = pdfDocument.getPage(1);

const annotationStorage = pdfDocument.annotationStorage;
// Rendering (potentially) depends on this, hence fetching it immediately.
const optionalContentConfigPromise = pdfDocument.getOptionalContentConfig();

this._pagesCapability.promise.then(() => {
Expand Down Expand Up @@ -521,7 +520,6 @@ class BaseViewer {
id: pageNum,
scale,
defaultViewport: viewport.clone(),
annotationStorage,
optionalContentConfigPromise,
renderingQueue: this.renderingQueue,
textLayerFactory,
Expand Down Expand Up @@ -1244,11 +1242,14 @@ class BaseViewer {
/**
* @param {HTMLDivElement} pageDiv
* @param {PDFPage} pdfPage
* @param {AnnotationStorage} [annotationStorage] - Storage for annotation
* data in forms.
* @param {string} [imageResourcesPath] - Path for image resources, mainly
* for annotation icons. Include trailing slash.
* @param {boolean} renderInteractiveForms
* @param {IL10n} l10n
* @param {boolean} [enableScripting]
* @param {Promise<boolean>} [hasJSActionsPromise]
* @returns {AnnotationLayerBuilder}
*/
createAnnotationLayerBuilder(
Expand All @@ -1258,21 +1259,22 @@ class BaseViewer {
imageResourcesPath = "",
renderInteractiveForms = false,
l10n = NullL10n,
enableScripting = false
enableScripting = false,
hasJSActionsPromise = null
) {
return new AnnotationLayerBuilder({
pageDiv,
pdfPage,
annotationStorage,
annotationStorage:
annotationStorage || this.pdfDocument?.annotationStorage,
imageResourcesPath,
renderInteractiveForms,
linkService: this.linkService,
downloadManager: this.downloadManager,
l10n,
enableScripting,
hasJSActionsPromise: enableScripting
? this.pdfDocument.hasJSActions()
: Promise.resolve(false),
hasJSActionsPromise:
hasJSActionsPromise || this.pdfDocument?.hasJSActions(),
});
}

Expand Down
8 changes: 3 additions & 5 deletions web/pdf_page_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@ import { viewerCompatibilityParams } from "./viewer_compatibility.js";
* @property {number} id - The page unique ID (normally its number).
* @property {number} scale - The page scale display.
* @property {PageViewport} defaultViewport - The page viewport.
* @property {AnnotationStorage} [annotationStorage] - Storage for annotation
* data in forms. The default value is `null`.
* @property {Promise<OptionalContentConfig>} [optionalContentConfigPromise] -
* A promise that is resolved with an {@link OptionalContentConfig} instance.
* The default value is `null`.
Expand Down Expand Up @@ -89,7 +87,6 @@ class PDFPageView {
this.scale = options.scale || DEFAULT_SCALE;
this.viewport = defaultViewport;
this.pdfPageRotate = defaultViewport.rotation;
this._annotationStorage = options.annotationStorage || null;
this._optionalContentConfigPromise =
options.optionalContentConfigPromise || null;
this.hasRestrictedScaling = false;
Expand Down Expand Up @@ -549,11 +546,12 @@ class PDFPageView {
this.annotationLayer = this.annotationLayerFactory.createAnnotationLayerBuilder(
div,
pdfPage,
this._annotationStorage,
/* annotationStorage = */ null,
this.imageResourcesPath,
this.renderInteractiveForms,
this.l10n,
this.enableScripting
this.enableScripting,
/* hasJSActionsPromise = */ null
);
}
this._renderAnnotationLayer();
Expand Down