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

Reset state upon load if showPreviousViewOnLoad #5680

Merged
merged 1 commit into from Mar 2, 2015

Conversation

Rob--W
Copy link
Member

@Rob--W Rob--W commented Jan 27, 2015

Fixes #5648

@Snuffleupagus
Copy link
Collaborator

I'm sorry, but given the asynchronous nature of the code involved I don't understand how we can guarantee that this will work (even if it currently does).
For it to work reliably, the code in the patch needs to be executed before viewer.js#L869. Note how both firstPagePromise and the preference fetching are async.
If these async operations happen in the wrong order, not only will the code in this PR not work, but it would also cause breakage in the history.

I'm instead suggesting that we move Preferences.get('showPreviousViewOnLoad') up to the rest of the prefs near the top of the file, and then place the code in this patch immediately before viewer.js#L869.
This would also, for free, prevent any possible issues with the browser not supporting replaceState.

Edit: Yes, I'm aware that this means that the pref won't be read again if a new file is opened in the viewer. However, I regard that as an edge case (given the main use-case for the default viewer), and I'm more worried about this patch causing unnecessary and easily preventable regressions in the future.

@Rob--W
Copy link
Member Author

Rob--W commented Feb 27, 2015

If you worry about race conditions, what about:

        showPreviousViewOnLoadPromise.then(function() {
            PDFHistory.initialize(self.documentFingerprint, self);
        });

@Snuffleupagus
Copy link
Collaborator

That would introduce a completely unnecessary dependency between the history and the preferences.
If we fail to initialize the preferences, this means that the history wouldn't work either, which would be bad.
All in all, since this is really an edge case I think that we should complicate it as little as possible, hence why I'm suggesting to move the preference fetching code to one central spot.

@Rob--W Rob--W force-pushed the forget-showPreviousViewOnLoad branch from e0c90f8 to 1bead89 Compare February 28, 2015 11:30
@Rob--W
Copy link
Member Author

Rob--W commented Feb 28, 2015

@Snuffleupagus Done.

I guess that by the same reasoning, we should move defaultZoomValue up.

I've noticed that we're using var self = this; in various places, where this is just the singletion PDFViewerApplication. To make it easier to search for the declarations and uses of certain properties, shouldn't we get rid of self.foo and use PDFViewerApplication.foo directly?

@Snuffleupagus
Copy link
Collaborator

Seems fine, but please also add preferenceShowPreviousViewOnLoad: true here: https://github.com/mozilla/pdf.js/blob/master/web/viewer.js#L112.

I guess that by the same reasoning, we should move defaultZoomValue up.

Yes, I think that would be best.
The reason that this code is spread out, is that the various pieces was added at different points in time, and no-one got around to moving it yet (hence the TODO).
(The recent effort, as far as refactoring the viewer code, has been (and still is) on preparation work to be able to release embeddable viewer APIs, see e.g. the viewer components.)

I've noticed that we're using var self = this; in various places, where this is just the singletion PDFViewerApplication. To make it easier to search for the declarations and uses of certain properties, shouldn't we get rid of self.foo and use PDFViewerApplication.foo directly?

It's fairly common in the PDF.js codebase to use self as an alias for this of the surrounding scope, to avoid the need to create unnecessary closures with bind(this).
Considering the length of e.g. PDFViewerApplication vs self, spelling it out actually feels slightly unwieldy to me. (Anyway, I think this discussion is out of scope of the current PR.)

@Rob--W Rob--W force-pushed the forget-showPreviousViewOnLoad branch from 1bead89 to 3f96ff7 Compare March 2, 2015 20:34
And moved showPreviousViewOnLoad up to PDFViewerApplication.initialize
@Rob--W Rob--W force-pushed the forget-showPreviousViewOnLoad branch from 3f96ff7 to 6a16d7d Compare March 2, 2015 20:36
@Rob--W
Copy link
Member Author

Rob--W commented Mar 2, 2015

@Snuffleupagus Done. Moving the other parameter can be done in a separate commit.

Snuffleupagus added a commit that referenced this pull request Mar 2, 2015
Reset state upon load if showPreviousViewOnLoad
@Snuffleupagus Snuffleupagus merged commit 43e6de7 into mozilla:master Mar 2, 2015
@Snuffleupagus
Copy link
Collaborator

Thanks for the patch!

speedplane pushed a commit to speedplane/pdf.js that referenced this pull request Mar 4, 2015
…Load

Reset state upon load if showPreviousViewOnLoad
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.

'Show previous position upon load' preference not set correctly
3 participants