| 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 #if defined(OS_MACOSX) && !defined(USE_SKIA) | 7 #if defined(OS_MACOSX) && !defined(USE_SKIA) |
| 8 #include <CoreGraphics/CGContext.h> | 8 #include <CoreGraphics/CGContext.h> |
| 9 #endif | 9 #endif |
| 10 | 10 |
| (...skipping 611 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 622 WebNode duplicate_node(*node); | 622 WebNode duplicate_node(*node); |
| 623 Print(frame, &duplicate_node); | 623 Print(frame, &duplicate_node); |
| 624 } | 624 } |
| 625 } | 625 } |
| 626 | 626 |
| 627 void PrintWebViewHelper::OnPrintPreview(const DictionaryValue& settings) { | 627 void PrintWebViewHelper::OnPrintPreview(const DictionaryValue& settings) { |
| 628 DCHECK(is_preview_); | 628 DCHECK(is_preview_); |
| 629 print_preview_context_.OnPrintPreview(); | 629 print_preview_context_.OnPrintPreview(); |
| 630 | 630 |
| 631 if (!InitPrintSettings(print_preview_context_.frame(), | 631 if (!InitPrintSettings(print_preview_context_.frame(), |
| 632 print_preview_context_.node())) { | 632 print_preview_context_.node(), |
| 633 NOTREACHED(); | 633 true)) { |
| 634 Send(new PrintHostMsg_PrintPreviewInvalidDefaultPrinter( |
| 635 routing_id(), |
| 636 print_pages_params_->params.document_cookie)); |
| 634 return; | 637 return; |
| 635 } | 638 } |
| 636 | 639 |
| 637 if (!UpdatePrintSettings(settings, true)) { | 640 if (!UpdatePrintSettings(settings, true)) { |
| 638 DidFinishPrinting(FAIL_PREVIEW); | 641 DidFinishPrinting(FAIL_PREVIEW); |
| 639 return; | 642 return; |
| 640 } | 643 } |
| 641 | 644 |
| 642 if (!print_pages_params_->params.is_first_request && | 645 if (!print_pages_params_->params.is_first_request && |
| 643 old_print_pages_params_.get() && | 646 old_print_pages_params_.get() && |
| (...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1002 static_cast<int>(ConvertUnitDouble( | 1005 static_cast<int>(ConvertUnitDouble( |
| 1003 page_height_in_points, printing::kPointsPerInch, dpi))); | 1006 page_height_in_points, printing::kPointsPerInch, dpi))); |
| 1004 | 1007 |
| 1005 params->margin_top = static_cast<int>(ConvertUnitDouble( | 1008 params->margin_top = static_cast<int>(ConvertUnitDouble( |
| 1006 page_layout_in_points.margin_top, printing::kPointsPerInch, dpi)); | 1009 page_layout_in_points.margin_top, printing::kPointsPerInch, dpi)); |
| 1007 params->margin_left = static_cast<int>(ConvertUnitDouble( | 1010 params->margin_left = static_cast<int>(ConvertUnitDouble( |
| 1008 page_layout_in_points.margin_left, printing::kPointsPerInch, dpi)); | 1011 page_layout_in_points.margin_left, printing::kPointsPerInch, dpi)); |
| 1009 } | 1012 } |
| 1010 | 1013 |
| 1011 bool PrintWebViewHelper::InitPrintSettings(WebKit::WebFrame* frame, | 1014 bool PrintWebViewHelper::InitPrintSettings(WebKit::WebFrame* frame, |
| 1012 WebKit::WebNode* node) { | 1015 WebKit::WebNode* node, |
| 1016 bool is_preview) { |
| 1013 DCHECK(frame); | 1017 DCHECK(frame); |
| 1014 PrintMsg_PrintPages_Params settings; | 1018 PrintMsg_PrintPages_Params settings; |
| 1015 | 1019 |
| 1016 Send(new PrintHostMsg_GetDefaultPrintSettings(routing_id(), | 1020 Send(new PrintHostMsg_GetDefaultPrintSettings(routing_id(), |
| 1017 &settings.params)); | 1021 &settings.params)); |
| 1018 // Check if the printer returned any settings, if the settings is empty, we | 1022 // Check if the printer returned any settings, if the settings is empty, we |
| 1019 // can safely assume there are no printer drivers configured. So we safely | 1023 // can safely assume there are no printer drivers configured. So we safely |
| 1020 // terminate. | 1024 // terminate. |
| 1021 if (PrintMsg_Print_Params_IsEmpty(settings.params)) { | 1025 if (PrintMsg_Print_Params_IsEmpty(settings.params)) { |
| 1022 render_view()->runModalAlertDialog( | 1026 if (!is_preview) { |
| 1023 frame, | 1027 render_view()->runModalAlertDialog( |
| 1024 l10n_util::GetStringUTF16(IDS_DEFAULT_PRINTER_NOT_FOUND_WARNING)); | 1028 frame, |
| 1029 l10n_util::GetStringUTF16(IDS_DEFAULT_PRINTER_NOT_FOUND_WARNING)); |
| 1030 } |
| 1025 return false; | 1031 return false; |
| 1026 } | 1032 } |
| 1027 if (settings.params.dpi < kMinDpi || settings.params.document_cookie == 0) { | 1033 if (settings.params.dpi < kMinDpi || settings.params.document_cookie == 0) { |
| 1028 // Invalid print page settings. | 1034 // Invalid print page settings. |
| 1029 NOTREACHED(); | 1035 NOTREACHED(); |
| 1030 return false; | 1036 return false; |
| 1031 } | 1037 } |
| 1032 | 1038 |
| 1033 settings.pages.clear(); | 1039 settings.pages.clear(); |
| 1034 print_pages_params_.reset(new PrintMsg_PrintPages_Params(settings)); | 1040 print_pages_params_.reset(new PrintMsg_PrintPages_Params(settings)); |
| 1035 return true; | 1041 return true; |
| 1036 } | 1042 } |
| 1037 | 1043 |
| 1038 bool PrintWebViewHelper::InitPrintSettingsAndPrepareFrame( | 1044 bool PrintWebViewHelper::InitPrintSettingsAndPrepareFrame( |
| 1039 WebKit::WebFrame* frame, WebKit::WebNode* node, | 1045 WebKit::WebFrame* frame, WebKit::WebNode* node, |
| 1040 scoped_ptr<PrepareFrameAndViewForPrint>* prepare) { | 1046 scoped_ptr<PrepareFrameAndViewForPrint>* prepare) { |
| 1041 if (!InitPrintSettings(frame, node)) | 1047 if (!InitPrintSettings(frame, node, false)) |
| 1042 return false; | 1048 return false; |
| 1043 | 1049 |
| 1044 DCHECK(!prepare->get()); | 1050 DCHECK(!prepare->get()); |
| 1045 prepare->reset(new PrepareFrameAndViewForPrint(print_pages_params_->params, | 1051 prepare->reset(new PrepareFrameAndViewForPrint(print_pages_params_->params, |
| 1046 frame, node)); | 1052 frame, node)); |
| 1047 UpdatePrintableSizeInPrintParameters(frame, node, prepare->get(), | 1053 UpdatePrintableSizeInPrintParameters(frame, node, prepare->get(), |
| 1048 &print_pages_params_->params); | 1054 &print_pages_params_->params); |
| 1049 Send(new PrintHostMsg_DidGetDocumentCookie( | 1055 Send(new PrintHostMsg_DidGetDocumentCookie( |
| 1050 routing_id(), print_pages_params_->params.document_cookie)); | 1056 routing_id(), print_pages_params_->params.document_cookie)); |
| 1051 return true; | 1057 return true; |
| (...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1437 const gfx::Size& | 1443 const gfx::Size& |
| 1438 PrintWebViewHelper::PrintPreviewContext::GetPrintCanvasSize() const { | 1444 PrintWebViewHelper::PrintPreviewContext::GetPrintCanvasSize() const { |
| 1439 return prep_frame_view_->GetPrintCanvasSize(); | 1445 return prep_frame_view_->GetPrintCanvasSize(); |
| 1440 } | 1446 } |
| 1441 | 1447 |
| 1442 void PrintWebViewHelper::PrintPreviewContext::ClearContext() { | 1448 void PrintWebViewHelper::PrintPreviewContext::ClearContext() { |
| 1443 prep_frame_view_.reset(); | 1449 prep_frame_view_.reset(); |
| 1444 metafile_.reset(); | 1450 metafile_.reset(); |
| 1445 pages_to_render_.clear(); | 1451 pages_to_render_.clear(); |
| 1446 } | 1452 } |
| OLD | NEW |