diff --git a/atom/browser/api/lib/web-contents.coffee b/atom/browser/api/lib/web-contents.coffee index 5725f0011908..865154f0cdc4 100644 --- a/atom/browser/api/lib/web-contents.coffee +++ b/atom/browser/api/lib/web-contents.coffee @@ -89,6 +89,7 @@ wrapWebContents = (webContents) -> collate:true, shouldPrintBackgrounds:false, shouldPrintSelectionOnly:false + silent:false if options.landscape printingSetting.landscape = options.landscape 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 dc7052cab1a1..9b72a9a10445 100644 --- a/chromium_src/chrome/browser/printing/print_preview_message_handler.cc +++ b/chromium_src/chrome/browser/printing/print_preview_message_handler.cc @@ -119,14 +119,21 @@ void PrintPreviewMessageHandler::OnMetafileReadyForPrinting( if (!data || !data->size()) return; - atom::NativeWindow* window = atom::NativeWindow::FromWebContents( - web_contents()); - base::FilePath save_path; - if (!file_dialog::ShowSaveDialog(window, "Save As", - base::FilePath(FILE_PATH_LITERAL("print.pdf")), - file_dialog::Filters(), &save_path)) { // Users cancel dialog. - RunPrintToPDFCallback(params.preview_request_id, FAIL_CANCEL); - return; + int request_id = params.preview_request_id; + std::string file_path = + print_to_pdf_request_details_map_[request_id].save_path; + base::FilePath save_path = + file_path.empty() ? base::FilePath(FILE_PATH_LITERAL("print.pdf")): + base::FilePath::FromUTF8Unsafe(file_path); + if (!print_to_pdf_request_details_map_[request_id].silent) { + atom::NativeWindow* window = atom::NativeWindow::FromWebContents( + web_contents()); + if (!file_dialog::ShowSaveDialog(window, "Save As", + base::FilePath(FILE_PATH_LITERAL("print.pdf")), + file_dialog::Filters(), &save_path)) { // Users cancel dialog. + RunPrintToPDFCallback(request_id, FAIL_CANCEL); + return; + } } BrowserThread::PostTaskAndReplyWithResult( BrowserThread::FILE, @@ -134,7 +141,7 @@ void PrintPreviewMessageHandler::OnMetafileReadyForPrinting( base::Bind(&SavePDF, data, save_path), base::Bind(&PrintPreviewMessageHandler::RunPrintToPDFCallback, base::Unretained(this), - params.preview_request_id)); + request_id)); } void PrintPreviewMessageHandler::OnPrintPreviewFailed(int document_cookie, @@ -165,7 +172,11 @@ void PrintPreviewMessageHandler::PrintToPDF( const atom::api::WebContents::PrintToPDFCallback& callback) { int request_id; options.GetInteger(printing::kPreviewRequestID, &request_id); - print_to_pdf_callback_map_[request_id] = callback; + PrintToPDFRequestDetails details; + options.GetBoolean("silent", &details.silent); + options.GetString("savePath", &details.save_path); + details.callback = callback; + print_to_pdf_request_details_map_[request_id] = details; content::RenderViewHost* rvh = web_contents()->GetRenderViewHost(); rvh->Send(new PrintMsg_PrintPreview(rvh->GetRoutingID(), options)); @@ -173,8 +184,9 @@ void PrintPreviewMessageHandler::PrintToPDF( void PrintPreviewMessageHandler::RunPrintToPDFCallback( int request_id, PrintPDFResult result) { - print_to_pdf_callback_map_[request_id].Run(static_cast(result)); - print_to_pdf_callback_map_.erase(request_id); + print_to_pdf_request_details_map_[request_id].callback.Run( + static_cast(result)); + print_to_pdf_request_details_map_.erase(request_id); } } // namespace printing 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 692baba36ee7..656fde4a6083 100644 --- a/chromium_src/chrome/browser/printing/print_preview_message_handler.h +++ b/chromium_src/chrome/browser/printing/print_preview_message_handler.h @@ -53,8 +53,14 @@ class PrintPreviewMessageHandler const atom::api::WebContents::PrintToPDFCallback& callback); private: - typedef std::map - PrintToPDFCallbackMap; + struct PrintToPDFRequestDetails { + std::string save_path; + bool silent; + atom::api::WebContents::PrintToPDFCallback callback; + }; + + typedef std::map + PrintToPDFRequestDetailsMap; explicit PrintPreviewMessageHandler(content::WebContents* web_contents); friend class content::WebContentsUserData; @@ -69,7 +75,7 @@ class PrintPreviewMessageHandler void RunPrintToPDFCallback(int request_id, PrintPDFResult result); - PrintToPDFCallbackMap print_to_pdf_callback_map_; + PrintToPDFRequestDetailsMap print_to_pdf_request_details_map_; DISALLOW_COPY_AND_ASSIGN(PrintPreviewMessageHandler); };