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

Refactor/simplify the "delayedFallback" handling in the default viewer #12056

Merged
merged 2 commits into from
Jul 8, 2020

Conversation

Snuffleupagus
Copy link
Collaborator

@Snuffleupagus Snuffleupagus commented Jul 4, 2020

There's a few things that could be improved in the current implementation, such as:

  • It's currently necessary to both manually track the featureIds which should trigger delayed fallback, as well as manually report telemetry in affected cases.
    Obviously there's only two call-sites as of now (forms and javaScript), but it still feels somewhat error-prone especially if more cases were to be added in the future. To address this, this patch adds a new (private) method which abstracts away these details from the call-sites.

  • Generally, it also seems nice to reduce and simplify the amount of state we need to store on PDFViewerApplication in order to support the "delayedFallback" functionality.
    Also, having to manually work with the "delayedFallback"-array in multiple places feels cumbersome and makes e.g. the PDFViewerApplication.fallback method less clear as to its behaviour.

  • Having code outside of PDFViewerApplication, i.e. in the event handlers, directly access properties which are marked as "private" via a leading underscore doesn't seem that great in general.
    Furthermore, having the event handlers directly deal with that should be internal state also seem unfortunate. To address this, the patch will instead make use of a new PDFViewerApplication.triggerDelayedFallback callback.

  • There's at least one code-path in the viewer, see PDFViewerApplication.error, where fallback can be called without an argument.
    It's currently possible (although maybe somewhat unlikely) that such a call could be overridden by the featureId of a pending "delayedFallback" call, thus not reporting the correct fallback reason.

  • The "delayedFallback"-state weren't being reset on document close (which shouldn't affect Firefox, but nonetheless it ought to be fixed).

Smaller diff with https://github.com/mozilla/pdf.js/pull/12056/files?w=1

web/app.js Outdated Show resolved Hide resolved
web/app.js Outdated Show resolved Hide resolved
There's a few things that could be improved in the current implementation, such as:
 - It's currently necessary to *both* manually track the `featureId`s which should trigger delayed fallback, as well as manually report telemetry in affected cases.
Obviously there's only two call-sites as of now (forms and javaScript), but it still feels somewhat error-prone especially if more cases were to be added in the future. To address this, this patch adds a new (private) method which abstracts away these details from the call-sites.

 - Generally, it also seems nice to reduce *and* simplify the amount of state we need to store on `PDFViewerApplication` in order to support the "delayedFallback" functionality.
Also, having to *manually* work with the "delayedFallback"-array in multiple places feels cumbersome and makes e.g. the `PDFViewerApplication.fallback` method less clear as to its behaviour.

 - Having code *outside* of `PDFViewerApplication`, i.e. in the event handlers, directly access properties which are marked as "private" via a leading underscore doesn't seem that great in general.
Furthermore, having the event handlers directly deal with that should be internal state also seem unfortunate. To address this, the patch will instead make use of a new `PDFViewerApplication.triggerDelayedFallback` callback.

 - There's at least one code-path in the viewer, see `PDFViewerApplication.error`, where `fallback` can be called without an argument.
It's currently possible (although maybe somewhat unlikely) that such a call *could* be overridden by the `featureId` of a pending "delayedFallback" call, thus not reporting the *correct* fallback reason.

 - The "delayedFallback"-state weren't being reset on document close (which shouldn't affect Firefox, but nonetheless it ought to be fixed).
…target

Given the dummy-methods on `DefaultExternalServices`, there's no longer any compelling reason not to (attempt to) report telemetry unconditionally.

The only larger change consists of moving the `KNOWN_VERSIONS` and `KNOWN_GENERATORS` arrays ouf of the `PDFViewerApplication._initializeMetadata` method.

*Please note:* Most of this patch consists of whitespace-only changes.
@Snuffleupagus
Copy link
Collaborator Author

/botio-linux preview

@pdfjsbot
Copy link

pdfjsbot commented Jul 8, 2020

From: Bot.io (Linux m4)


Received

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

Live output at: http://54.67.70.0:8877/b647bc048bab574/output.txt

@pdfjsbot
Copy link

pdfjsbot commented Jul 8, 2020

From: Bot.io (Linux m4)


Success

Full output at http://54.67.70.0:8877/b647bc048bab574/output.txt

Total script time: 3.36 mins

Published

@timvandermeij timvandermeij merged commit 72d71ba into mozilla:master Jul 8, 2020
@timvandermeij
Copy link
Contributor

Thank you for improving this code!

@Snuffleupagus Snuffleupagus deleted the _delayedFallback branch July 9, 2020 07:30
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