Skip to content

Commit

Permalink
M109: Print Preview: Fix regression where afterprint event does not f…
Browse files Browse the repository at this point in the history
…ire.

When window.print() gets called, the browser-side handler for this
renderer triggered JS function does not properly set up a Mojo
communication channel from the browser-side. When the Print Preview
dialog closes, the browser fails to let the renderer know, and the
renderer fails to fire the afterprint event as a result.

Prior to https://crrev.com/1065832, the excessive browser to renderer
IPCs usually manages to set up the Mojo channel, thus masking this
issue. With those IPCs removed, this bug shows up. Fix this in
PrintViewManager::SetupScriptedPrintPreview() by explicitly setting up
the Mojo channel.

(cherry picked from commit 9ed33fc)

Bug: 1406838
Change-Id: Id5b803d749b2e47ead474f447e107000eead65f7
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4175682
Reviewed-by: Alan Screen <awscreen@chromium.org>
Commit-Queue: Lei Zhang <thestig@chromium.org>
Cr-Original-Commit-Position: refs/heads/main@{#1093990}
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4181802
Cr-Commit-Position: refs/branch-heads/5414@{#1420}
Cr-Branched-From: 4417ee5-refs/heads/main@{#1070088}
  • Loading branch information
leizleiz authored and Chromium LUCI CQ committed Jan 19, 2023
1 parent 2a7d1fc commit 8502fb7
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions chrome/browser/printing/print_view_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,11 @@ void PrintViewManager::SetupScriptedPrintPreview(
return;
}

// Since window.print() is renderer-initiated, explicitly establish a
// connection to the RenderFrame here. Without this, later operations that
// expect the established connection can unexpected fail.
GetPrintRenderFrame(rfh);

DCHECK(!print_preview_rfh_);
print_preview_rfh_ = rfh;
print_preview_state_ = SCRIPTED_PREVIEW;
Expand Down

0 comments on commit 8502fb7

Please sign in to comment.