Commit f7f3bcc9 authored by Julie Jeongeun Kim's avatar Julie Jeongeun Kim Committed by Commit Bot

[printing] Check |preview_ui_| is bounded before calling mojo interfaces

This CL fixes the crash caused by calling mojom::PrintPreviewUI
on the unbounded |preview_ui_|.
PrepareFrameAndViewForPrint::DidStopLoading() is an implementation
of a blink::WebViewClient method and it's called when the loading
is stopped. At that time, the preview dialog could be closed
already and |preview_ui_| is unbound.

When the preview UI used legacy IPC messages, it searched the
preview UI first and then passed the messages. So, this CL adds
also checking if |preview_ui_| is bound.

Bug: 1084641,1008939
Change-Id: Ifcb80306e485c8796456512777ebc67b62e9842d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2208847Reviewed-by: default avatarLei Zhang <thestig@chromium.org>
Commit-Queue: Julie Kim <jkim@igalia.com>
Cr-Commit-Position: refs/heads/master@{#770975}
parent d657d303
......@@ -1220,8 +1220,9 @@ void PrintRenderFrameHelper::PrintForSystemDialog() {
void PrintRenderFrameHelper::SetPrintPreviewUI(
mojo::PendingAssociatedRemote<mojom::PrintPreviewUI> preview) {
preview_ui_.Bind(std::move(preview));
preview_ui_.set_disconnect_handler(base::BindOnce(
&PrintRenderFrameHelper::OnPreviewDisconnect, base::Unretained(this)));
preview_ui_.set_disconnect_handler(
base::BindOnce(&PrintRenderFrameHelper::OnPreviewDisconnect,
weak_ptr_factory_.GetWeakPtr()));
}
void PrintRenderFrameHelper::InitiatePrintPreview(
......@@ -1289,7 +1290,7 @@ void PrintRenderFrameHelper::PrintPreview(base::Value settings) {
if (print_pages_params_->params.is_first_request &&
!print_preview_context_.IsModifiable()) {
mojom::OptionsFromDocumentParamsPtr options = SetOptionsFromPdfDocument();
if (options) {
if (options && preview_ui_) {
preview_ui_->SetOptionsFromDocument(
std::move(options), print_pages_params_->params.preview_request_id);
}
......@@ -1852,14 +1853,17 @@ void PrintRenderFrameHelper::DidFinishPrinting(PrintingResult result) {
if (!is_print_ready_metafile_sent_) {
if (notify_browser_of_print_failure_) {
LOG(ERROR) << "CreatePreviewDocument failed";
if (preview_ui_)
preview_ui_->PrintPreviewFailed(cookie, ids.request_id);
} else {
if (preview_ui_)
preview_ui_->PrintPreviewCancelled(cookie, ids.request_id);
}
}
print_preview_context_.Failed(notify_browser_of_print_failure_);
break;
case INVALID_SETTINGS:
if (preview_ui_)
preview_ui_->PrinterSettingsInvalid(cookie, ids.request_id);
print_preview_context_.Failed(false);
break;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment