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 552 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 563 // <object> with id="pdf-viewer" is created in | 563 // <object> with id="pdf-viewer" is created in |
| 564 // chrome/browser/resources/print_preview/print_preview.js | 564 // chrome/browser/resources/print_preview/print_preview.js |
| 565 WebElement pdf_element = document.getElementById("pdf-viewer"); | 565 WebElement pdf_element = document.getElementById("pdf-viewer"); |
| 566 if (pdf_element.isNull()) { | 566 if (pdf_element.isNull()) { |
| 567 NOTREACHED(); | 567 NOTREACHED(); |
| 568 return; | 568 return; |
| 569 } | 569 } |
| 570 | 570 |
| 571 WebFrame* pdf_frame = pdf_element.document().frame(); | 571 WebFrame* pdf_frame = pdf_element.document().frame(); |
| 572 scoped_ptr<PrepareFrameAndViewForPrint> prepare; | 572 scoped_ptr<PrepareFrameAndViewForPrint> prepare; |
| 573 if (!InitPrintSettingsAndPrepareFrame(pdf_frame, &pdf_element, &prepare)) { | 573 if (!InitPrintSettingsAndPrepareFrame(pdf_frame, &pdf_element, &prepare)) { |
|
kmadhusu
2011/09/13 20:15:34
What will happen if the user has a invalid default
arthurhsu
2011/09/14 01:08:03
Done.
| |
| 574 LOG(ERROR) << "Failed to initialize print page settings"; | 574 LOG(ERROR) << "Failed to initialize print page settings"; |
| 575 return; | 575 return; |
| 576 } | 576 } |
| 577 | 577 |
| 578 if (!UpdatePrintSettings(job_settings, false)) { | 578 if (!UpdatePrintSettings(job_settings, false)) { |
| 579 LOG(ERROR) << "UpdatePrintSettings failed"; | 579 LOG(ERROR) << "UpdatePrintSettings failed"; |
| 580 DidFinishPrinting(FAIL_PRINT); | 580 DidFinishPrinting(FAIL_PRINT); |
| 581 return; | 581 return; |
| 582 } | 582 } |
| 583 | 583 |
| (...skipping 39 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/13 20:09:53
Since you are removing this, nobody will call Init
arthurhsu
2011/09/14 01:08:03
Done.
| |
| 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; |
|
kmadhusu
2011/09/13 20:01:33
Do you want to clear print_pages_params_ ??
arthurhsu
2011/09/14 01:08:03
Done.
| |
| 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 401 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1059 bool is_preview) { | 1051 bool is_preview) { |
| 1060 DCHECK(frame); | 1052 DCHECK(frame); |
| 1061 PrintMsg_PrintPages_Params settings; | 1053 PrintMsg_PrintPages_Params settings; |
| 1062 | 1054 |
| 1063 Send(new PrintHostMsg_GetDefaultPrintSettings(routing_id(), | 1055 Send(new PrintHostMsg_GetDefaultPrintSettings(routing_id(), |
| 1064 &settings.params)); | 1056 &settings.params)); |
| 1065 // Check if the printer returned any settings, if the settings is empty, we | 1057 // Check if the printer returned any settings, if the settings is empty, we |
| 1066 // can safely assume there are no printer drivers configured. So we safely | 1058 // can safely assume there are no printer drivers configured. So we safely |
| 1067 // terminate. | 1059 // terminate. |
| 1068 bool result = true; | 1060 bool result = true; |
| 1069 if (PrintMsg_Print_Params_IsEmpty(settings.params)) { | |
|
kmadhusu
2011/09/13 20:01:33
You still need this code. This function is used by
Lei Zhang
2011/09/13 20:09:53
I don't think you can remove this for the native d
arthurhsu
2011/09/14 01:08:03
Done.
arthurhsu
2011/09/14 01:08:03
Done.
| |
| 1070 if (!is_preview) { | |
| 1071 render_view()->runModalAlertDialog( | |
| 1072 frame, | |
| 1073 l10n_util::GetStringUTF16( | |
| 1074 IDS_PRINT_PREVIEW_INVALID_PRINTER_SETTINGS)); | |
| 1075 } | |
| 1076 result = false; | |
| 1077 } | |
| 1078 | 1061 |
| 1079 if (result && | 1062 if (result && |
| 1080 (settings.params.dpi < kMinDpi || settings.params.document_cookie == 0)) { | 1063 (settings.params.dpi < kMinDpi || settings.params.document_cookie == 0)) { |
| 1081 // Invalid print page settings. | 1064 // Invalid print page settings. |
| 1082 NOTREACHED(); | 1065 NOTREACHED(); |
| 1083 result = false; | 1066 result = false; |
| 1084 } | 1067 } |
| 1085 | 1068 |
| 1086 settings.pages.clear(); | 1069 settings.pages.clear(); |
| 1087 print_pages_params_.reset(new PrintMsg_PrintPages_Params(settings)); | 1070 print_pages_params_.reset(new PrintMsg_PrintPages_Params(settings)); |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 1101 &print_pages_params_->params); | 1084 &print_pages_params_->params); |
| 1102 Send(new PrintHostMsg_DidGetDocumentCookie( | 1085 Send(new PrintHostMsg_DidGetDocumentCookie( |
| 1103 routing_id(), print_pages_params_->params.document_cookie)); | 1086 routing_id(), print_pages_params_->params.document_cookie)); |
| 1104 return true; | 1087 return true; |
| 1105 } | 1088 } |
| 1106 | 1089 |
| 1107 bool PrintWebViewHelper::UpdatePrintSettings( | 1090 bool PrintWebViewHelper::UpdatePrintSettings( |
| 1108 const DictionaryValue& job_settings, bool is_preview) { | 1091 const DictionaryValue& job_settings, bool is_preview) { |
| 1109 PrintMsg_PrintPages_Params settings; | 1092 PrintMsg_PrintPages_Params settings; |
| 1110 | 1093 |
| 1094 print_pages_params_.reset(new PrintMsg_PrintPages_Params(settings)); | |
|
Lei Zhang
2011/09/13 20:09:53
This basically resets |print_pages_params_| to all
arthurhsu
2011/09/14 01:08:03
Done.
| |
| 1095 Send(new PrintHostMsg_DidGetDocumentCookie( | |
|
kmadhusu
2011/09/13 20:01:33
You need to send this message only during the prev
arthurhsu
2011/09/14 01:08:03
Done.
| |
| 1096 routing_id(), print_pages_params_->params.document_cookie)); | |
|
Lei Zhang
2011/09/13 20:09:53
This will always send a value of 0 for the cookie.
arthurhsu
2011/09/14 01:08:03
Done.
| |
| 1111 Send(new PrintHostMsg_UpdatePrintSettings(routing_id(), | 1097 Send(new PrintHostMsg_UpdatePrintSettings(routing_id(), |
| 1112 print_pages_params_->params.document_cookie, job_settings, &settings)); | 1098 print_pages_params_->params.document_cookie, job_settings, &settings)); |
| 1099 | |
| 1100 if (PrintMsg_Print_Params_IsEmpty(settings.params)) { | |
| 1101 if (!is_preview) { | |
| 1102 render_view()->runModalAlertDialog( | |
| 1103 print_preview_context_.frame(), | |
| 1104 l10n_util::GetStringUTF16( | |
| 1105 IDS_PRINT_PREVIEW_INVALID_PRINTER_SETTINGS)); | |
| 1106 } | |
| 1107 return false; | |
| 1108 } | |
| 1109 | |
| 1113 if (settings.params.dpi < kMinDpi || !settings.params.document_cookie) | 1110 if (settings.params.dpi < kMinDpi || !settings.params.document_cookie) |
| 1114 return false; | 1111 return false; |
| 1115 | 1112 |
| 1116 if (is_preview) { | 1113 if (is_preview) { |
| 1117 // Validate expected print preview settings. | 1114 // Validate expected print preview settings. |
| 1118 if (!job_settings.GetString(printing::kPreviewUIAddr, | 1115 if (!job_settings.GetString(printing::kPreviewUIAddr, |
| 1119 &(settings.params.preview_ui_addr)) || | 1116 &(settings.params.preview_ui_addr)) || |
| 1120 !job_settings.GetInteger(printing::kPreviewRequestID, | 1117 !job_settings.GetInteger(printing::kPreviewRequestID, |
| 1121 &(settings.params.preview_request_id)) || | 1118 &(settings.params.preview_request_id)) || |
| 1122 !job_settings.GetBoolean(printing::kIsFirstRequest, | 1119 !job_settings.GetBoolean(printing::kIsFirstRequest, |
| (...skipping 406 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1529 const gfx::Size& | 1526 const gfx::Size& |
| 1530 PrintWebViewHelper::PrintPreviewContext::GetPrintCanvasSize() const { | 1527 PrintWebViewHelper::PrintPreviewContext::GetPrintCanvasSize() const { |
| 1531 return prep_frame_view_->GetPrintCanvasSize(); | 1528 return prep_frame_view_->GetPrintCanvasSize(); |
| 1532 } | 1529 } |
| 1533 | 1530 |
| 1534 void PrintWebViewHelper::PrintPreviewContext::ClearContext() { | 1531 void PrintWebViewHelper::PrintPreviewContext::ClearContext() { |
| 1535 prep_frame_view_.reset(); | 1532 prep_frame_view_.reset(); |
| 1536 metafile_.reset(); | 1533 metafile_.reset(); |
| 1537 pages_to_render_.clear(); | 1534 pages_to_render_.clear(); |
| 1538 } | 1535 } |
| OLD | NEW |