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

fix: crash on printer dialog cancellation #32632

Merged
merged 3 commits into from Feb 1, 2022
Merged

Conversation

codebytere
Copy link
Member

@codebytere codebytere commented Jan 26, 2022

Description of Change

Closes #32684.

This PR fixes a crash that occurred when a user attempted to print a document either with window.print(), the print button in the PDF viewer, or with BrowserWindow.webContents() and clicked cancel in the resulting print dialog. This was introduced in e693ad9 as a result of an attempt to handle upstream changed in CL:3305095. This added a new function OnUserInitCancelled to the PrintJob Observer with the intent that when a job was cancelled it would broadcast to an observed function OnUserInitCancelled() in PrintViewManagerBase. However, there is one critical problem with that - that print_job_ does not exist that that point and is intialized afterwards here. As such, print_job->OnUserInitCancelled() was a null pointer crash. We fix this by moving the cancellation check to ScriptedPrintReplyOnIO.

Checklist

Release Notes

Notes: Fixed a crash that occurred when a user attempted to print a document either with window.print(), the print button in the PDF viewer, or with BrowserWindow.webContents() and clicked cancel in the resulting print dialog

@codebytere codebytere requested a review from a team as a code owner January 26, 2022 15:52
@electron-cation electron-cation bot added the new-pr 🌱 PR opened in the last 24 hours label Jan 26, 2022
Copy link
Member

@VerteDinde VerteDinde left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! 🙇‍♀️

@codebytere codebytere added the semver/patch backwards-compatible bug fixes label Jan 26, 2022
@electron-cation electron-cation bot removed the new-pr 🌱 PR opened in the last 24 hours label Jan 27, 2022
@deepak1556
Copy link
Member

ScriptedPrintReplyOnIO will yield back to UI thread via ScriptedPrintReply , the user cancellation check can be performed there and end up calling UserInitCancelled directly. This will reduce the patch to not pass around the manager class weak ptr to the different sequences and also avoid the necessity to create a separate UI task NotifyUserCancelled

Another question, the scripted print sequences will be triggered for renderer initiated print calls like the pdf viewer print and window.print but will this also handle the case for webContents.print as mentioned in the PR description ?

@codebytere
Copy link
Member Author

@deepak1556 updated and tested with https://gist.github.com/0f0e776b138452d6815ef4efc16aa0d1 to confirm that this fix covers relevant scenarios.

@codebytere codebytere merged commit 56c6d25 into main Feb 1, 2022
@codebytere codebytere deleted the fix-printer-cancellation branch February 1, 2022 19:00
@release-clerk
Copy link

release-clerk bot commented Feb 1, 2022

Release Notes Persisted

Fixed a crash that occurred when a user attempted to print a document either with window.print(), the print button in the PDF viewer, or with BrowserWindow.webContents() and clicked cancel in the resulting print dialog

@trop
Copy link
Contributor

trop bot commented Feb 1, 2022

I was unable to backport this PR to "17-x-y" cleanly;
you will need to perform this backport manually.

@pushkin-
Copy link

When can we expect a backport of this (to 17)?

@trop
Copy link
Contributor

trop bot commented Feb 21, 2022

@codebytere has manually backported this PR to "17-x-y", please check out #33015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver/patch backwards-compatible bug fixes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Cancelling print causes electron to crash
6 participants