| 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 "components/printing/renderer/print_web_view_helper.h" | 5 #include "components/printing/renderer/print_web_view_helper.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 | 113 |
| 114 bool PrintMsg_Print_Params_IsValid(const PrintMsg_Print_Params& params) { | 114 bool PrintMsg_Print_Params_IsValid(const PrintMsg_Print_Params& params) { |
| 115 return !params.content_size.IsEmpty() && !params.page_size.IsEmpty() && | 115 return !params.content_size.IsEmpty() && !params.page_size.IsEmpty() && |
| 116 !params.printable_area.IsEmpty() && params.document_cookie && | 116 !params.printable_area.IsEmpty() && params.document_cookie && |
| 117 params.desired_dpi && params.dpi && params.margin_top >= 0 && | 117 params.desired_dpi && params.dpi && params.margin_top >= 0 && |
| 118 params.margin_left >= 0 && params.dpi > kMinDpi && | 118 params.margin_left >= 0 && params.dpi > kMinDpi && |
| 119 params.document_cookie != 0; | 119 params.document_cookie != 0; |
| 120 } | 120 } |
| 121 | 121 |
| 122 PrintMsg_Print_Params GetCssPrintParams( | 122 PrintMsg_Print_Params GetCssPrintParams( |
| 123 blink::WebFrame* frame, | 123 blink::WebLocalFrame* frame, |
| 124 int page_index, | 124 int page_index, |
| 125 const PrintMsg_Print_Params& page_params) { | 125 const PrintMsg_Print_Params& page_params) { |
| 126 PrintMsg_Print_Params page_css_params = page_params; | 126 PrintMsg_Print_Params page_css_params = page_params; |
| 127 int dpi = GetDPI(&page_params); | 127 int dpi = GetDPI(&page_params); |
| 128 | 128 |
| 129 blink::WebSize page_size_in_pixels( | 129 blink::WebSize page_size_in_pixels( |
| 130 ConvertUnit(page_params.page_size.width(), dpi, kPixelsPerInch), | 130 ConvertUnit(page_params.page_size.width(), dpi, kPixelsPerInch), |
| 131 ConvertUnit(page_params.page_size.height(), dpi, kPixelsPerInch)); | 131 ConvertUnit(page_params.page_size.height(), dpi, kPixelsPerInch)); |
| 132 int margin_top_in_pixels = | 132 int margin_top_in_pixels = |
| 133 ConvertUnit(page_params.margin_top, dpi, kPixelsPerInch); | 133 ConvertUnit(page_params.margin_top, dpi, kPixelsPerInch); |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 311 | 311 |
| 312 #if defined(ENABLE_PRINT_PREVIEW) | 312 #if defined(ENABLE_PRINT_PREVIEW) |
| 313 // Returns true if the current destination printer is PRINT_TO_PDF. | 313 // Returns true if the current destination printer is PRINT_TO_PDF. |
| 314 bool IsPrintToPdfRequested(const base::DictionaryValue& job_settings) { | 314 bool IsPrintToPdfRequested(const base::DictionaryValue& job_settings) { |
| 315 bool print_to_pdf = false; | 315 bool print_to_pdf = false; |
| 316 if (!job_settings.GetBoolean(kSettingPrintToPDF, &print_to_pdf)) | 316 if (!job_settings.GetBoolean(kSettingPrintToPDF, &print_to_pdf)) |
| 317 NOTREACHED(); | 317 NOTREACHED(); |
| 318 return print_to_pdf; | 318 return print_to_pdf; |
| 319 } | 319 } |
| 320 | 320 |
| 321 bool PrintingFrameHasPageSizeStyle(blink::WebFrame* frame, | 321 bool PrintingFrameHasPageSizeStyle(blink::WebLocalFrame* frame, |
| 322 int total_page_count) { | 322 int total_page_count) { |
| 323 if (!frame) | 323 if (!frame) |
| 324 return false; | 324 return false; |
| 325 bool frame_has_custom_page_size_style = false; | 325 bool frame_has_custom_page_size_style = false; |
| 326 for (int i = 0; i < total_page_count; ++i) { | 326 for (int i = 0; i < total_page_count; ++i) { |
| 327 if (frame->hasCustomPageSizeStyle(i)) { | 327 if (frame->hasCustomPageSizeStyle(i)) { |
| 328 frame_has_custom_page_size_style = true; | 328 frame_has_custom_page_size_style = true; |
| 329 break; | 329 break; |
| 330 } | 330 } |
| 331 } | 331 } |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 416 | 416 |
| 417 bool no_plugin_scaling = PDFShouldDisableScaling(frame, node, params); | 417 bool no_plugin_scaling = PDFShouldDisableScaling(frame, node, params); |
| 418 if (params.is_first_request && no_plugin_scaling) | 418 if (params.is_first_request && no_plugin_scaling) |
| 419 return blink::WebPrintScalingOptionNone; | 419 return blink::WebPrintScalingOptionNone; |
| 420 } | 420 } |
| 421 return blink::WebPrintScalingOptionFitToPrintableArea; | 421 return blink::WebPrintScalingOptionFitToPrintableArea; |
| 422 } | 422 } |
| 423 #endif // defined(ENABLE_PRINT_PREVIEW) | 423 #endif // defined(ENABLE_PRINT_PREVIEW) |
| 424 | 424 |
| 425 PrintMsg_Print_Params CalculatePrintParamsForCss( | 425 PrintMsg_Print_Params CalculatePrintParamsForCss( |
| 426 blink::WebFrame* frame, | 426 blink::WebLocalFrame* frame, |
| 427 int page_index, | 427 int page_index, |
| 428 const PrintMsg_Print_Params& page_params, | 428 const PrintMsg_Print_Params& page_params, |
| 429 bool ignore_css_margins, | 429 bool ignore_css_margins, |
| 430 bool fit_to_page, | 430 bool fit_to_page, |
| 431 double* scale_factor) { | 431 double* scale_factor) { |
| 432 PrintMsg_Print_Params css_params = | 432 PrintMsg_Print_Params css_params = |
| 433 GetCssPrintParams(frame, page_index, page_params); | 433 GetCssPrintParams(frame, page_index, page_params); |
| 434 | 434 |
| 435 PrintMsg_Print_Params params = page_params; | 435 PrintMsg_Print_Params params = page_params; |
| 436 EnsureOrientationMatches(css_params, ¶ms); | 436 EnsureOrientationMatches(css_params, ¶ms); |
| (...skipping 1054 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1491 } | 1491 } |
| 1492 } | 1492 } |
| 1493 | 1493 |
| 1494 void PrintWebViewHelper::FinishFramePrinting() { | 1494 void PrintWebViewHelper::FinishFramePrinting() { |
| 1495 prep_frame_view_.reset(); | 1495 prep_frame_view_.reset(); |
| 1496 } | 1496 } |
| 1497 #endif // defined(ENABLE_BASIC_PRINTING) | 1497 #endif // defined(ENABLE_BASIC_PRINTING) |
| 1498 | 1498 |
| 1499 // static - Not anonymous so that platform implementations can use it. | 1499 // static - Not anonymous so that platform implementations can use it. |
| 1500 void PrintWebViewHelper::ComputePageLayoutInPointsForCss( | 1500 void PrintWebViewHelper::ComputePageLayoutInPointsForCss( |
| 1501 blink::WebFrame* frame, | 1501 blink::WebLocalFrame* frame, |
| 1502 int page_index, | 1502 int page_index, |
| 1503 const PrintMsg_Print_Params& page_params, | 1503 const PrintMsg_Print_Params& page_params, |
| 1504 bool ignore_css_margins, | 1504 bool ignore_css_margins, |
| 1505 double* scale_factor, | 1505 double* scale_factor, |
| 1506 PageSizeMargins* page_layout_in_points) { | 1506 PageSizeMargins* page_layout_in_points) { |
| 1507 PrintMsg_Print_Params params = CalculatePrintParamsForCss( | 1507 PrintMsg_Print_Params params = CalculatePrintParamsForCss( |
| 1508 frame, page_index, page_params, ignore_css_margins, | 1508 frame, page_index, page_params, ignore_css_margins, |
| 1509 page_params.print_scaling_option == | 1509 page_params.print_scaling_option == |
| 1510 blink::WebPrintScalingOptionFitToPrintableArea, | 1510 blink::WebPrintScalingOptionFitToPrintableArea, |
| 1511 scale_factor); | 1511 scale_factor); |
| (...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1737 render_view()->GetWebkitPreferences(), | 1737 render_view()->GetWebkitPreferences(), |
| 1738 base::Bind(&PrintWebViewHelper::OnFramePreparedForPrintPages, | 1738 base::Bind(&PrintWebViewHelper::OnFramePreparedForPrintPages, |
| 1739 base::Unretained(this))); | 1739 base::Unretained(this))); |
| 1740 return true; | 1740 return true; |
| 1741 } | 1741 } |
| 1742 #endif // defined(ENABLE_BASIC_PRINTING) | 1742 #endif // defined(ENABLE_BASIC_PRINTING) |
| 1743 | 1743 |
| 1744 #if !defined(OS_MACOSX) | 1744 #if !defined(OS_MACOSX) |
| 1745 void PrintWebViewHelper::PrintPageInternal( | 1745 void PrintWebViewHelper::PrintPageInternal( |
| 1746 const PrintMsg_PrintPage_Params& params, | 1746 const PrintMsg_PrintPage_Params& params, |
| 1747 blink::WebFrame* frame, | 1747 blink::WebLocalFrame* frame, |
| 1748 PdfMetafileSkia* metafile, | 1748 PdfMetafileSkia* metafile, |
| 1749 gfx::Size* page_size_in_dpi, | 1749 gfx::Size* page_size_in_dpi, |
| 1750 gfx::Rect* content_area_in_dpi) { | 1750 gfx::Rect* content_area_in_dpi) { |
| 1751 PageSizeMargins page_layout_in_points; | 1751 PageSizeMargins page_layout_in_points; |
| 1752 double css_scale_factor = 1.0f; | 1752 double css_scale_factor = 1.0f; |
| 1753 ComputePageLayoutInPointsForCss(frame, params.page_number, params.params, | 1753 ComputePageLayoutInPointsForCss(frame, params.page_number, params.params, |
| 1754 ignore_css_margins_, &css_scale_factor, | 1754 ignore_css_margins_, &css_scale_factor, |
| 1755 &page_layout_in_points); | 1755 &page_layout_in_points); |
| 1756 gfx::Size page_size; | 1756 gfx::Size page_size; |
| 1757 gfx::Rect content_area; | 1757 gfx::Rect content_area; |
| (...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2252 blink::WebConsoleMessage::LevelWarning, message)); | 2252 blink::WebConsoleMessage::LevelWarning, message)); |
| 2253 return false; | 2253 return false; |
| 2254 } | 2254 } |
| 2255 | 2255 |
| 2256 void PrintWebViewHelper::ScriptingThrottler::Reset() { | 2256 void PrintWebViewHelper::ScriptingThrottler::Reset() { |
| 2257 // Reset counter on successful print. | 2257 // Reset counter on successful print. |
| 2258 count_ = 0; | 2258 count_ = 0; |
| 2259 } | 2259 } |
| 2260 | 2260 |
| 2261 } // namespace printing | 2261 } // namespace printing |
| OLD | NEW |