-
Notifications
You must be signed in to change notification settings - Fork 10.1k
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
[Scripting] Try to ensure that the WillPrint
/DidPrint
respectively DidSave
events are always dispatched
#12771
[Scripting] Try to ensure that the WillPrint
/DidPrint
respectively DidSave
events are always dispatched
#12771
Conversation
…y `DidSave` events are always dispatched Note that currently the `DidSave` event is not *guaranteed* to actually be dispatched if there's any errors during saving, which is easily fixed by simply moving it to occur in the `finally`-handler in `PDFViewerApplication.save` method. For the `WillPrint`/`DidPrint` events, things are unfortunately more complicated. Currently these events will *only* be dispatched iff the printing request comes from within the viewer itself (e.g. by the user clicking on the "Print" toolbar button), however printing can be triggered in a few additional ways: - In the GENERIC viewer: - By the <kbd>Ctrl</kbd>+<kbd>P</kbd> keyboard shortcut. - In the MOZCENTRAL viewer, i.e. the Firefox built-in viewer: - By the <kbd>Ctrl</kbd>+<kbd>P</kbd> keyboard shortcut. - By the "Print" item, as found in either the Firefox "Hamburger menu" or in the browser-window menu. In either of the cases described above, no `WillPrint`/`DidPrint` events will be dispatched. In order to *guarantee* that things work in the general case, we thus have to move the `dispatchEventInSandbox` calls to the "beforeprint"/"afterprint" event handlers instead.
256d603
to
7e35a8c
Compare
…n the viewer Given that the `dispatchEventInSandbox` method (on the scripting-classes) is asynchronous, there's a very real risk that the events won't be dispatched/handled until *after* their associated functionality has actually run (with the "Will..." events being particularily susceptible to this issue). To reduce the likelihood of that happening, we can simply `await` the `dispatchEventInSandbox` calls as necessary. A couple of methods are now marked as `async` to support these changes, however that shouldn't be a problem as far as I can tell. *Please note:* Given that the browser "beforeprint"/"afterprint" events are *synchronous*, we unfortunately cannot await the `WillPrint`/`DidPrint` event dispatching. To fix this properly the web-platform would need support for asynchronous printing, and we'll thus have to hope that things work correctly anyway.
7e35a8c
to
a4786c9
Compare
/botio integrationtest |
From: Bot.io (Windows)ReceivedCommand cmd_integrationtest from @Snuffleupagus received. Current queue size: 0 Live output at: http://3.101.106.178:8877/08ff9f0af4470b6/output.txt |
From: Bot.io (Linux m4)ReceivedCommand cmd_integrationtest from @Snuffleupagus received. Current queue size: 0 Live output at: http://54.67.70.0:8877/7b1b5445fe690da/output.txt |
From: Bot.io (Linux m4)SuccessFull output at http://54.67.70.0:8877/7b1b5445fe690da/output.txt Total script time: 2.63 mins
|
From: Bot.io (Windows)SuccessFull output at http://3.101.106.178:8877/08ff9f0af4470b6/output.txt Total script time: 3.61 mins
|
I added some integration tests here: #12774 |
[Scripting] Try to ensure that the
WillPrint
/DidPrint
respectivelyDidSave
events are always dispatchedNote that currently the
DidSave
event is not guaranteed to actually be dispatched if there's any errors during saving, which is easily fixed by simply moving it to occur in thefinally
-handler inPDFViewerApplication.save
method.For the
WillPrint
/DidPrint
events, things are unfortunately more complicated. Currently these events will only be dispatched iff the printing request comes from within the viewer itself (e.g. by the user clicking on the "Print" toolbar button), however printing can be triggered in a few additional ways:In either of the cases described above, no
WillPrint
/DidPrint
events will be dispatched. In order to guarantee that things work in the general case, we thus have to move thedispatchEventInSandbox
calls to the "beforeprint"/"afterprint" event handlers instead.[Scripting] Await manually triggered
dispatchEventInSandbox
calls in the viewerGiven that the
dispatchEventInSandbox
method (on the scripting-classes) is asynchronous, there's a very real risk that the events won't be dispatched/handled until after their associated functionality has actually run (with the "Will..." events being particularily susceptible to this issue).To reduce the likelihood of that happening, we can simply
await
thedispatchEventInSandbox
calls as necessary. A couple of methods are now marked asasync
to support these changes, however that shouldn't be a problem as far as I can tell.Please note: Given that the browser "beforeprint"/"afterprint" events are synchronous, we unfortunately cannot await the
WillPrint
/DidPrint
event dispatching. To fix this properly the web-platform would need support for asynchronous printing, and we'll thus have to hope that things work correctly anyway./cc @calixteman