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

Re-factor the code to remove all uses of PDFViewerApplication.downloadComplete #18463

Merged
merged 2 commits into from
Jul 20, 2024

Conversation

Snuffleupagus
Copy link
Collaborator

  • Stop using downloadComplete in PDFViewerApplication.progress

    This was only necessary to prevent (unlikely) visual glitches when disableAutoFetch = true is being used.
    However, it turns out that we can move this functionality into the ProgressBar class instead by checking if the entire PDF document has loaded. This works since the API is always reporting 100% loading progress regardless of how the document was loaded; see this code.

  • Avoid downloading the document twice in PDFViewerApplication.download

    The old implementation in PDFViewerApplication.download means that if the getDocument-call hasn't yet downloaded the entire PDF document it will be re-downloaded. This seems generally undesirable since:

    • In some (probably rare) cases a URL may not be valid an arbitrary number of times, which means that the download may fail.
    • It will lead to wasted resources, since we'll end up fetching the same PDF document twice in that case (once via the getDocument-call and once to allow the user to save it).

    Hence this patch suggests that we change this very old code to instead always call the PDFDocumentProxy.getData method, since that'll trigger immediate downloading of the remaining document via the existing getDocument-call.

    Finally, the patch removes the PDFViewerApplication.downloadComplete property since it's now unused.

This was only necessary to prevent (unlikely) visual glitches when `disableAutoFetch = true` is being used.
However, it turns out that we can move this functionality into the `ProgressBar` class instead by checking if the entire PDF document has loaded. This works since the API is always reporting 100% loading progress regardless of how the document was loaded; see [this code](https://github.com/mozilla/pdf.js/blob/ed83d7c5e16798a56c493d56aaa8200dd280bb17/src/display/api.js#L2735-L2740).
The old implementation in `PDFViewerApplication.download` means that if the `getDocument`-call hasn't yet downloaded the *entire* PDF document it will be re-downloaded. This seems generally undesirable since:
 - In some (probably rare) cases a URL may not be valid an arbitrary number of times, which means that the download may fail.
 - It will lead to wasted resources, since we'll end up fetching the same PDF document *twice* in that case (once via the `getDocument`-call and once to allow the user to save it).

Hence this patch suggests that we change this very old code to instead always call the `PDFDocumentProxy.getData` method, since that'll trigger immediate downloading of the remaining document via the existing `getDocument`-call.

Finally, the patch removes the `PDFViewerApplication.downloadComplete` property since it's now unused.
@timvandermeij
Copy link
Contributor

/botio-linux preview

@moz-tools-bot
Copy link
Collaborator

From: Bot.io (Linux m4)


Received

Command cmd_preview from @timvandermeij received. Current queue size: 0

Live output at: http://54.241.84.105:8877/29025d32dd12097/output.txt

@moz-tools-bot
Copy link
Collaborator

From: Bot.io (Linux m4)


Success

Full output at http://54.241.84.105:8877/29025d32dd12097/output.txt

Total script time: 1.04 mins

Published

@timvandermeij timvandermeij merged commit 7a8acee into mozilla:master Jul 20, 2024
7 checks passed
@timvandermeij
Copy link
Contributor

Thank you for simplifying this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants