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() { ...@@ -1220,8 +1220,9 @@ void PrintRenderFrameHelper::PrintForSystemDialog() {
void PrintRenderFrameHelper::SetPrintPreviewUI( void PrintRenderFrameHelper::SetPrintPreviewUI(
mojo::PendingAssociatedRemote<mojom::PrintPreviewUI> preview) { mojo::PendingAssociatedRemote<mojom::PrintPreviewUI> preview) {
preview_ui_.Bind(std::move(preview)); preview_ui_.Bind(std::move(preview));
preview_ui_.set_disconnect_handler(base::BindOnce( preview_ui_.set_disconnect_handler(
&PrintRenderFrameHelper::OnPreviewDisconnect, base::Unretained(this))); base::BindOnce(&PrintRenderFrameHelper::OnPreviewDisconnect,
weak_ptr_factory_.GetWeakPtr()));
} }
void PrintRenderFrameHelper::InitiatePrintPreview( void PrintRenderFrameHelper::InitiatePrintPreview(
...@@ -1289,7 +1290,7 @@ void PrintRenderFrameHelper::PrintPreview(base::Value settings) { ...@@ -1289,7 +1290,7 @@ void PrintRenderFrameHelper::PrintPreview(base::Value settings) {
if (print_pages_params_->params.is_first_request && if (print_pages_params_->params.is_first_request &&
!print_preview_context_.IsModifiable()) { !print_preview_context_.IsModifiable()) {
mojom::OptionsFromDocumentParamsPtr options = SetOptionsFromPdfDocument(); mojom::OptionsFromDocumentParamsPtr options = SetOptionsFromPdfDocument();
if (options) { if (options && preview_ui_) {
preview_ui_->SetOptionsFromDocument( preview_ui_->SetOptionsFromDocument(
std::move(options), print_pages_params_->params.preview_request_id); std::move(options), print_pages_params_->params.preview_request_id);
} }
...@@ -1852,15 +1853,18 @@ void PrintRenderFrameHelper::DidFinishPrinting(PrintingResult result) { ...@@ -1852,15 +1853,18 @@ void PrintRenderFrameHelper::DidFinishPrinting(PrintingResult result) {
if (!is_print_ready_metafile_sent_) { if (!is_print_ready_metafile_sent_) {
if (notify_browser_of_print_failure_) { if (notify_browser_of_print_failure_) {
LOG(ERROR) << "CreatePreviewDocument failed"; LOG(ERROR) << "CreatePreviewDocument failed";
preview_ui_->PrintPreviewFailed(cookie, ids.request_id); if (preview_ui_)
preview_ui_->PrintPreviewFailed(cookie, ids.request_id);
} else { } else {
preview_ui_->PrintPreviewCancelled(cookie, ids.request_id); if (preview_ui_)
preview_ui_->PrintPreviewCancelled(cookie, ids.request_id);
} }
} }
print_preview_context_.Failed(notify_browser_of_print_failure_); print_preview_context_.Failed(notify_browser_of_print_failure_);
break; break;
case INVALID_SETTINGS: case INVALID_SETTINGS:
preview_ui_->PrinterSettingsInvalid(cookie, ids.request_id); if (preview_ui_)
preview_ui_->PrinterSettingsInvalid(cookie, ids.request_id);
print_preview_context_.Failed(false); print_preview_context_.Failed(false);
break; break;
#endif // BUILDFLAG(ENABLE_PRINT_PREVIEW) #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW)
......
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