Commit Graph

81 Commits

Author SHA1 Message Date
Jonas Jenwald
388851e37b Add a isDestsEqual helper function, to allow comparing explicit destinations, in pdf_history.js 2017-08-30 19:45:13 +02:00
Jonas Jenwald
28ce3b6185 Rip out the current implementation of PDFHistory
The current implementation of `PDFHistory` contains a number of smaller bugs, which are *very* difficult to address without breaking other parts of its code.
Possibly the main issue with the current implementation, is that I wrote it quite some time ago, and at the time my understanding of the various edge-cases the code has to deal with was quite limited.
Currently `PDFHistory` may, despite most of those cases being fixed, in certain edge-cases lock-up the browser history, essentially preventing the user from navigating back/forward.

Hence rather than trying to iterate on `PDFHistory` to make it better, the only viable approach is unfortunately rip it out in its entirety and re-write it from scratch.
2017-08-30 19:45:13 +02:00
Jonas Jenwald
223c429357 Fix inconsistent spacing and trailing commas in objects in web/ files, so we can enable the comma-dangle and object-curly-spacing ESLint rules later on
http://eslint.org/docs/rules/comma-dangle
http://eslint.org/docs/rules/object-curly-spacing

Given that we currently have quite inconsistent object formatting, fixing this in in *one* big patch probably wouldn't be feasible (since I cannot imagine anyone wanting to review that); hence I've opted to try and do this piecewise instead.

*Please note:* This patch was created automatically, using the ESLint `--fix` command line option. In a couple of places this caused lines to become too long, and I've fixed those manually; please refer to the interdiff below for the only hand-edits in this patch.

```diff
diff --git a/web/pdf_thumbnail_view.js b/web/pdf_thumbnail_view.js
index 002dbf29..1de4e530 100644
--- a/web/pdf_thumbnail_view.js
+++ b/web/pdf_thumbnail_view.js
@@ -420,8 +420,8 @@ var PDFThumbnailView = (function PDFThumbnailViewClosure() {
     setPageLabel: function PDFThumbnailView_setPageLabel(label) {
       this.pageLabel = (typeof label === 'string' ? label : null);

-      this.l10n.get('thumb_page_title', { page: this.pageId, }, 'Page {{page}}').
-          then((msg) => {
+      this.l10n.get('thumb_page_title', { page: this.pageId, },
+                    'Page {{page}}').then((msg) => {
         this.anchor.title = msg;
       });

diff --git a/web/secondary_toolbar.js b/web/secondary_toolbar.js
index 160e0410..6495fc5e 100644
--- a/web/secondary_toolbar.js
+++ b/web/secondary_toolbar.js
@@ -65,7 +65,8 @@ class SecondaryToolbar {
       { element: options.printButton, eventName: 'print', close: true, },
       { element: options.downloadButton, eventName: 'download', close: true, },
       { element: options.viewBookmarkButton, eventName: null, close: true, },
-      { element: options.firstPageButton, eventName: 'firstpage', close: true, },
+      { element: options.firstPageButton, eventName: 'firstpage',
+        close: true, },
       { element: options.lastPageButton, eventName: 'lastpage', close: true, },
       { element: options.pageRotateCwButton, eventName: 'rotatecw',
         close: false, },
@@ -76,7 +77,7 @@ class SecondaryToolbar {
       { element: options.cursorHandToolButton, eventName: 'switchcursortool',
         eventDetails: { tool: CursorTool.HAND, }, close: true, },
       { element: options.documentPropertiesButton,
-        eventName: 'documentproperties', close: true, }
+        eventName: 'documentproperties', close: true, },
     ];
     this.items = {
       firstPage: options.firstPageButton,
```
2017-06-01 12:47:47 +02:00
Jonas Jenwald
79e0745a12 Import getGlobalEventBus correctly from web/dom_events.js in various /web files, to un-break e.g. the viewer components (PR 8203 follow-up)
In PR 8203, I somehow managed to mess up the import of `getGlobalEventBus` in *all* files where it's present; my sincere apologies for this!
2017-04-17 00:54:29 +02:00
Yury Delendik
8e681ce3e2 Change amd to cjs path in ES6 modules 2017-04-14 10:32:36 -05:00
Jonas Jenwald
3b35c15d42 Convert the files in the /web folder to ES6 modules
Note that as discussed on IRC, this makes the viewer slightly slower to load *only* in `gulp server` mode, however the difference seem slight enough that I think it will be fine.
2017-04-09 11:55:48 +02:00
Jonas Jenwald
70c1a6b120 [Bug 1331081] omit addEventListener/removeEventListener's third parameter when it's false
Upstream changes from https://bugzilla.mozilla.org/show_bug.cgi?id=1331081; this patch also covers one file, `pdf_print_service.js`, that's not present in mozilla-central.

