Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/webui/print_preview/print_preview_handler.h" | 5 #include "chrome/browser/ui/webui/print_preview/print_preview_handler.h" |
| 6 | 6 |
| 7 #include <ctype.h> | 7 #include <ctype.h> |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 | 9 |
| 10 #include <map> | 10 #include <map> |
| (...skipping 1017 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1028 auto* main_render_frame = initiator->GetMainFrame(); | 1028 auto* main_render_frame = initiator->GetMainFrame(); |
| 1029 settings->SetInteger(printing::kPreviewInitiatorHostId, | 1029 settings->SetInteger(printing::kPreviewInitiatorHostId, |
| 1030 main_render_frame->GetProcess()->GetID()); | 1030 main_render_frame->GetProcess()->GetID()); |
| 1031 settings->SetInteger(printing::kPreviewInitiatorRoutingId, | 1031 settings->SetInteger(printing::kPreviewInitiatorRoutingId, |
| 1032 main_render_frame->GetRoutingID()); | 1032 main_render_frame->GetRoutingID()); |
| 1033 } | 1033 } |
| 1034 | 1034 |
| 1035 // Set ID to know whether printing is for preview. | 1035 // Set ID to know whether printing is for preview. |
| 1036 settings->SetInteger(printing::kPreviewUIID, | 1036 settings->SetInteger(printing::kPreviewUIID, |
| 1037 print_preview_ui()->GetIDForPrintPreviewUI()); | 1037 print_preview_ui()->GetIDForPrintPreviewUI()); |
| 1038 RenderFrameHost* rfh = preview_web_contents()->GetMainFrame(); | |
| 1039 rfh->Send(new PrintMsg_PrintForPrintPreview(rfh->GetRoutingID(), *settings)); | |
| 1040 | 1038 |
| 1041 // Set this so when print preview sends "hidePreviewDialog" we clear the | 1039 // Save the settings and notify print preview. Print preview will respond |
| 1042 // initiator and call PrintPreviewDone(). In the cases above, the preview | 1040 // with a "hidePreviewDialog" message, and then the message can be sent to |
| 1043 // dialog stays open until printing is finished and we do this when the | 1041 // the renderer. |
|
Lei Zhang
2017/06/27 21:58:48
for additional context:
the renderer in HandleHid
rbpotter
2017/06/28 00:18:58
Done.
| |
| 1044 // dialog is closed. In this case, we set this so that these tasks are | 1042 settings_ = std::move(settings); |
| 1045 // done in HandleHidePreview(). | |
| 1046 printing_started_ = true; | |
| 1047 | |
| 1048 // This will ultimately try to activate the initiator as well, so do not | |
| 1049 // clear the association with the initiator until "hidePreviewDialog" is | |
| 1050 // received from JS. | |
| 1051 ResolveJavascriptCallback(base::Value(callback_id), base::Value()); | 1043 ResolveJavascriptCallback(base::Value(callback_id), base::Value()); |
| 1052 | 1044 |
| 1053 #else | 1045 #else |
| 1054 NOTREACHED(); | 1046 NOTREACHED(); |
| 1055 #endif // BUILDFLAG(ENABLE_BASIC_PRINTING) | 1047 #endif // BUILDFLAG(ENABLE_BASIC_PRINTING) |
| 1056 } | 1048 } |
| 1057 | 1049 |
| 1058 void PrintPreviewHandler::PrintToPdf() { | 1050 void PrintPreviewHandler::PrintToPdf() { |
| 1059 if (!print_to_pdf_path_.empty()) { | 1051 if (!print_to_pdf_path_.empty()) { |
| 1060 // User has already selected a path, no need to show the dialog again. | 1052 // User has already selected a path, no need to show the dialog again. |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 1080 default_filename = | 1072 default_filename = |
| 1081 default_filename.ReplaceExtension(FILE_PATH_LITERAL("pdf")); | 1073 default_filename.ReplaceExtension(FILE_PATH_LITERAL("pdf")); |
| 1082 | 1074 |
| 1083 base::CommandLine* cmdline = base::CommandLine::ForCurrentProcess(); | 1075 base::CommandLine* cmdline = base::CommandLine::ForCurrentProcess(); |
| 1084 bool prompt_user = !cmdline->HasSwitch(switches::kKioskModePrinting); | 1076 bool prompt_user = !cmdline->HasSwitch(switches::kKioskModePrinting); |
| 1085 SelectFile(default_filename, prompt_user); | 1077 SelectFile(default_filename, prompt_user); |
| 1086 } | 1078 } |
| 1087 } | 1079 } |
| 1088 | 1080 |
| 1089 void PrintPreviewHandler::HandleHidePreview(const base::ListValue* /*args*/) { | 1081 void PrintPreviewHandler::HandleHidePreview(const base::ListValue* /*args*/) { |
| 1090 if (printing_started_) { | 1082 if (settings_) { |
| 1091 // Printing has started, so clear the initiator so that it can open a new | 1083 // Print preview is responding to a resolution of "print" promise. Send the |
| 1092 // print preview dialog, while the current print preview dialog is still | 1084 // print message to the renderer. |
| 1093 // handling its print job. | 1085 RenderFrameHost* rfh = preview_web_contents()->GetMainFrame(); |
| 1086 rfh->Send( | |
| 1087 new PrintMsg_PrintForPrintPreview(rfh->GetRoutingID(), *settings_)); | |
| 1088 settings_ = nullptr; | |
|
Lei Zhang
2017/06/27 21:58:48
Let's call settings_.reset() so it's more obvious
rbpotter
2017/06/28 00:18:58
Done.
| |
| 1089 | |
| 1090 // Clear the initiator so that it can open a new print preview dialog, while | |
| 1091 // the current print preview dialog is still handling its print job. | |
| 1094 WebContents* initiator = GetInitiator(); | 1092 WebContents* initiator = GetInitiator(); |
| 1095 ClearInitiatorDetails(); | 1093 ClearInitiatorDetails(); |
| 1096 | 1094 |
| 1097 // Since the preview dialog will be hidden and not closed, we need to make | 1095 // Since the preview dialog will be hidden and not closed, we need to make |
| 1098 // this call. | 1096 // this call. |
| 1099 if (initiator) { | 1097 if (initiator) { |
| 1100 auto* print_view_manager = PrintViewManager::FromWebContents(initiator); | 1098 auto* print_view_manager = PrintViewManager::FromWebContents(initiator); |
| 1101 print_view_manager->PrintPreviewDone(); | 1099 print_view_manager->PrintPreviewDone(); |
| 1102 } | 1100 } |
| 1103 | |
| 1104 // Since the initiator is cleared, only want to do this once. | |
| 1105 printing_started_ = false; | |
| 1106 } | 1101 } |
| 1107 | 1102 |
| 1108 print_preview_ui()->OnHidePreviewDialog(); | 1103 print_preview_ui()->OnHidePreviewDialog(); |
| 1109 } | 1104 } |
| 1110 | 1105 |
| 1111 void PrintPreviewHandler::HandleCancelPendingPrintRequest( | 1106 void PrintPreviewHandler::HandleCancelPendingPrintRequest( |
| 1112 const base::ListValue* /*args*/) { | 1107 const base::ListValue* /*args*/) { |
| 1113 WebContents* initiator = GetInitiator(); | 1108 WebContents* initiator = GetInitiator(); |
| 1114 if (initiator) | 1109 if (initiator) |
| 1115 ClearInitiatorDetails(); | 1110 ClearInitiatorDetails(); |
| (...skipping 782 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1898 | 1893 |
| 1899 void PrintPreviewHandler::UnregisterForGaiaCookieChanges() { | 1894 void PrintPreviewHandler::UnregisterForGaiaCookieChanges() { |
| 1900 if (gaia_cookie_manager_service_) | 1895 if (gaia_cookie_manager_service_) |
| 1901 gaia_cookie_manager_service_->RemoveObserver(this); | 1896 gaia_cookie_manager_service_->RemoveObserver(this); |
| 1902 } | 1897 } |
| 1903 | 1898 |
| 1904 void PrintPreviewHandler::SetPdfSavedClosureForTesting( | 1899 void PrintPreviewHandler::SetPdfSavedClosureForTesting( |
| 1905 const base::Closure& closure) { | 1900 const base::Closure& closure) { |
| 1906 pdf_file_saved_closure_ = closure; | 1901 pdf_file_saved_closure_ = closure; |
| 1907 } | 1902 } |
| OLD | NEW |