From cef177abc460cecd4fc9004f7f9497a222c1e13d Mon Sep 17 00:00:00 2001 From: Haojian Wu Date: Mon, 1 Jun 2015 11:08:40 +0800 Subject: [PATCH] Add preview failed error. --- .../printing/print_preview_message_handler.cc | 17 +++++++---------- .../printing/print_preview_message_handler.h | 2 +- chromium_src/chrome/common/print_messages.h | 3 +++ .../renderer/printing/print_web_view_helper.cc | 10 +++++++++- 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/chromium_src/chrome/browser/printing/print_preview_message_handler.cc b/chromium_src/chrome/browser/printing/print_preview_message_handler.cc index 36befec47915..0a3ae97afd60 100644 --- a/chromium_src/chrome/browser/printing/print_preview_message_handler.cc +++ b/chromium_src/chrome/browser/printing/print_preview_message_handler.cc @@ -141,14 +141,11 @@ void PrintPreviewMessageHandler::OnMetafileReadyForPrinting( params.preview_request_id)); } -//void PrintPreviewMessageHandler::OnPrintPreviewFailed(int document_cookie) { - //StopWorker(document_cookie); - - ////PrintPreviewUI* print_preview_ui = GetPrintPreviewUI(); - ////if (!print_preview_ui) - ////return; - ////print_preview_ui->OnPrintPreviewFailed(); -//} +void PrintPreviewMessageHandler::OnPrintPreviewFailed(int document_cookie, + int request_id) { + StopWorker(document_cookie); + RunPrintToPDFCallback(request_id, FAIL_PREVIEW); +} //void PrintPreviewMessageHandler::OnDidGetDefaultPageLayout( //const PageSizeMargins& page_layout_in_points, @@ -193,8 +190,8 @@ bool PrintPreviewMessageHandler::OnMessageReceived( OnDidPreviewPage) IPC_MESSAGE_HANDLER(PrintHostMsg_MetafileReadyForPrinting, OnMetafileReadyForPrinting) - //IPC_MESSAGE_HANDLER(PrintHostMsg_PrintPreviewFailed, - //OnPrintPreviewFailed) + IPC_MESSAGE_HANDLER(PrintHostMsg_PrintPreviewFailed, + OnPrintPreviewFailed) //IPC_MESSAGE_HANDLER(PrintHostMsg_DidGetDefaultPageLayout, //OnDidGetDefaultPageLayout) //IPC_MESSAGE_HANDLER(PrintHostMsg_PrintPreviewCancelled, diff --git a/chromium_src/chrome/browser/printing/print_preview_message_handler.h b/chromium_src/chrome/browser/printing/print_preview_message_handler.h index 5594a41f2db1..f4298fb6b2fc 100644 --- a/chromium_src/chrome/browser/printing/print_preview_message_handler.h +++ b/chromium_src/chrome/browser/printing/print_preview_message_handler.h @@ -73,7 +73,7 @@ class PrintPreviewMessageHandler void OnDidPreviewPage(const PrintHostMsg_DidPreviewPage_Params& params); void OnMetafileReadyForPrinting( const PrintHostMsg_DidPreviewDocument_Params& params); - //void OnPrintPreviewFailed(int document_cookie); + void OnPrintPreviewFailed(int document_cookie, int request_id); //void OnPrintPreviewCancelled(int document_cookie); //void OnInvalidPrinterSettings(int document_cookie); //void OnSetOptionsFromDocument( diff --git a/chromium_src/chrome/common/print_messages.h b/chromium_src/chrome/common/print_messages.h index 2e6d23771676..fc9c1d493509 100644 --- a/chromium_src/chrome/common/print_messages.h +++ b/chromium_src/chrome/common/print_messages.h @@ -332,6 +332,9 @@ IPC_MESSAGE_ROUTED1(PrintHostMsg_MetafileReadyForPrinting, IPC_MESSAGE_ROUTED1(PrintHostMsg_DidGetPreviewPageCount, PrintHostMsg_DidGetPreviewPageCount_Params /* params */) +IPC_MESSAGE_ROUTED2(PrintHostMsg_PrintPreviewFailed, + int /* document cookie */, + int /* request_id */); #if defined(OS_WIN) // Tell the utility process to start rendering the given PDF into a metafile. diff --git a/chromium_src/chrome/renderer/printing/print_web_view_helper.cc b/chromium_src/chrome/renderer/printing/print_web_view_helper.cc index 82a7b54fc2c5..550735f709b5 100644 --- a/chromium_src/chrome/renderer/printing/print_web_view_helper.cc +++ b/chromium_src/chrome/renderer/printing/print_web_view_helper.cc @@ -724,7 +724,6 @@ void PrintWebViewHelper::OnPrintPreview(const base::DictionaryValue& settings) { } LOG(ERROR) << "OnPrintPreview2"; - //SetPrintPagesParams(settings) if (!UpdatePrintSettings(print_preview_context_.source_frame(), print_preview_context_.source_node(), settings)) { DidFinishPrinting(FAIL_PREVIEW); @@ -938,6 +937,15 @@ void PrintWebViewHelper::DidFinishPrinting(PrintingResult result) { Send(new PrintHostMsg_PrintingFailed(routing_id(), cookie)); } break; + + case FAIL_PREVIEW: + LOG(ERROR) << "PREVIEW FAILED."; + if (print_pages_params_) { + Send(new PrintHostMsg_PrintPreviewFailed(routing_id(), + print_pages_params_->params.document_cookie, + print_pages_params_->params.preview_request_id)); + } + break; } prep_frame_view_.reset(); print_pages_params_.reset();