Fixes 7962.
2017-01-17 17:50:21 +01:00
Jonas Jenwald
4046d67fde Enable the no-else-return ESLint rule
Using `else` after `return` is not necessary, and can often lead to unnecessarily cluttered code. By using the `no-else-return` rule in ESLint we can avoid this pattern, see http://eslint.org/docs/rules/no-else-return.
2017-01-09 20:27:39 +01:00
Yury Delendik
0576c9c6c6 Replaces all preprocessor directives with PDFJSDev calls. 2016-10-14 10:57:53 -05:00
Yury Delendik
32ce369d88 Fixes some static analysis warnings and recommendations
* Useless conditional
* Superfluous trailing arguments
* Useless assignment to local variable
* Misspelled identifier
* JSDoc tag for non-existent parameter
2016-05-02 17:34:58 -05:00
Yury Delendik
7fd3db9977 Adds EventBus. 2016-04-28 06:57:24 -05:00
Yury Delendik
006e8fb59d Introduces UMD headers to the web/ folder. 2016-04-13 10:09:48 -05:00
Manas
a2ba1b8189 Uses editorconfig to maintain consistent coding styles
Removes the following as they unnecessary
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set shiftwidth=2 tabstop=2 autoindent cindent expandtab: */
2015-11-14 07:32:18 +05:30
Rob Wu
cdea75dc39 Refactor the previous history rewriting logic
When the user edits the URL and changes the reference fragment (hash),
PDF.js intercepts this action, and saves the then-current history state
in the previous history entry. This is implemented by navigating back,
editing the history and navigating forward again.

The current logic has a flaw: It assumes that calling history.back() and
history.forward() immediately updates the history state. This is however
not guaranteed by the web standards, which states that calling e.g.
history.back "must traverse the history by a delta -1", which means that
the browser must QUEUE a task to traverse the session history, per spec:
http://w3.org/TR/2011/WD-html5-20110113/history.html#dom-history-back
https://html.spec.whatwg.org/multipage/browsers.html#dom-history-back

Firefox and Internet Explorer deviate from the standards by immediately
changing the history state instead of queuing the navigation.
WebKit derived browsers (Chrome, Opera, Safari) and Opera presto do not.

The user-visible consequence of strictly adhering to the standards in
PDF.js can be shown as follows:

1. Edit the URL.
2. Append #page=2 for example.
3. Press Enter.
   -> Presto and WebKit: PDF.js reverts to the previous URL.
   -> Gecko and Trident: PDF.js keeps the new URL, as expected.

To fix the issue, modification of the previous history item happens in
a few asynchronous steps, guided by the popstate event to detect when
the history navigation request has been committed.

--
Some more implementation notes:

I have removed the preventDefault and stopPropagation calls, because
popstate is not cancelable, and window is already the last target of the
event propagation.

The previous allowHashChange logic was hard to follow, because it did
not explain that hashchange will be called twice; once during the
popstate handler for history.back() (which will reset allowHashChange),
and again for history.forward() (where allowHashChange will be false).
The purpose of allowHashChange is now more explicit, by incorporating
the logic in the replacePreviousHistoryState helper function.
2015-09-26 23:15:29 +02:00
Rob Wu
adb2f8ae21 [CRX] Add Referer request header if needed
This patch adds the Referer request header to PDF requests if
the original PDF request included the Referer header.
2015-06-05 23:24:40 +02:00
Yury Delendik
5cff06e52a Refactors PDFHistory.
# Conflicts:
#	extensions/b2g/viewer.js
#	web/pdf_history.js
#	web/pdf_viewer.component.js
#	web/viewer.js
2015-05-16 11:20:36 -05:00
Jonas Jenwald
2dc1af8028 Break dependencies between PresentationMode and other code, and add PresentationMode related utility methods to PDFViewer
This patch:
 - Adds a couple of utility methods to `PDFViewer` to enable checking `presentationModeState` without cumbersome comparisons.

 - Disentangles `PresentationMode` from `PDFHistory` and `HandTool`, by adding event listeners for `presentationmodechanged` to both of them.

 - Adds a utility function to `PDFViewerApplication` for requesting PresentationMode.

 - Prevents initialization of `PresentationMode` if the browser does not support the fullscreen API.
2015-04-21 16:02:32 +02:00
Yury Delendik
44779f14b0 Renames and refactors PDFView to PDFViewerApplication. 2014-09-28 10:39:56 -05:00
Rob Wu
aeaf11ca43 [CRX] Fall back to sender.tab.url if !tab.url
sender.url is relatively new (Chromium 29)
 ( https://chromiumcodereview.appspot.com/14301016 )
2014-01-25 20:15:43 +01:00
Rob Wu
8526d3c600 [CRX] Add a pageAction to omnibox showing PDF URL
In Chromium extensions, the viewer's URL looks like this:
chrome-extension://oemmndcbldboiebfnladdacbdfmadadm/http://example.com/file.pdf

Furthermore, the PDF Viewer itself can also add something to the reference fragment:
chrome-extension://oemmndcbldboiebfnladdacbdfmadadm/http://example.com/file.pdf#page=2

Consequently, it is difficult to copy a clean URL (e.g. for sharing over mail)
without having to tidy-up the URL manually.

This commit solves this issue by adding a button to the omnibox,
which shows the clean PDF URL on click.
2013-12-16 19:00:32 +01:00
Jonas Jenwald
44725d4657 [PDFHistory] Fix "Warning: Unhandled rejection: [Exception... "The operation is insecure."" in Firefox 25 2013-11-23 12:15:39 +01:00
Jonas Jenwald
ca8e3ea06f [PDFHistory] Fix "Warning: Unhandled rejection: [Exception... "The operation is insecure."" when opening local file 2013-11-22 11:49:16 +01:00
Brendan Dahl
2d489bab22 Merge pull request #3582 from Rob--W/pushState
Set URL in history.replaceState/pushState
2013-10-03 11:35:36 -07:00
Jonas Jenwald
bfc66626a0 Move Presentation Mode related code from viewer.js to its own file 2013-10-01 23:11:46 +02:00
Jonas Jenwald
fc73dbe695 [PDFHistory] Prevent the history from skipping entries in certain edge cases, when specifying an initialBookmark in the hash parameters on document load 2013-09-14 17:14:04 +02:00
Brendan Dahl
189d444ded Merge pull request #3507 from Snuffleupagus/PDFHistory-fix-multiple-identical-states
[PDFHistory] Prevent the history from getting stuck in certain edge cases
2013-09-04 12:09:41 -07:00
Rob Wu
c653bf3aff Set URL in history.replaceState/pushState
When <base href> is present, history.replaceState and
history.pushState behave inconsistent with relative URLs.
http://code.google.com/p/chromium/issues/detail?id=274024

Contrary to what one expect, passing '' as the URL parameter to
replaceState/pushState does not associate the currently active
URL with the history entry, but a path relative to <base href>.

To fix the issue, explicitly associate the current active URL
with the history's state.
2013-08-16 17:30:07 +02:00
Yury Delendik
fa885678df Don't provide optional pushState parameter 2013-08-16 09:09:32 -05:00
Jonas
869c4de289 [PDFHistory] Prevent the history from getting stuck in certain edge cases 2013-07-23 21:50:09 +02:00
Jonas
d99b7753d6 Check if viewer is embedded only once and cache the result 2013-07-20 16:33:40 +02:00
Jonas
09e0c9b65d Move PDFHistory from viewer.js to its own file 2013-07-18 17:18:27 +02:00