Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/renderer/print_web_view_helper.h" | 5 #include "chrome/renderer/print_web_view_helper.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 623 // copy when the print preview tab closes. | 623 // copy when the print preview tab closes. |
| 624 WebNode duplicate_node(*node); | 624 WebNode duplicate_node(*node); |
| 625 Print(frame, &duplicate_node); | 625 Print(frame, &duplicate_node); |
| 626 } | 626 } |
| 627 } | 627 } |
| 628 | 628 |
| 629 void PrintWebViewHelper::OnPrintPreview(const DictionaryValue& settings) { | 629 void PrintWebViewHelper::OnPrintPreview(const DictionaryValue& settings) { |
| 630 DCHECK(is_preview_); | 630 DCHECK(is_preview_); |
| 631 print_preview_context_.OnPrintPreview(); | 631 print_preview_context_.OnPrintPreview(); |
| 632 | 632 |
| 633 if (!InitPrintSettings(print_preview_context_.frame(), | 633 if (!UpdatePrintSettings(settings, true)) { |
|
Lei Zhang
2011/09/02 18:44:19
I don't understand why you are not calling InitPri
arthurhsu
2011/09/06 22:02:27
It's done so based on Kausalya's suggestion. For
kmadhusu
2011/09/06 22:47:11
thestig@:
Two main reasons for this change:
(1)
| |
| 634 print_preview_context_.node(), | |
| 635 true)) { | |
| 636 Send(new PrintHostMsg_PrintPreviewInvalidPrinterSettings( | 634 Send(new PrintHostMsg_PrintPreviewInvalidPrinterSettings( |
| 637 routing_id(), | 635 routing_id(), |
| 638 print_pages_params_->params.document_cookie)); | 636 print_pages_params_->params.document_cookie)); |
| 639 return; | 637 return; |
| 640 } | 638 } |
| 641 | 639 |
| 642 if (!UpdatePrintSettings(settings, true)) { | |
| 643 LOG(ERROR) << "UpdatePrintSettings failed"; | |
| 644 DidFinishPrinting(FAIL_PREVIEW); | |
| 645 return; | |
| 646 } | |
| 647 | |
| 648 if (!print_pages_params_->params.is_first_request && | 640 if (!print_pages_params_->params.is_first_request && |
| 649 old_print_pages_params_.get() && | 641 old_print_pages_params_.get() && |
| 650 PrintMsg_Print_Params_IsEqual(*old_print_pages_params_, | 642 PrintMsg_Print_Params_IsEqual(*old_print_pages_params_, |
| 651 *print_pages_params_)) { | 643 *print_pages_params_)) { |
| 652 PrintHostMsg_DidPreviewDocument_Params preview_params; | 644 PrintHostMsg_DidPreviewDocument_Params preview_params; |
| 653 preview_params.reuse_existing_data = true; | 645 preview_params.reuse_existing_data = true; |
| 654 preview_params.data_size = 0; | 646 preview_params.data_size = 0; |
| 655 preview_params.document_cookie = | 647 preview_params.document_cookie = |
| 656 print_pages_params_->params.document_cookie; | 648 print_pages_params_->params.document_cookie; |
| 657 preview_params.expected_pages_count = | 649 preview_params.expected_pages_count = |
| (...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1044 bool is_preview) { | 1036 bool is_preview) { |
| 1045 DCHECK(frame); | 1037 DCHECK(frame); |
| 1046 PrintMsg_PrintPages_Params settings; | 1038 PrintMsg_PrintPages_Params settings; |
| 1047 | 1039 |
| 1048 Send(new PrintHostMsg_GetDefaultPrintSettings(routing_id(), | 1040 Send(new PrintHostMsg_GetDefaultPrintSettings(routing_id(), |
| 1049 &settings.params)); | 1041 &settings.params)); |
| 1050 // Check if the printer returned any settings, if the settings is empty, we | 1042 // Check if the printer returned any settings, if the settings is empty, we |
| 1051 // can safely assume there are no printer drivers configured. So we safely | 1043 // can safely assume there are no printer drivers configured. So we safely |
| 1052 // terminate. | 1044 // terminate. |
| 1053 bool result = true; | 1045 bool result = true; |
| 1054 if (PrintMsg_Print_Params_IsEmpty(settings.params)) { | |
| 1055 if (!is_preview) { | |
| 1056 render_view()->runModalAlertDialog( | |
| 1057 frame, | |
| 1058 l10n_util::GetStringUTF16( | |
| 1059 IDS_PRINT_PREVIEW_INVALID_PRINTER_SETTINGS)); | |
| 1060 } | |
| 1061 result = false; | |
| 1062 } | |
| 1063 | 1046 |
| 1064 if (result && | 1047 if (result && |
| 1065 (settings.params.dpi < kMinDpi || settings.params.document_cookie == 0)) { | 1048 (settings.params.dpi < kMinDpi || settings.params.document_cookie == 0)) { |
| 1066 // Invalid print page settings. | 1049 // Invalid print page settings. |
| 1067 NOTREACHED(); | 1050 NOTREACHED(); |
| 1068 result = false; | 1051 result = false; |
| 1069 } | 1052 } |
| 1070 | 1053 |
| 1071 settings.pages.clear(); | 1054 settings.pages.clear(); |
| 1072 print_pages_params_.reset(new PrintMsg_PrintPages_Params(settings)); | 1055 print_pages_params_.reset(new PrintMsg_PrintPages_Params(settings)); |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 1086 &print_pages_params_->params); | 1069 &print_pages_params_->params); |
| 1087 Send(new PrintHostMsg_DidGetDocumentCookie( | 1070 Send(new PrintHostMsg_DidGetDocumentCookie( |
| 1088 routing_id(), print_pages_params_->params.document_cookie)); | 1071 routing_id(), print_pages_params_->params.document_cookie)); |
| 1089 return true; | 1072 return true; |
| 1090 } | 1073 } |
| 1091 | 1074 |
| 1092 bool PrintWebViewHelper::UpdatePrintSettings( | 1075 bool PrintWebViewHelper::UpdatePrintSettings( |
| 1093 const DictionaryValue& job_settings, bool is_preview) { | 1076 const DictionaryValue& job_settings, bool is_preview) { |
| 1094 PrintMsg_PrintPages_Params settings; | 1077 PrintMsg_PrintPages_Params settings; |
| 1095 | 1078 |
| 1079 if (print_pages_params_ == NULL) { | |
|
kmadhusu
2011/09/12 17:20:33
Can you please explain why do you need this check
arthurhsu
2011/09/12 17:25:13
The check is to avoid crashing in line 1085 when p
kmadhusu
2011/09/12 17:36:52
(repeating our in-person conversation): We will ca
arthurhsu
2011/09/12 18:20:11
Done.
| |
| 1080 print_pages_params_.reset(new PrintMsg_PrintPages_Params(settings)); | |
| 1081 Send(new PrintHostMsg_DidGetDocumentCookie( | |
| 1082 routing_id(), print_pages_params_->params.document_cookie)); | |
| 1083 } | |
| 1084 | |
| 1096 Send(new PrintHostMsg_UpdatePrintSettings(routing_id(), | 1085 Send(new PrintHostMsg_UpdatePrintSettings(routing_id(), |
| 1097 print_pages_params_->params.document_cookie, job_settings, &settings)); | 1086 print_pages_params_->params.document_cookie, job_settings, &settings)); |
| 1087 | |
| 1088 if (PrintMsg_Print_Params_IsEmpty(settings.params)) { | |
| 1089 if (!is_preview) { | |
| 1090 render_view()->runModalAlertDialog( | |
| 1091 print_preview_context_.frame(), | |
| 1092 l10n_util::GetStringUTF16( | |
| 1093 IDS_PRINT_PREVIEW_INVALID_PRINTER_SETTINGS)); | |
| 1094 } | |
| 1095 return false; | |
| 1096 } | |
| 1097 | |
| 1098 if (settings.params.dpi < kMinDpi || !settings.params.document_cookie) | 1098 if (settings.params.dpi < kMinDpi || !settings.params.document_cookie) |
| 1099 return false; | 1099 return false; |
| 1100 | 1100 |
| 1101 if (is_preview) { | 1101 if (is_preview) { |
| 1102 // Validate expected print preview settings. | 1102 // Validate expected print preview settings. |
| 1103 if (!job_settings.GetString(printing::kPreviewUIAddr, | 1103 if (!job_settings.GetString(printing::kPreviewUIAddr, |
| 1104 &(settings.params.preview_ui_addr)) || | 1104 &(settings.params.preview_ui_addr)) || |
| 1105 !job_settings.GetInteger(printing::kPreviewRequestID, | 1105 !job_settings.GetInteger(printing::kPreviewRequestID, |
| 1106 &(settings.params.preview_request_id)) || | 1106 &(settings.params.preview_request_id)) || |
| 1107 !job_settings.GetBoolean(printing::kIsFirstRequest, | 1107 !job_settings.GetBoolean(printing::kIsFirstRequest, |
| (...skipping 397 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1505 const gfx::Size& | 1505 const gfx::Size& |
| 1506 PrintWebViewHelper::PrintPreviewContext::GetPrintCanvasSize() const { | 1506 PrintWebViewHelper::PrintPreviewContext::GetPrintCanvasSize() const { |
| 1507 return prep_frame_view_->GetPrintCanvasSize(); | 1507 return prep_frame_view_->GetPrintCanvasSize(); |
| 1508 } | 1508 } |
| 1509 | 1509 |
| 1510 void PrintWebViewHelper::PrintPreviewContext::ClearContext() { | 1510 void PrintWebViewHelper::PrintPreviewContext::ClearContext() { |
| 1511 prep_frame_view_.reset(); | 1511 prep_frame_view_.reset(); |
| 1512 metafile_.reset(); | 1512 metafile_.reset(); |
| 1513 pages_to_render_.clear(); | 1513 pages_to_render_.clear(); |
| 1514 } | 1514 } |
| OLD | NEW |