-
Notifications
You must be signed in to change notification settings - Fork 10k
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
[api-major] Move the remaining options from, and completely remove, the global PDFJS
object
#9493
[api-major] Move the remaining options from, and completely remove, the global PDFJS
object
#9493
Conversation
/botio test |
From: Bot.io (Linux m4)ReceivedCommand cmd_test from @Snuffleupagus received. Current queue size: 0 Live output at: http://54.67.70.0:8877/f3f3d7e85d770d2/output.txt |
From: Bot.io (Windows)ReceivedCommand cmd_test from @Snuffleupagus received. Current queue size: 1 Live output at: http://54.215.176.217:8877/f9371548bb9379e/output.txt |
From: Bot.io (Linux m4)SuccessFull output at http://54.67.70.0:8877/f3f3d7e85d770d2/output.txt Total script time: 17.99 mins
|
From: Bot.io (Windows)SuccessFull output at http://54.215.176.217:8877/f9371548bb9379e/output.txt Total script time: 24.28 mins
|
I think I'll have time during the weekend to review this. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me with the comments addressed. I'm really impressed with how much work has been put in this patch! The new way of handling app options is much more consistent in my opinion.
web/app_options.js
Outdated
}, | ||
externalLinkRel: { | ||
/** @type {string} */ | ||
value: null, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the reason you're not using the LinkTarget
enumeration and DEFAULT_LINK_REL
constant here? Especially for the latter, the default was different from null
(see https://github.com/Snuffleupagus/pdf.js/blob/3c7909f2fe8329e3544942690ebf8d172bd8ae63/src/display/dom_utils.js#L22). Moreover, since this is a string type, I would at least expect ''
. If this is to avoid a dependecy on code from src
, can we add a comment somewhere in this file to indicate that?
The same applies for other options below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moreover, since this is a string type, I would at least expect
''
.
You're absolutely correct that this should be a string, however an empty string wouldn't work here; see:
pdf.js/src/display/dom_utils.js
Line 317 in 5f98f9b
link.rel = (typeof rel === 'string' ? rel : DEFAULT_LINK_REL); |
I've changed this particular line to explicitly list the "default" link rel instead; but see below as well.
If this is to avoid a dependecy on code from src, can we add a comment somewhere in this file to indicate that?
Correct, I view this (new) file somewhat similar to https://github.com/mozilla/pdf.js/blob/master/web/default_preferences.json. Even though we can, as opposed to a .json
file, import constants/types from elsewhere here I nonetheless wanted to avoid that pattern. I've tried to add a comment to that effect.
}, | ||
maxCanvasPixels: { | ||
/** @type {number} */ | ||
value: viewerCompatibilityParams.maxCanvasPixels || 16777216, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add a comment that this magic number is calculated from 4096 * 4096
(since this way in the old, removed comment). Perhaps also mention that -1
removes any limit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd very much prefer to not do that, for a couple of reasons.
First of all, the "source of truth" in the new code is the JSDocs added to the viewer components and API methods, rather than this file itself; again compare with https://github.com/mozilla/pdf.js/blob/master/web/default_preferences.json.
In this particular case, the documentation is already present in
Lines 59 to 61 in 5f98f9b
* @property {number} maxCanvasPixels - (optional) The maximum supported canvas | |
* size in total pixels, i.e. width * height. Use -1 for no limit. | |
* The default value is 4096 * 4096 (16 mega-pixels). |
Lines 59 to 61 in 5f98f9b
* @property {number} maxCanvasPixels - (optional) The maximum supported canvas | |
* size in total pixels, i.e. width * height. Use -1 for no limit. | |
* The default value is 4096 * 4096 (16 mega-pixels). |
Second of all, if we start adding that kind of comments in this file we'll probably end up doing it for a lot more options. That would add maintenance burden, since each JSDoc comment would then be duplicated twice in the code-base. Furthermore, this file would become much longer and quite unwieldy in my opinion.
web/app_options.js
Outdated
workerSrc: { | ||
/** @type {string} */ | ||
value: (typeof PDFJSDev === 'undefined' || !PDFJSDev.test('PRODUCTION') ? | ||
'../src/worker_loader.js' : '../build/pdf.worker.js'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: add an extra space here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
@@ -1512,6 +1515,9 @@ if (typeof PDFJSDev === 'undefined' || PDFJSDev.test('GENERIC')) { | |||
|
|||
function loadFakeWorker() { | |||
return new Promise(function(resolve, reject) { | |||
if (!GlobalWorkerOptions.workerSrc) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this if
statement required? As far as I can see, this should always be present because of the default in the app options.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With the new way of setting the API/worker options, in PDFViewerApplication.open
, we haven't actually set the workerSrc
by the time this code runs (which happens during initialization of the viewer itself).
Previously the workerSrc
was set earlier during the viewer initialization, see:
Line 53 in 5f98f9b
function configure(PDFJS) { |
However, with all this refactoring I wanted to unify how/when the API/worker options are set, which necessitated setting the
workerSrc
here as well.If your question is why we don't just set the
workerSrc
directly here, and simply skip this check, it's to be ever so slightly more accommodating to a custom deployment where globalWorkerOptions.workerSrc
was manually set.
@@ -26,6 +26,7 @@ import { | |||
RenderingCancelledException, StatTimer | |||
} from './dom_utils'; | |||
import { FontFaceObject, FontLoader } from './font_loader'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like the commit message of this commit is copy-pasted from the first one ;-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've tried to trim the commit messages a bit.
src/display/api.js
Outdated
@@ -169,6 +169,9 @@ function setPDFNetworkStreamFactory(pdfNetworkStreamFactory) { | |||
* of PDF files. When enabled, and if the server supports partial content | |||
* requests, then the PDF will be fetched in chunks. | |||
* The default value is `false`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like the commit message of this commit is copy-pasted from the first one ;-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've tried to trim the commit messages a bit.
src/display/api.js
Outdated
@@ -178,6 +178,9 @@ function setPDFNetworkStreamFactory(pdfNetworkStreamFactory) { | |||
* The default value is `false`. | |||
* NOTE: It is also necessary to disable streaming, see above, | |||
* in order for disabling of pre-fetching to work correctly. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like the commit message of this commit is copy-pasted from the first one ;-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've tried to trim the commit messages a bit.
container: container, | ||
linkService: pdfLinkService, | ||
}); | ||
pdfLinkService.setViewer(pdfSinglePageViewer); | ||
|
||
// (Optionally) enable find controller. | ||
var pdfFindController = new PDFJS.PDFFindController({ | ||
var pdfFindController = new pdfjsDistWebPdfViewer.PDFFindController({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For consistency with the other examples, could you add a trailing comma on the next line?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
PDFJS.ProgressBar = ProgressBar; | ||
PDFJS.GenericL10n = GenericL10n; | ||
PDFJS.NullL10n = NullL10n; | ||
const pdfjsVersion = PDFJSDev.eval('BUNDLE_VERSION'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not entirely sure why these two constants are added here because they weren't in the code before and they are not exported. What am I missing here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was probably not entirely relevant to the rest of the patch, however it addresses an in my opinion existing shortcoming.
Note how both https://github.com/mozilla/pdf.js/blob/master/src/pdf.js and https://github.com/mozilla/pdf.js/blob/master/src/pdf.worker.js contains this information (without exporting it). That can be very handy if you're looking at the built files and want to know which version/build it corresponds to.
@timvandermeij Thanks a lot for taking the time to review this, much appreciated :-) |
…y.js` and into a separate file Unfortunately, as far as I can tell, we still need the ability to adjust certain API options depending on the browser environment in PDF.js version `2.0`. However, we should be able to separate this from the general compatibility code in the `src/shared/compatibility.js` file.
…factoring of the way that viewer options are handled The way that various options are handled in the default viewer is currently a bit of a mess (to say the least). Some viewer options reside in the global `PDFJS` object, while others reside in `Preferences`. To make matters worse, some options even exist in both of the two. Since the goal, with PDF.js version `2.0`, is to reduce our usage of the global `PDFJS` object, we'll instead want pass in the options when initializing the viewer components and when calling API methods (such as `getDocument`). However given the current state of things in the default viewer, this wouldn't be exactly easy to implement. Hence this patch, which attempts to consolidate the way that viewer (and later API) options are handled by introducing a `AppOptions` singleton that provides *one* centralized way of interacting with the various options in the default viewer.
…tion.viewerPrefs` and into `AppOptions` instead
…ions` instead The `appConfig` contains (mostly) references to various DOM elements, used when initializing the viewer components. Hence `defaultUrl` seem like a slightly better fit for the new `AppOptions` abstraction, not to mention that it should thus be easier to set/modify it for custom deployments of the default viewer.
… use of `AppOptions` instead of the global `PDFJS` object
…o `getDocument` instead
…bject and into `getDocument` instead
…into `getDocument` instead
…into `getDocument` instead
… into `getDocument` instead One additional complication with removing this option from the global `PDFJS` object, is that the viewer currently needs to check `disableAutoFetch` in a couple of places. To address this I'm thus proposing adding a getter in `PDFDocumentProxy`, to allow checking the *actually* used values for a particular `getDocument` invocation.
…g `PDFDataTransportStream`/`PDFNetworkStream` in `src/display/api.js` With options being moved from the global `PDFJS` object and into `getDocument`, a side-effect is that we're now passing in a fair number of useless parameters to the various transport/network streams. Even though this doesn't *currently* cause any problems, it nonetheless seem like a good idea to explicitly provide the parameters that are actually necessary.
From: Bot.io (Linux m4)ReceivedCommand cmd_preview from @Snuffleupagus received. Current queue size: 0 Live output at: http://54.67.70.0:8877/9a338c627674a08/output.txt |
From: Bot.io (Linux m4)SuccessFull output at http://54.67.70.0:8877/9a338c627674a08/output.txt Total script time: 2.64 mins Published |
/botio test |
From: Bot.io (Windows)ReceivedCommand cmd_test from @Snuffleupagus received. Current queue size: 0 Live output at: http://54.215.176.217:8877/a537ac405e38a32/output.txt |
From: Bot.io (Linux m4)ReceivedCommand cmd_test from @Snuffleupagus received. Current queue size: 0 Live output at: http://54.67.70.0:8877/fbd0fededd352c5/output.txt |
From: Bot.io (Linux m4)SuccessFull output at http://54.67.70.0:8877/fbd0fededd352c5/output.txt Total script time: 18.21 mins
|
From: Bot.io (Windows)SuccessFull output at http://54.215.176.217:8877/a537ac405e38a32/output.txt Total script time: 24.36 mins
|
It's really good to finally get rid of the global |
PR mozilla#9493 moved from `appConfig.defaultUrl` to `AppOptions.get('defaultUrl')`. However, it forgot to replace `appConfig.defaultUrl` in chromecom.js, and as a result the extension is not able to open any PDF file. This patch fixes that issue.
PR mozilla#9493 moved from `appConfig.defaultUrl` to `AppOptions.get('defaultUrl')`. However, it forgot to replace `appConfig.defaultUrl` in chromecom.js, and as a result the extension is not able to open any PDF file. This patch fixes that issue.
PR mozilla#9493 moved from `appConfig.defaultUrl` to `AppOptions.get('defaultUrl')`. However, it forgot to replace `appConfig.defaultUrl` in chromecom.js, and as a result the extension is not able to open any PDF file. This patch fixes that issue. (cherry picked from commit 39e0b4b)
Hi, I couldn't raise an issue on the pdfjs-dist repo. We were on version 2.0.376 of pdfjs-dist and a later patch release broke the build for us as it removed the PDFJS export — we had an import line of How does the versioning of pdfjs-dist work? Why was this breaking change made in a patch release? |
@agsingletrack see #9440 |
PR mozilla#9493 moved from `appConfig.defaultUrl` to `AppOptions.get('defaultUrl')`. However, it forgot to replace `appConfig.defaultUrl` in chromecom.js, and as a result the extension is not able to open any PDF file. This patch fixes that issue.
[api-major] Move the remaining options from, and completely remove, the global `PDFJS` object
PR mozilla#9493 moved from `appConfig.defaultUrl` to `AppOptions.get('defaultUrl')`. However, it forgot to replace `appConfig.defaultUrl` in chromecom.js, and as a result the extension is not able to open any PDF file. This patch fixes that issue.
This is the final (major) piece of work required before we can release PDF.js version
2.0
, the other remaining TODOs are basically of the nice-to-have kind.I've tried to split it into as many commits as possible to aid reviewing; in some cases ignoring whitespace changes with
?w=1
should also help.@yurydelendik, @timvandermeij Please check if the new way of handling (default) viewer options makes sense here!