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 11 matching lines...) Expand all Loading... |
22 #include "base/strings/utf_string_conversions.h" | 22 #include "base/strings/utf_string_conversions.h" |
23 #include "base/threading/thread_task_runner_handle.h" | 23 #include "base/threading/thread_task_runner_handle.h" |
24 #include "build/build_config.h" | 24 #include "build/build_config.h" |
25 #include "components/printing/common/print_messages.h" | 25 #include "components/printing/common/print_messages.h" |
26 #include "content/public/common/web_preferences.h" | 26 #include "content/public/common/web_preferences.h" |
27 #include "content/public/renderer/render_frame.h" | 27 #include "content/public/renderer/render_frame.h" |
28 #include "content/public/renderer/render_thread.h" | 28 #include "content/public/renderer/render_thread.h" |
29 #include "content/public/renderer/render_view.h" | 29 #include "content/public/renderer/render_view.h" |
30 #include "grit/components_resources.h" | 30 #include "grit/components_resources.h" |
31 #include "net/base/escape.h" | 31 #include "net/base/escape.h" |
| 32 #include "printing/features/features.h" |
32 #include "printing/metafile_skia_wrapper.h" | 33 #include "printing/metafile_skia_wrapper.h" |
33 #include "printing/pdf_metafile_skia.h" | 34 #include "printing/pdf_metafile_skia.h" |
34 #include "printing/units.h" | 35 #include "printing/units.h" |
35 #include "third_party/WebKit/public/platform/WebDoubleSize.h" | 36 #include "third_party/WebKit/public/platform/WebDoubleSize.h" |
36 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h" | 37 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h" |
37 #include "third_party/WebKit/public/platform/WebSize.h" | 38 #include "third_party/WebKit/public/platform/WebSize.h" |
38 #include "third_party/WebKit/public/platform/WebURLRequest.h" | 39 #include "third_party/WebKit/public/platform/WebURLRequest.h" |
39 #include "third_party/WebKit/public/web/WebConsoleMessage.h" | 40 #include "third_party/WebKit/public/web/WebConsoleMessage.h" |
40 #include "third_party/WebKit/public/web/WebDocument.h" | 41 #include "third_party/WebKit/public/web/WebDocument.h" |
41 #include "third_party/WebKit/public/web/WebElement.h" | 42 #include "third_party/WebKit/public/web/WebElement.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 PREVIEW_EVENT_CREATE_DOCUMENT, | 78 PREVIEW_EVENT_CREATE_DOCUMENT, |
78 PREVIEW_EVENT_NEW_SETTINGS, // Unused | 79 PREVIEW_EVENT_NEW_SETTINGS, // Unused |
79 PREVIEW_EVENT_MAX, | 80 PREVIEW_EVENT_MAX, |
80 }; | 81 }; |
81 | 82 |
82 const double kMinDpi = 1.0; | 83 const double kMinDpi = 1.0; |
83 | 84 |
84 // Also set in third_party/WebKit/Source/core/page/PrintContext.cpp | 85 // Also set in third_party/WebKit/Source/core/page/PrintContext.cpp |
85 const float kPrintingMinimumShrinkFactor = 1.333f; | 86 const float kPrintingMinimumShrinkFactor = 1.333f; |
86 | 87 |
87 #if defined(ENABLE_PRINT_PREVIEW) | 88 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) |
88 bool g_is_preview_enabled = true; | 89 bool g_is_preview_enabled = true; |
89 | 90 |
90 const char kPageLoadScriptFormat[] = | 91 const char kPageLoadScriptFormat[] = |
91 "document.open(); document.write(%s); document.close();"; | 92 "document.open(); document.write(%s); document.close();"; |
92 | 93 |
93 const char kPageSetupScriptFormat[] = "setup(%s);"; | 94 const char kPageSetupScriptFormat[] = "setup(%s);"; |
94 | 95 |
95 void ExecuteScript(blink::WebFrame* frame, | 96 void ExecuteScript(blink::WebFrame* frame, |
96 const char* script_format, | 97 const char* script_format, |
97 const base::Value& parameters) { | 98 const base::Value& parameters) { |
98 std::string json; | 99 std::string json; |
99 base::JSONWriter::Write(parameters, &json); | 100 base::JSONWriter::Write(parameters, &json); |
100 std::string script = base::StringPrintf(script_format, json.c_str()); | 101 std::string script = base::StringPrintf(script_format, json.c_str()); |
101 frame->executeScript(blink::WebString(base::UTF8ToUTF16(script))); | 102 frame->executeScript(blink::WebString(base::UTF8ToUTF16(script))); |
102 } | 103 } |
103 #else | 104 #else |
104 bool g_is_preview_enabled = false; | 105 bool g_is_preview_enabled = false; |
105 #endif // defined(ENABLE_PRINT_PREVIEW) | 106 #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW) |
106 | 107 |
107 int GetDPI(const PrintMsg_Print_Params* print_params) { | 108 int GetDPI(const PrintMsg_Print_Params* print_params) { |
108 #if defined(OS_MACOSX) | 109 #if defined(OS_MACOSX) |
109 // On the Mac, the printable area is in points, don't do any scaling based | 110 // On the Mac, the printable area is in points, don't do any scaling based |
110 // on dpi. | 111 // on dpi. |
111 return kPointsPerInch; | 112 return kPointsPerInch; |
112 #else | 113 #else |
113 return static_cast<int>(print_params->dpi); | 114 return static_cast<int>(print_params->dpi); |
114 #endif // defined(OS_MACOSX) | 115 #endif // defined(OS_MACOSX) |
115 } | 116 } |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 } | 313 } |
313 | 314 |
314 bool PrintingNodeOrPdfFrame(const blink::WebLocalFrame* frame, | 315 bool PrintingNodeOrPdfFrame(const blink::WebLocalFrame* frame, |
315 const blink::WebNode& node) { | 316 const blink::WebNode& node) { |
316 if (!node.isNull()) | 317 if (!node.isNull()) |
317 return true; | 318 return true; |
318 blink::WebPlugin* plugin = GetPlugin(frame); | 319 blink::WebPlugin* plugin = GetPlugin(frame); |
319 return plugin && plugin->supportsPaginatedPrint(); | 320 return plugin && plugin->supportsPaginatedPrint(); |
320 } | 321 } |
321 | 322 |
322 #if defined(ENABLE_PRINT_PREVIEW) | 323 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) |
323 // Returns true if the current destination printer is PRINT_TO_PDF. | 324 // Returns true if the current destination printer is PRINT_TO_PDF. |
324 bool IsPrintToPdfRequested(const base::DictionaryValue& job_settings) { | 325 bool IsPrintToPdfRequested(const base::DictionaryValue& job_settings) { |
325 bool print_to_pdf = false; | 326 bool print_to_pdf = false; |
326 if (!job_settings.GetBoolean(kSettingPrintToPDF, &print_to_pdf)) | 327 if (!job_settings.GetBoolean(kSettingPrintToPDF, &print_to_pdf)) |
327 NOTREACHED(); | 328 NOTREACHED(); |
328 return print_to_pdf; | 329 return print_to_pdf; |
329 } | 330 } |
330 | 331 |
331 bool PrintingFrameHasPageSizeStyle(blink::WebLocalFrame* frame, | 332 bool PrintingFrameHasPageSizeStyle(blink::WebLocalFrame* frame, |
332 int total_page_count) { | 333 int total_page_count) { |
333 if (!frame) | 334 if (!frame) |
334 return false; | 335 return false; |
335 bool frame_has_custom_page_size_style = false; | 336 bool frame_has_custom_page_size_style = false; |
336 for (int i = 0; i < total_page_count; ++i) { | 337 for (int i = 0; i < total_page_count; ++i) { |
337 if (frame->hasCustomPageSizeStyle(i)) { | 338 if (frame->hasCustomPageSizeStyle(i)) { |
338 frame_has_custom_page_size_style = true; | 339 frame_has_custom_page_size_style = true; |
339 break; | 340 break; |
340 } | 341 } |
341 } | 342 } |
342 return frame_has_custom_page_size_style; | 343 return frame_has_custom_page_size_style; |
343 } | 344 } |
344 #endif // defined(ENABLE_PRINT_PREVIEW) | 345 #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW) |
345 | 346 |
346 // Disable scaling when either: | 347 // Disable scaling when either: |
347 // - The PDF specifies disabling scaling. | 348 // - The PDF specifies disabling scaling. |
348 // - All the pages in the PDF are the same size, | 349 // - All the pages in the PDF are the same size, |
349 // - |ignore_page_size| is false and the uniform size is the same as the paper | 350 // - |ignore_page_size| is false and the uniform size is the same as the paper |
350 // size. | 351 // size. |
351 bool PDFShouldDisableScalingBasedOnPreset( | 352 bool PDFShouldDisableScalingBasedOnPreset( |
352 const blink::WebPrintPresetOptions& options, | 353 const blink::WebPrintPresetOptions& options, |
353 const PrintMsg_Print_Params& params, | 354 const PrintMsg_Print_Params& params, |
354 bool ignore_page_size) { | 355 bool ignore_page_size) { |
(...skipping 24 matching lines...) Expand all Loading... |
379 const PrintMsg_Print_Params& params, | 380 const PrintMsg_Print_Params& params, |
380 bool ignore_page_size) { | 381 bool ignore_page_size) { |
381 const bool kDefaultPDFShouldDisableScalingSetting = true; | 382 const bool kDefaultPDFShouldDisableScalingSetting = true; |
382 blink::WebPrintPresetOptions preset_options; | 383 blink::WebPrintPresetOptions preset_options; |
383 if (!frame->getPrintPresetOptionsForPlugin(node, &preset_options)) | 384 if (!frame->getPrintPresetOptionsForPlugin(node, &preset_options)) |
384 return kDefaultPDFShouldDisableScalingSetting; | 385 return kDefaultPDFShouldDisableScalingSetting; |
385 return PDFShouldDisableScalingBasedOnPreset(preset_options, params, | 386 return PDFShouldDisableScalingBasedOnPreset(preset_options, params, |
386 ignore_page_size); | 387 ignore_page_size); |
387 } | 388 } |
388 | 389 |
389 #if defined(ENABLE_BASIC_PRINTING) | 390 #if BUILDFLAG(ENABLE_BASIC_PRINTING) |
390 MarginType GetMarginsForPdf(blink::WebLocalFrame* frame, | 391 MarginType GetMarginsForPdf(blink::WebLocalFrame* frame, |
391 const blink::WebNode& node, | 392 const blink::WebNode& node, |
392 const PrintMsg_Print_Params& params) { | 393 const PrintMsg_Print_Params& params) { |
393 return PDFShouldDisableScaling(frame, node, params, false) ? | 394 return PDFShouldDisableScaling(frame, node, params, false) ? |
394 NO_MARGINS : PRINTABLE_AREA_MARGINS; | 395 NO_MARGINS : PRINTABLE_AREA_MARGINS; |
395 } | 396 } |
396 #endif | 397 #endif |
397 | 398 |
398 #if defined(ENABLE_PRINT_PREVIEW) | 399 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) |
399 bool FitToPageEnabled(const base::DictionaryValue& job_settings) { | 400 bool FitToPageEnabled(const base::DictionaryValue& job_settings) { |
400 bool fit_to_paper_size = false; | 401 bool fit_to_paper_size = false; |
401 if (!job_settings.GetBoolean(kSettingFitToPageEnabled, &fit_to_paper_size)) { | 402 if (!job_settings.GetBoolean(kSettingFitToPageEnabled, &fit_to_paper_size)) { |
402 NOTREACHED(); | 403 NOTREACHED(); |
403 } | 404 } |
404 return fit_to_paper_size; | 405 return fit_to_paper_size; |
405 } | 406 } |
406 | 407 |
407 // Returns the print scaling option to retain/scale/crop the source page size | 408 // Returns the print scaling option to retain/scale/crop the source page size |
408 // to fit the printable area of the paper. | 409 // to fit the printable area of the paper. |
(...skipping 22 matching lines...) Expand all Loading... |
431 if (!FitToPageEnabled(job_settings)) | 432 if (!FitToPageEnabled(job_settings)) |
432 return blink::WebPrintScalingOptionNone; | 433 return blink::WebPrintScalingOptionNone; |
433 | 434 |
434 bool no_plugin_scaling = PDFShouldDisableScaling(frame, node, params, | 435 bool no_plugin_scaling = PDFShouldDisableScaling(frame, node, params, |
435 true); | 436 true); |
436 if (params.is_first_request && no_plugin_scaling) | 437 if (params.is_first_request && no_plugin_scaling) |
437 return blink::WebPrintScalingOptionNone; | 438 return blink::WebPrintScalingOptionNone; |
438 } | 439 } |
439 return blink::WebPrintScalingOptionFitToPrintableArea; | 440 return blink::WebPrintScalingOptionFitToPrintableArea; |
440 } | 441 } |
441 #endif // defined(ENABLE_PRINT_PREVIEW) | 442 #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW) |
442 | 443 |
443 // Helper function to scale and round an integer value with a double valued | 444 // Helper function to scale and round an integer value with a double valued |
444 // scaling. | 445 // scaling. |
445 int ScaleAndRound(int value, double scaling) { | 446 int ScaleAndRound(int value, double scaling) { |
446 return static_cast<int>(static_cast<double>(value) / scaling); | 447 return static_cast<int>(static_cast<double>(value) / scaling); |
447 } | 448 } |
448 | 449 |
449 // Helper function to scale the width and height of a gfx::Size by scaling. | 450 // Helper function to scale the width and height of a gfx::Size by scaling. |
450 gfx::Size ScaleAndRoundSize(gfx::Size original, double scaling) { | 451 gfx::Size ScaleAndRoundSize(gfx::Size original, double scaling) { |
451 return gfx::Size(ScaleAndRound(original.width(), scaling), | 452 return gfx::Size(ScaleAndRound(original.width(), scaling), |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
550 if (frame == frame_) | 551 if (frame == frame_) |
551 return frame_; | 552 return frame_; |
552 } | 553 } |
553 return NULL; | 554 return NULL; |
554 } | 555 } |
555 | 556 |
556 blink::WebView* FrameReference::view() { | 557 blink::WebView* FrameReference::view() { |
557 return view_; | 558 return view_; |
558 } | 559 } |
559 | 560 |
560 #if defined(ENABLE_PRINT_PREVIEW) | 561 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) |
561 // static - Not anonymous so that platform implementations can use it. | 562 // static - Not anonymous so that platform implementations can use it. |
562 void PrintWebViewHelper::PrintHeaderAndFooter( | 563 void PrintWebViewHelper::PrintHeaderAndFooter( |
563 blink::WebCanvas* canvas, | 564 blink::WebCanvas* canvas, |
564 int page_number, | 565 int page_number, |
565 int total_pages, | 566 int total_pages, |
566 const blink::WebFrame& source_frame, | 567 const blink::WebFrame& source_frame, |
567 float webkit_scale_factor, | 568 float webkit_scale_factor, |
568 const PageSizeMargins& page_layout, | 569 const PageSizeMargins& page_layout, |
569 const PrintMsg_Print_Params& params) { | 570 const PrintMsg_Print_Params& params) { |
570 SkAutoCanvasRestore auto_restore(canvas, true); | 571 SkAutoCanvasRestore auto_restore(canvas, true); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
608 | 609 |
609 blink::WebPrintParams webkit_params(page_size); | 610 blink::WebPrintParams webkit_params(page_size); |
610 webkit_params.printerDPI = GetDPI(¶ms); | 611 webkit_params.printerDPI = GetDPI(¶ms); |
611 | 612 |
612 frame->printBegin(webkit_params); | 613 frame->printBegin(webkit_params); |
613 frame->printPage(0, canvas); | 614 frame->printPage(0, canvas); |
614 frame->printEnd(); | 615 frame->printEnd(); |
615 | 616 |
616 web_view->close(); | 617 web_view->close(); |
617 } | 618 } |
618 #endif // defined(ENABLE_PRINT_PREVIEW) | 619 #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW) |
619 | 620 |
620 // static - Not anonymous so that platform implementations can use it. | 621 // static - Not anonymous so that platform implementations can use it. |
621 float PrintWebViewHelper::RenderPageContent(blink::WebFrame* frame, | 622 float PrintWebViewHelper::RenderPageContent(blink::WebFrame* frame, |
622 int page_number, | 623 int page_number, |
623 const gfx::Rect& canvas_area, | 624 const gfx::Rect& canvas_area, |
624 const gfx::Rect& content_area, | 625 const gfx::Rect& content_area, |
625 double scale_factor, | 626 double scale_factor, |
626 blink::WebCanvas* canvas) { | 627 blink::WebCanvas* canvas) { |
627 SkAutoCanvasRestore auto_restore(canvas, true); | 628 SkAutoCanvasRestore auto_restore(canvas, true); |
628 canvas->translate((content_area.x() - canvas_area.x()) / scale_factor, | 629 canvas->translate((content_area.x() - canvas_area.x()) / scale_factor, |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
714 is_printing_started_(false), | 715 is_printing_started_(false), |
715 weak_ptr_factory_(this) { | 716 weak_ptr_factory_(this) { |
716 PrintMsg_Print_Params print_params = params; | 717 PrintMsg_Print_Params print_params = params; |
717 if (!should_print_selection_only_ || | 718 if (!should_print_selection_only_ || |
718 !PrintingNodeOrPdfFrame(frame, node_to_print_)) { | 719 !PrintingNodeOrPdfFrame(frame, node_to_print_)) { |
719 bool fit_to_page = | 720 bool fit_to_page = |
720 ignore_css_margins && IsWebPrintScalingOptionFitToPage(print_params); | 721 ignore_css_margins && IsWebPrintScalingOptionFitToPage(print_params); |
721 ComputeWebKitPrintParamsInDesiredDpi(params, &web_print_params_); | 722 ComputeWebKitPrintParamsInDesiredDpi(params, &web_print_params_); |
722 frame->printBegin(web_print_params_, node_to_print_); | 723 frame->printBegin(web_print_params_, node_to_print_); |
723 double scale_factor = 1.0f; | 724 double scale_factor = 1.0f; |
724 #if defined(ENABLE_PRINT_PREVIEW) | 725 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) |
725 if (print_params.scale_factor >= PrintWebViewHelper::kEpsilon) | 726 if (print_params.scale_factor >= PrintWebViewHelper::kEpsilon) |
726 scale_factor = print_params.scale_factor; | 727 scale_factor = print_params.scale_factor; |
727 #endif | 728 #endif |
728 print_params = CalculatePrintParamsForCss( | 729 print_params = CalculatePrintParamsForCss( |
729 frame, 0, print_params, ignore_css_margins, fit_to_page, &scale_factor); | 730 frame, 0, print_params, ignore_css_margins, fit_to_page, &scale_factor); |
730 frame->printEnd(); | 731 frame->printEnd(); |
731 } | 732 } |
732 ComputeWebKitPrintParamsInDesiredDpi(print_params, &web_print_params_); | 733 ComputeWebKitPrintParamsInDesiredDpi(print_params, &web_print_params_); |
733 } | 734 } |
734 | 735 |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
946 if (delegate_->CancelPrerender(render_view(), routing_id())) | 947 if (delegate_->CancelPrerender(render_view(), routing_id())) |
947 return; | 948 return; |
948 | 949 |
949 if (!IsScriptInitiatedPrintAllowed(frame, user_initiated)) | 950 if (!IsScriptInitiatedPrintAllowed(frame, user_initiated)) |
950 return; | 951 return; |
951 | 952 |
952 if (delegate_->OverridePrint(frame)) | 953 if (delegate_->OverridePrint(frame)) |
953 return; | 954 return; |
954 | 955 |
955 if (g_is_preview_enabled) { | 956 if (g_is_preview_enabled) { |
956 #if defined(ENABLE_PRINT_PREVIEW) | 957 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) |
957 print_preview_context_.InitWithFrame(frame); | 958 print_preview_context_.InitWithFrame(frame); |
958 RequestPrintPreview(PRINT_PREVIEW_SCRIPTED); | 959 RequestPrintPreview(PRINT_PREVIEW_SCRIPTED); |
959 #endif | 960 #endif |
960 } else { | 961 } else { |
961 #if defined(ENABLE_BASIC_PRINTING) | 962 #if BUILDFLAG(ENABLE_BASIC_PRINTING) |
962 Print(frame, blink::WebNode(), true); | 963 Print(frame, blink::WebNode(), true); |
963 #endif | 964 #endif |
964 } | 965 } |
965 } | 966 } |
966 | 967 |
967 bool PrintWebViewHelper::OnMessageReceived(const IPC::Message& message) { | 968 bool PrintWebViewHelper::OnMessageReceived(const IPC::Message& message) { |
968 // The class is not designed to handle recursive messages. This is not | 969 // The class is not designed to handle recursive messages. This is not |
969 // expected during regular flow. However, during rendering of content for | 970 // expected during regular flow. However, during rendering of content for |
970 // printing, lower level code may run nested message loop. E.g. PDF may has | 971 // printing, lower level code may run nested message loop. E.g. PDF may has |
971 // script to show message box http://crbug.com/502562. In that moment browser | 972 // script to show message box http://crbug.com/502562. In that moment browser |
972 // may receive updated printer capabilities and decide to restart print | 973 // may receive updated printer capabilities and decide to restart print |
973 // preview generation. When this happened message handling function may | 974 // preview generation. When this happened message handling function may |
974 // choose to ignore message or safely crash process. | 975 // choose to ignore message or safely crash process. |
975 ++ipc_nesting_level_; | 976 ++ipc_nesting_level_; |
976 | 977 |
977 bool handled = true; | 978 bool handled = true; |
978 IPC_BEGIN_MESSAGE_MAP(PrintWebViewHelper, message) | 979 IPC_BEGIN_MESSAGE_MAP(PrintWebViewHelper, message) |
979 #if defined(ENABLE_BASIC_PRINTING) | 980 #if BUILDFLAG(ENABLE_BASIC_PRINTING) |
980 IPC_MESSAGE_HANDLER(PrintMsg_PrintPages, OnPrintPages) | 981 IPC_MESSAGE_HANDLER(PrintMsg_PrintPages, OnPrintPages) |
981 IPC_MESSAGE_HANDLER(PrintMsg_PrintForSystemDialog, OnPrintForSystemDialog) | 982 IPC_MESSAGE_HANDLER(PrintMsg_PrintForSystemDialog, OnPrintForSystemDialog) |
982 #endif // defined(ENABLE_BASIC_PRINTING) | 983 #endif // BUILDFLAG(ENABLE_BASIC_PRINTING) |
983 #if defined(ENABLE_BASIC_PRINTING) && defined(ENABLE_PRINT_PREVIEW) | 984 #if BUILDFLAG(ENABLE_BASIC_PRINTING) && BUILDFLAG(ENABLE_PRINT_PREVIEW) |
984 IPC_MESSAGE_HANDLER(PrintMsg_PrintForPrintPreview, OnPrintForPrintPreview) | 985 IPC_MESSAGE_HANDLER(PrintMsg_PrintForPrintPreview, OnPrintForPrintPreview) |
985 #endif | 986 #endif |
986 #if defined(ENABLE_PRINT_PREVIEW) | 987 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) |
987 IPC_MESSAGE_HANDLER(PrintMsg_InitiatePrintPreview, OnInitiatePrintPreview) | 988 IPC_MESSAGE_HANDLER(PrintMsg_InitiatePrintPreview, OnInitiatePrintPreview) |
988 IPC_MESSAGE_HANDLER(PrintMsg_PrintPreview, OnPrintPreview) | 989 IPC_MESSAGE_HANDLER(PrintMsg_PrintPreview, OnPrintPreview) |
989 IPC_MESSAGE_HANDLER(PrintMsg_PrintingDone, OnPrintingDone) | 990 IPC_MESSAGE_HANDLER(PrintMsg_PrintingDone, OnPrintingDone) |
990 #endif // defined(ENABLE_PRINT_PREVIEW) | 991 #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW) |
991 IPC_MESSAGE_HANDLER(PrintMsg_SetScriptedPrintingBlocked, | 992 IPC_MESSAGE_HANDLER(PrintMsg_SetScriptedPrintingBlocked, |
992 SetScriptedPrintBlocked) | 993 SetScriptedPrintBlocked) |
993 IPC_MESSAGE_UNHANDLED(handled = false) | 994 IPC_MESSAGE_UNHANDLED(handled = false) |
994 IPC_END_MESSAGE_MAP() | 995 IPC_END_MESSAGE_MAP() |
995 | 996 |
996 --ipc_nesting_level_; | 997 --ipc_nesting_level_; |
997 return handled; | 998 return handled; |
998 } | 999 } |
999 | 1000 |
1000 void PrintWebViewHelper::OnDestruct() { | 1001 void PrintWebViewHelper::OnDestruct() { |
1001 delete this; | 1002 delete this; |
1002 } | 1003 } |
1003 | 1004 |
1004 bool PrintWebViewHelper::GetPrintFrame(blink::WebLocalFrame** frame) { | 1005 bool PrintWebViewHelper::GetPrintFrame(blink::WebLocalFrame** frame) { |
1005 DCHECK(frame); | 1006 DCHECK(frame); |
1006 blink::WebView* webView = render_view()->GetWebView(); | 1007 blink::WebView* webView = render_view()->GetWebView(); |
1007 DCHECK(webView); | 1008 DCHECK(webView); |
1008 if (!webView) | 1009 if (!webView) |
1009 return false; | 1010 return false; |
1010 | 1011 |
1011 // If the user has selected text in the currently focused frame we print | 1012 // If the user has selected text in the currently focused frame we print |
1012 // only that frame (this makes print selection work for multiple frames). | 1013 // only that frame (this makes print selection work for multiple frames). |
1013 blink::WebLocalFrame* focusedFrame = webView->focusedFrame(); | 1014 blink::WebLocalFrame* focusedFrame = webView->focusedFrame(); |
1014 *frame = focusedFrame->hasSelection() | 1015 *frame = focusedFrame->hasSelection() |
1015 ? focusedFrame | 1016 ? focusedFrame |
1016 : webView->mainFrame()->toWebLocalFrame(); | 1017 : webView->mainFrame()->toWebLocalFrame(); |
1017 return true; | 1018 return true; |
1018 } | 1019 } |
1019 | 1020 |
1020 #if defined(ENABLE_BASIC_PRINTING) | 1021 #if BUILDFLAG(ENABLE_BASIC_PRINTING) |
1021 void PrintWebViewHelper::OnPrintPages() { | 1022 void PrintWebViewHelper::OnPrintPages() { |
1022 if (ipc_nesting_level_> 1) | 1023 if (ipc_nesting_level_> 1) |
1023 return; | 1024 return; |
1024 blink::WebLocalFrame* frame; | 1025 blink::WebLocalFrame* frame; |
1025 if (!GetPrintFrame(&frame)) | 1026 if (!GetPrintFrame(&frame)) |
1026 return; | 1027 return; |
1027 // If we are printing a PDF extension frame, find the plugin node and print | 1028 // If we are printing a PDF extension frame, find the plugin node and print |
1028 // that instead. | 1029 // that instead. |
1029 auto plugin = delegate_->GetPdfElement(frame); | 1030 auto plugin = delegate_->GetPdfElement(frame); |
1030 Print(frame, plugin, false); | 1031 Print(frame, plugin, false); |
1031 } | 1032 } |
1032 | 1033 |
1033 void PrintWebViewHelper::OnPrintForSystemDialog() { | 1034 void PrintWebViewHelper::OnPrintForSystemDialog() { |
1034 if (ipc_nesting_level_> 1) | 1035 if (ipc_nesting_level_> 1) |
1035 return; | 1036 return; |
1036 blink::WebLocalFrame* frame = print_preview_context_.source_frame(); | 1037 blink::WebLocalFrame* frame = print_preview_context_.source_frame(); |
1037 if (!frame) { | 1038 if (!frame) { |
1038 NOTREACHED(); | 1039 NOTREACHED(); |
1039 return; | 1040 return; |
1040 } | 1041 } |
1041 Print(frame, print_preview_context_.source_node(), false); | 1042 Print(frame, print_preview_context_.source_node(), false); |
1042 } | 1043 } |
1043 #endif // defined(ENABLE_BASIC_PRINTING) | 1044 #endif // BUILDFLAG(ENABLE_BASIC_PRINTING) |
1044 | 1045 |
1045 #if defined(ENABLE_BASIC_PRINTING) && defined(ENABLE_PRINT_PREVIEW) | 1046 #if BUILDFLAG(ENABLE_BASIC_PRINTING) && BUILDFLAG(ENABLE_PRINT_PREVIEW) |
1046 void PrintWebViewHelper::OnPrintForPrintPreview( | 1047 void PrintWebViewHelper::OnPrintForPrintPreview( |
1047 const base::DictionaryValue& job_settings) { | 1048 const base::DictionaryValue& job_settings) { |
1048 CHECK_LE(ipc_nesting_level_, 1); | 1049 CHECK_LE(ipc_nesting_level_, 1); |
1049 // If still not finished with earlier print request simply ignore. | 1050 // If still not finished with earlier print request simply ignore. |
1050 if (prep_frame_view_) | 1051 if (prep_frame_view_) |
1051 return; | 1052 return; |
1052 | 1053 |
1053 if (!render_view()->GetWebView()) | 1054 if (!render_view()->GetWebView()) |
1054 return; | 1055 return; |
1055 blink::WebFrame* main_frame = render_view()->GetWebView()->mainFrame(); | 1056 blink::WebFrame* main_frame = render_view()->GetWebView()->mainFrame(); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1100 // See http://crbug.com/123408 | 1101 // See http://crbug.com/123408 |
1101 PrintMsg_Print_Params& print_params = print_pages_params_->params; | 1102 PrintMsg_Print_Params& print_params = print_pages_params_->params; |
1102 print_params.printable_area = gfx::Rect(print_params.page_size); | 1103 print_params.printable_area = gfx::Rect(print_params.page_size); |
1103 | 1104 |
1104 // Render Pages for printing. | 1105 // Render Pages for printing. |
1105 if (!RenderPagesForPrint(plugin_frame, plugin_element)) { | 1106 if (!RenderPagesForPrint(plugin_frame, plugin_element)) { |
1106 LOG(ERROR) << "RenderPagesForPrint failed"; | 1107 LOG(ERROR) << "RenderPagesForPrint failed"; |
1107 DidFinishPrinting(FAIL_PRINT); | 1108 DidFinishPrinting(FAIL_PRINT); |
1108 } | 1109 } |
1109 } | 1110 } |
1110 #endif // defined(ENABLE_BASIC_PRINTING) && defined(ENABLE_PRINT_PREVIEW) | 1111 #endif // BUILDFLAG(ENABLE_BASIC_PRINTING) && BUILDFLAG(ENABLE_PRINT_PREVIEW) |
1111 | 1112 |
1112 void PrintWebViewHelper::GetPageSizeAndContentAreaFromPageLayout( | 1113 void PrintWebViewHelper::GetPageSizeAndContentAreaFromPageLayout( |
1113 const PageSizeMargins& page_layout_in_points, | 1114 const PageSizeMargins& page_layout_in_points, |
1114 gfx::Size* page_size, | 1115 gfx::Size* page_size, |
1115 gfx::Rect* content_area) { | 1116 gfx::Rect* content_area) { |
1116 *page_size = gfx::Size( | 1117 *page_size = gfx::Size( |
1117 page_layout_in_points.content_width + page_layout_in_points.margin_right + | 1118 page_layout_in_points.content_width + page_layout_in_points.margin_right + |
1118 page_layout_in_points.margin_left, | 1119 page_layout_in_points.margin_left, |
1119 page_layout_in_points.content_height + page_layout_in_points.margin_top + | 1120 page_layout_in_points.content_height + page_layout_in_points.margin_top + |
1120 page_layout_in_points.margin_bottom); | 1121 page_layout_in_points.margin_bottom); |
1121 *content_area = gfx::Rect(page_layout_in_points.margin_left, | 1122 *content_area = gfx::Rect(page_layout_in_points.margin_left, |
1122 page_layout_in_points.margin_top, | 1123 page_layout_in_points.margin_top, |
1123 page_layout_in_points.content_width, | 1124 page_layout_in_points.content_width, |
1124 page_layout_in_points.content_height); | 1125 page_layout_in_points.content_height); |
1125 } | 1126 } |
1126 | 1127 |
1127 void PrintWebViewHelper::UpdateFrameMarginsCssInfo( | 1128 void PrintWebViewHelper::UpdateFrameMarginsCssInfo( |
1128 const base::DictionaryValue& settings) { | 1129 const base::DictionaryValue& settings) { |
1129 int margins_type = 0; | 1130 int margins_type = 0; |
1130 if (!settings.GetInteger(kSettingMarginsType, &margins_type)) | 1131 if (!settings.GetInteger(kSettingMarginsType, &margins_type)) |
1131 margins_type = DEFAULT_MARGINS; | 1132 margins_type = DEFAULT_MARGINS; |
1132 ignore_css_margins_ = (margins_type != DEFAULT_MARGINS); | 1133 ignore_css_margins_ = (margins_type != DEFAULT_MARGINS); |
1133 } | 1134 } |
1134 | 1135 |
1135 #if defined(ENABLE_PRINT_PREVIEW) | 1136 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) |
1136 void PrintWebViewHelper::OnPrintPreview(const base::DictionaryValue& settings) { | 1137 void PrintWebViewHelper::OnPrintPreview(const base::DictionaryValue& settings) { |
1137 if (ipc_nesting_level_ > 1) | 1138 if (ipc_nesting_level_ > 1) |
1138 return; | 1139 return; |
1139 | 1140 |
1140 print_preview_context_.OnPrintPreview(); | 1141 print_preview_context_.OnPrintPreview(); |
1141 | 1142 |
1142 UMA_HISTOGRAM_ENUMERATION("PrintPreview.PreviewEvent", | 1143 UMA_HISTOGRAM_ENUMERATION("PrintPreview.PreviewEvent", |
1143 PREVIEW_EVENT_REQUESTED, PREVIEW_EVENT_MAX); | 1144 PREVIEW_EVENT_REQUESTED, PREVIEW_EVENT_MAX); |
1144 | 1145 |
1145 if (!print_preview_context_.source_frame()) { | 1146 if (!print_preview_context_.source_frame()) { |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1310 DCHECK(print_preview_context_.IsModifiable() || | 1311 DCHECK(print_preview_context_.IsModifiable() || |
1311 print_preview_context_.IsFinalPageRendered()); | 1312 print_preview_context_.IsFinalPageRendered()); |
1312 if (!FinalizePrintReadyDocument()) | 1313 if (!FinalizePrintReadyDocument()) |
1313 return false; | 1314 return false; |
1314 } | 1315 } |
1315 } | 1316 } |
1316 print_preview_context_.Finished(); | 1317 print_preview_context_.Finished(); |
1317 return true; | 1318 return true; |
1318 } | 1319 } |
1319 | 1320 |
1320 #if !defined(OS_MACOSX) && defined(ENABLE_PRINT_PREVIEW) | 1321 #if !defined(OS_MACOSX) && BUILDFLAG(ENABLE_PRINT_PREVIEW) |
1321 bool PrintWebViewHelper::RenderPreviewPage( | 1322 bool PrintWebViewHelper::RenderPreviewPage( |
1322 int page_number, | 1323 int page_number, |
1323 const PrintMsg_Print_Params& print_params) { | 1324 const PrintMsg_Print_Params& print_params) { |
1324 PrintMsg_PrintPage_Params page_params; | 1325 PrintMsg_PrintPage_Params page_params; |
1325 page_params.params = print_params; | 1326 page_params.params = print_params; |
1326 page_params.page_number = page_number; | 1327 page_params.page_number = page_number; |
1327 std::unique_ptr<PdfMetafileSkia> draft_metafile; | 1328 std::unique_ptr<PdfMetafileSkia> draft_metafile; |
1328 PdfMetafileSkia* initial_render_metafile = print_preview_context_.metafile(); | 1329 PdfMetafileSkia* initial_render_metafile = print_preview_context_.metafile(); |
1329 if (print_preview_context_.IsModifiable() && is_print_ready_metafile_sent_) { | 1330 if (print_preview_context_.IsModifiable() && is_print_ready_metafile_sent_) { |
1330 draft_metafile.reset(new PdfMetafileSkia(PDF_SKIA_DOCUMENT_TYPE)); | 1331 draft_metafile.reset(new PdfMetafileSkia(PDF_SKIA_DOCUMENT_TYPE)); |
1331 initial_render_metafile = draft_metafile.get(); | 1332 initial_render_metafile = draft_metafile.get(); |
1332 } | 1333 } |
1333 | 1334 |
1334 base::TimeTicks begin_time = base::TimeTicks::Now(); | 1335 base::TimeTicks begin_time = base::TimeTicks::Now(); |
1335 PrintPageInternal(page_params, print_preview_context_.prepared_frame(), | 1336 PrintPageInternal(page_params, print_preview_context_.prepared_frame(), |
1336 initial_render_metafile, nullptr, nullptr); | 1337 initial_render_metafile, nullptr, nullptr); |
1337 print_preview_context_.RenderedPreviewPage( | 1338 print_preview_context_.RenderedPreviewPage( |
1338 base::TimeTicks::Now() - begin_time); | 1339 base::TimeTicks::Now() - begin_time); |
1339 if (draft_metafile.get()) { | 1340 if (draft_metafile.get()) { |
1340 draft_metafile->FinishDocument(); | 1341 draft_metafile->FinishDocument(); |
1341 } else if (print_preview_context_.IsModifiable() && | 1342 } else if (print_preview_context_.IsModifiable() && |
1342 print_preview_context_.generate_draft_pages()) { | 1343 print_preview_context_.generate_draft_pages()) { |
1343 DCHECK(!draft_metafile.get()); | 1344 DCHECK(!draft_metafile.get()); |
1344 draft_metafile = | 1345 draft_metafile = |
1345 print_preview_context_.metafile()->GetMetafileForCurrentPage( | 1346 print_preview_context_.metafile()->GetMetafileForCurrentPage( |
1346 PDF_SKIA_DOCUMENT_TYPE); | 1347 PDF_SKIA_DOCUMENT_TYPE); |
1347 } | 1348 } |
1348 return PreviewPageRendered(page_number, draft_metafile.get()); | 1349 return PreviewPageRendered(page_number, draft_metafile.get()); |
1349 } | 1350 } |
1350 #endif // !defined(OS_MACOSX) && defined(ENABLE_PRINT_PREVIEW) | 1351 #endif // !defined(OS_MACOSX) && BUILDFLAG(ENABLE_PRINT_PREVIEW) |
1351 | 1352 |
1352 bool PrintWebViewHelper::FinalizePrintReadyDocument() { | 1353 bool PrintWebViewHelper::FinalizePrintReadyDocument() { |
1353 DCHECK(!is_print_ready_metafile_sent_); | 1354 DCHECK(!is_print_ready_metafile_sent_); |
1354 print_preview_context_.FinalizePrintReadyDocument(); | 1355 print_preview_context_.FinalizePrintReadyDocument(); |
1355 | 1356 |
1356 PdfMetafileSkia* metafile = print_preview_context_.metafile(); | 1357 PdfMetafileSkia* metafile = print_preview_context_.metafile(); |
1357 PrintHostMsg_DidPreviewDocument_Params preview_params; | 1358 PrintHostMsg_DidPreviewDocument_Params preview_params; |
1358 | 1359 |
1359 // Ask the browser to create the shared memory for us. | 1360 // Ask the browser to create the shared memory for us. |
1360 if (!CopyMetafileDataToSharedMem(*metafile, | 1361 if (!CopyMetafileDataToSharedMem(*metafile, |
1361 &(preview_params.metafile_data_handle))) { | 1362 &(preview_params.metafile_data_handle))) { |
1362 LOG(ERROR) << "CopyMetafileDataToSharedMem failed"; | 1363 LOG(ERROR) << "CopyMetafileDataToSharedMem failed"; |
1363 print_preview_context_.set_error(PREVIEW_ERROR_METAFILE_COPY_FAILED); | 1364 print_preview_context_.set_error(PREVIEW_ERROR_METAFILE_COPY_FAILED); |
1364 return false; | 1365 return false; |
1365 } | 1366 } |
1366 | 1367 |
1367 preview_params.data_size = metafile->GetDataSize(); | 1368 preview_params.data_size = metafile->GetDataSize(); |
1368 preview_params.document_cookie = print_pages_params_->params.document_cookie; | 1369 preview_params.document_cookie = print_pages_params_->params.document_cookie; |
1369 preview_params.expected_pages_count = | 1370 preview_params.expected_pages_count = |
1370 print_preview_context_.total_page_count(); | 1371 print_preview_context_.total_page_count(); |
1371 preview_params.modifiable = print_preview_context_.IsModifiable(); | 1372 preview_params.modifiable = print_preview_context_.IsModifiable(); |
1372 preview_params.preview_request_id = | 1373 preview_params.preview_request_id = |
1373 print_pages_params_->params.preview_request_id; | 1374 print_pages_params_->params.preview_request_id; |
1374 | 1375 |
1375 is_print_ready_metafile_sent_ = true; | 1376 is_print_ready_metafile_sent_ = true; |
1376 | 1377 |
1377 Send(new PrintHostMsg_MetafileReadyForPrinting(routing_id(), preview_params)); | 1378 Send(new PrintHostMsg_MetafileReadyForPrinting(routing_id(), preview_params)); |
1378 return true; | 1379 return true; |
1379 } | 1380 } |
1380 #endif // defined(ENABLE_PRINT_PREVIEW) | 1381 #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW) |
1381 | 1382 |
1382 void PrintWebViewHelper::OnPrintingDone(bool success) { | 1383 void PrintWebViewHelper::OnPrintingDone(bool success) { |
1383 if (ipc_nesting_level_ > 1) | 1384 if (ipc_nesting_level_ > 1) |
1384 return; | 1385 return; |
1385 notify_browser_of_print_failure_ = false; | 1386 notify_browser_of_print_failure_ = false; |
1386 if (!success) | 1387 if (!success) |
1387 LOG(ERROR) << "Failure in OnPrintingDone"; | 1388 LOG(ERROR) << "Failure in OnPrintingDone"; |
1388 DidFinishPrinting(success ? OK : FAIL_PRINT); | 1389 DidFinishPrinting(success ? OK : FAIL_PRINT); |
1389 } | 1390 } |
1390 | 1391 |
1391 void PrintWebViewHelper::SetScriptedPrintBlocked(bool blocked) { | 1392 void PrintWebViewHelper::SetScriptedPrintBlocked(bool blocked) { |
1392 is_scripted_printing_blocked_ = blocked; | 1393 is_scripted_printing_blocked_ = blocked; |
1393 } | 1394 } |
1394 | 1395 |
1395 #if defined(ENABLE_PRINT_PREVIEW) | 1396 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) |
1396 void PrintWebViewHelper::OnInitiatePrintPreview(bool selection_only) { | 1397 void PrintWebViewHelper::OnInitiatePrintPreview(bool selection_only) { |
1397 if (ipc_nesting_level_ > 1) | 1398 if (ipc_nesting_level_ > 1) |
1398 return; | 1399 return; |
1399 blink::WebLocalFrame* frame = NULL; | 1400 blink::WebLocalFrame* frame = NULL; |
1400 GetPrintFrame(&frame); | 1401 GetPrintFrame(&frame); |
1401 DCHECK(frame); | 1402 DCHECK(frame); |
1402 // If we are printing a PDF extension frame, find the plugin node and print | 1403 // If we are printing a PDF extension frame, find the plugin node and print |
1403 // that instead. | 1404 // that instead. |
1404 auto plugin = delegate_->GetPdfElement(frame); | 1405 auto plugin = delegate_->GetPdfElement(frame); |
1405 if (!plugin.isNull()) { | 1406 if (!plugin.isNull()) { |
(...skipping 25 matching lines...) Expand all Loading... |
1431 // from ppapi plugins. It's a rare case, so its OK to just fail here. | 1432 // from ppapi plugins. It's a rare case, so its OK to just fail here. |
1432 // See http://crbug.com/159165. | 1433 // See http://crbug.com/159165. |
1433 return; | 1434 return; |
1434 } | 1435 } |
1435 | 1436 |
1436 print_node_in_progress_ = true; | 1437 print_node_in_progress_ = true; |
1437 | 1438 |
1438 // Make a copy of the node, in case RenderView::OnContextMenuClosed resets | 1439 // Make a copy of the node, in case RenderView::OnContextMenuClosed resets |
1439 // its |context_menu_node_|. | 1440 // its |context_menu_node_|. |
1440 if (g_is_preview_enabled) { | 1441 if (g_is_preview_enabled) { |
1441 #if defined(ENABLE_PRINT_PREVIEW) | 1442 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) |
1442 print_preview_context_.InitWithNode(node); | 1443 print_preview_context_.InitWithNode(node); |
1443 RequestPrintPreview(PRINT_PREVIEW_USER_INITIATED_CONTEXT_NODE); | 1444 RequestPrintPreview(PRINT_PREVIEW_USER_INITIATED_CONTEXT_NODE); |
1444 #endif | 1445 #endif |
1445 } else { | 1446 } else { |
1446 #if defined(ENABLE_BASIC_PRINTING) | 1447 #if BUILDFLAG(ENABLE_BASIC_PRINTING) |
1447 blink::WebNode duplicate_node(node); | 1448 blink::WebNode duplicate_node(node); |
1448 Print(duplicate_node.document().frame(), duplicate_node, false); | 1449 Print(duplicate_node.document().frame(), duplicate_node, false); |
1449 #endif | 1450 #endif |
1450 } | 1451 } |
1451 | 1452 |
1452 print_node_in_progress_ = false; | 1453 print_node_in_progress_ = false; |
1453 } | 1454 } |
1454 | 1455 |
1455 #if defined(ENABLE_BASIC_PRINTING) | 1456 #if BUILDFLAG(ENABLE_BASIC_PRINTING) |
1456 void PrintWebViewHelper::Print(blink::WebLocalFrame* frame, | 1457 void PrintWebViewHelper::Print(blink::WebLocalFrame* frame, |
1457 const blink::WebNode& node, | 1458 const blink::WebNode& node, |
1458 bool is_scripted) { | 1459 bool is_scripted) { |
1459 // If still not finished with earlier print request simply ignore. | 1460 // If still not finished with earlier print request simply ignore. |
1460 if (prep_frame_view_) | 1461 if (prep_frame_view_) |
1461 return; | 1462 return; |
1462 | 1463 |
1463 FrameReference frame_ref(frame); | 1464 FrameReference frame_ref(frame); |
1464 | 1465 |
1465 int expected_page_count = 0; | 1466 int expected_page_count = 0; |
(...skipping 16 matching lines...) Expand all Loading... |
1482 return; | 1483 return; |
1483 } | 1484 } |
1484 | 1485 |
1485 // Render Pages for printing. | 1486 // Render Pages for printing. |
1486 if (!RenderPagesForPrint(frame_ref.GetFrame(), node)) { | 1487 if (!RenderPagesForPrint(frame_ref.GetFrame(), node)) { |
1487 LOG(ERROR) << "RenderPagesForPrint failed"; | 1488 LOG(ERROR) << "RenderPagesForPrint failed"; |
1488 DidFinishPrinting(FAIL_PRINT); | 1489 DidFinishPrinting(FAIL_PRINT); |
1489 } | 1490 } |
1490 scripting_throttler_.Reset(); | 1491 scripting_throttler_.Reset(); |
1491 } | 1492 } |
1492 #endif // defined(ENABLE_BASIC_PRINTING) | 1493 #endif // BUILDFLAG(ENABLE_BASIC_PRINTING) |
1493 | 1494 |
1494 void PrintWebViewHelper::DidFinishPrinting(PrintingResult result) { | 1495 void PrintWebViewHelper::DidFinishPrinting(PrintingResult result) { |
1495 switch (result) { | 1496 switch (result) { |
1496 case OK: | 1497 case OK: |
1497 break; | 1498 break; |
1498 | 1499 |
1499 case FAIL_PRINT_INIT: | 1500 case FAIL_PRINT_INIT: |
1500 DCHECK(!notify_browser_of_print_failure_); | 1501 DCHECK(!notify_browser_of_print_failure_); |
1501 break; | 1502 break; |
1502 | 1503 |
1503 case FAIL_PRINT: | 1504 case FAIL_PRINT: |
1504 if (notify_browser_of_print_failure_ && print_pages_params_) { | 1505 if (notify_browser_of_print_failure_ && print_pages_params_) { |
1505 int cookie = print_pages_params_->params.document_cookie; | 1506 int cookie = print_pages_params_->params.document_cookie; |
1506 Send(new PrintHostMsg_PrintingFailed(routing_id(), cookie)); | 1507 Send(new PrintHostMsg_PrintingFailed(routing_id(), cookie)); |
1507 } | 1508 } |
1508 break; | 1509 break; |
1509 | 1510 |
1510 #if defined(ENABLE_PRINT_PREVIEW) | 1511 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) |
1511 case FAIL_PREVIEW: | 1512 case FAIL_PREVIEW: |
1512 int cookie = | 1513 int cookie = |
1513 print_pages_params_ ? print_pages_params_->params.document_cookie : 0; | 1514 print_pages_params_ ? print_pages_params_->params.document_cookie : 0; |
1514 if (notify_browser_of_print_failure_) { | 1515 if (notify_browser_of_print_failure_) { |
1515 LOG(ERROR) << "CreatePreviewDocument failed"; | 1516 LOG(ERROR) << "CreatePreviewDocument failed"; |
1516 Send(new PrintHostMsg_PrintPreviewFailed(routing_id(), cookie)); | 1517 Send(new PrintHostMsg_PrintPreviewFailed(routing_id(), cookie)); |
1517 } else { | 1518 } else { |
1518 Send(new PrintHostMsg_PrintPreviewCancelled(routing_id(), cookie)); | 1519 Send(new PrintHostMsg_PrintPreviewCancelled(routing_id(), cookie)); |
1519 } | 1520 } |
1520 print_preview_context_.Failed(notify_browser_of_print_failure_); | 1521 print_preview_context_.Failed(notify_browser_of_print_failure_); |
1521 break; | 1522 break; |
1522 #endif // defined(ENABLE_PRINT_PREVIEW) | 1523 #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW) |
1523 } | 1524 } |
1524 prep_frame_view_.reset(); | 1525 prep_frame_view_.reset(); |
1525 print_pages_params_.reset(); | 1526 print_pages_params_.reset(); |
1526 notify_browser_of_print_failure_ = true; | 1527 notify_browser_of_print_failure_ = true; |
1527 } | 1528 } |
1528 | 1529 |
1529 #if defined(ENABLE_BASIC_PRINTING) | 1530 #if BUILDFLAG(ENABLE_BASIC_PRINTING) |
1530 void PrintWebViewHelper::OnFramePreparedForPrintPages() { | 1531 void PrintWebViewHelper::OnFramePreparedForPrintPages() { |
1531 PrintPages(); | 1532 PrintPages(); |
1532 FinishFramePrinting(); | 1533 FinishFramePrinting(); |
1533 } | 1534 } |
1534 | 1535 |
1535 void PrintWebViewHelper::PrintPages() { | 1536 void PrintWebViewHelper::PrintPages() { |
1536 if (!prep_frame_view_) // Printing is already canceled or failed. | 1537 if (!prep_frame_view_) // Printing is already canceled or failed. |
1537 return; | 1538 return; |
1538 | 1539 |
1539 prep_frame_view_->StartPrinting(); | 1540 prep_frame_view_->StartPrinting(); |
(...skipping 23 matching lines...) Expand all Loading... |
1563 | 1564 |
1564 if (!PrintPagesNative(prep_frame_view_->frame(), page_count)) { | 1565 if (!PrintPagesNative(prep_frame_view_->frame(), page_count)) { |
1565 LOG(ERROR) << "Printing failed."; | 1566 LOG(ERROR) << "Printing failed."; |
1566 return DidFinishPrinting(FAIL_PRINT); | 1567 return DidFinishPrinting(FAIL_PRINT); |
1567 } | 1568 } |
1568 } | 1569 } |
1569 | 1570 |
1570 void PrintWebViewHelper::FinishFramePrinting() { | 1571 void PrintWebViewHelper::FinishFramePrinting() { |
1571 prep_frame_view_.reset(); | 1572 prep_frame_view_.reset(); |
1572 } | 1573 } |
1573 #endif // defined(ENABLE_BASIC_PRINTING) | 1574 #endif // BUILDFLAG(ENABLE_BASIC_PRINTING) |
1574 | 1575 |
1575 // static - Not anonymous so that platform implementations can use it. | 1576 // static - Not anonymous so that platform implementations can use it. |
1576 void PrintWebViewHelper::ComputePageLayoutInPointsForCss( | 1577 void PrintWebViewHelper::ComputePageLayoutInPointsForCss( |
1577 blink::WebLocalFrame* frame, | 1578 blink::WebLocalFrame* frame, |
1578 int page_index, | 1579 int page_index, |
1579 const PrintMsg_Print_Params& page_params, | 1580 const PrintMsg_Print_Params& page_params, |
1580 bool ignore_css_margins, | 1581 bool ignore_css_margins, |
1581 double* scale_factor, | 1582 double* scale_factor, |
1582 PageSizeMargins* page_layout_in_points) { | 1583 PageSizeMargins* page_layout_in_points) { |
1583 double input_scale_factor = *scale_factor; | 1584 double input_scale_factor = *scale_factor; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1644 } | 1645 } |
1645 | 1646 |
1646 const PrintMsg_Print_Params& params = print_pages_params_->params; | 1647 const PrintMsg_Print_Params& params = print_pages_params_->params; |
1647 PrepareFrameAndViewForPrint prepare(params, frame, node, ignore_css_margins_); | 1648 PrepareFrameAndViewForPrint prepare(params, frame, node, ignore_css_margins_); |
1648 prepare.StartPrinting(); | 1649 prepare.StartPrinting(); |
1649 | 1650 |
1650 *number_of_pages = prepare.GetExpectedPageCount(); | 1651 *number_of_pages = prepare.GetExpectedPageCount(); |
1651 return true; | 1652 return true; |
1652 } | 1653 } |
1653 | 1654 |
1654 #if defined(ENABLE_PRINT_PREVIEW) | 1655 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) |
1655 bool PrintWebViewHelper::SetOptionsFromPdfDocument( | 1656 bool PrintWebViewHelper::SetOptionsFromPdfDocument( |
1656 PrintHostMsg_SetOptionsFromDocument_Params* options) { | 1657 PrintHostMsg_SetOptionsFromDocument_Params* options) { |
1657 blink::WebLocalFrame* source_frame = print_preview_context_.source_frame(); | 1658 blink::WebLocalFrame* source_frame = print_preview_context_.source_frame(); |
1658 const blink::WebNode& source_node = print_preview_context_.source_node(); | 1659 const blink::WebNode& source_node = print_preview_context_.source_node(); |
1659 | 1660 |
1660 blink::WebPrintPresetOptions preset_options; | 1661 blink::WebPrintPresetOptions preset_options; |
1661 if (!source_frame->getPrintPresetOptionsForPlugin(source_node, | 1662 if (!source_frame->getPrintPresetOptionsForPlugin(source_node, |
1662 &preset_options)) { | 1663 &preset_options)) { |
1663 return false; | 1664 return false; |
1664 } | 1665 } |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1753 if (!print_for_preview_) | 1754 if (!print_for_preview_) |
1754 print_preview_context_.set_error(PREVIEW_ERROR_INVALID_PRINTER_SETTINGS); | 1755 print_preview_context_.set_error(PREVIEW_ERROR_INVALID_PRINTER_SETTINGS); |
1755 else | 1756 else |
1756 Send(new PrintHostMsg_ShowInvalidPrinterSettingsError(routing_id())); | 1757 Send(new PrintHostMsg_ShowInvalidPrinterSettingsError(routing_id())); |
1757 | 1758 |
1758 return false; | 1759 return false; |
1759 } | 1760 } |
1760 | 1761 |
1761 return true; | 1762 return true; |
1762 } | 1763 } |
1763 #endif // defined(ENABLE_PRINT_PREVIEW) | 1764 #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW) |
1764 | 1765 |
1765 #if defined(ENABLE_BASIC_PRINTING) | 1766 #if BUILDFLAG(ENABLE_BASIC_PRINTING) |
1766 bool PrintWebViewHelper::GetPrintSettingsFromUser(blink::WebLocalFrame* frame, | 1767 bool PrintWebViewHelper::GetPrintSettingsFromUser(blink::WebLocalFrame* frame, |
1767 const blink::WebNode& node, | 1768 const blink::WebNode& node, |
1768 int expected_pages_count, | 1769 int expected_pages_count, |
1769 bool is_scripted) { | 1770 bool is_scripted) { |
1770 PrintHostMsg_ScriptedPrint_Params params; | 1771 PrintHostMsg_ScriptedPrint_Params params; |
1771 PrintMsg_PrintPages_Params print_settings; | 1772 PrintMsg_PrintPages_Params print_settings; |
1772 | 1773 |
1773 params.cookie = print_pages_params_->params.document_cookie; | 1774 params.cookie = print_pages_params_->params.document_cookie; |
1774 params.has_selection = frame->hasSelection(); | 1775 params.has_selection = frame->hasSelection(); |
1775 params.expected_pages_count = expected_pages_count; | 1776 params.expected_pages_count = expected_pages_count; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1809 prep_frame_view_.reset(new PrepareFrameAndViewForPrint( | 1810 prep_frame_view_.reset(new PrepareFrameAndViewForPrint( |
1810 print_params, frame, node, ignore_css_margins_)); | 1811 print_params, frame, node, ignore_css_margins_)); |
1811 DCHECK(!print_pages_params_->params.selection_only || | 1812 DCHECK(!print_pages_params_->params.selection_only || |
1812 print_pages_params_->pages.empty()); | 1813 print_pages_params_->pages.empty()); |
1813 prep_frame_view_->CopySelectionIfNeeded( | 1814 prep_frame_view_->CopySelectionIfNeeded( |
1814 render_view()->GetWebkitPreferences(), | 1815 render_view()->GetWebkitPreferences(), |
1815 base::Bind(&PrintWebViewHelper::OnFramePreparedForPrintPages, | 1816 base::Bind(&PrintWebViewHelper::OnFramePreparedForPrintPages, |
1816 base::Unretained(this))); | 1817 base::Unretained(this))); |
1817 return true; | 1818 return true; |
1818 } | 1819 } |
1819 #endif // defined(ENABLE_BASIC_PRINTING) | 1820 #endif // BUILDFLAG(ENABLE_BASIC_PRINTING) |
1820 | 1821 |
1821 #if !defined(OS_MACOSX) | 1822 #if !defined(OS_MACOSX) |
1822 void PrintWebViewHelper::PrintPageInternal( | 1823 void PrintWebViewHelper::PrintPageInternal( |
1823 const PrintMsg_PrintPage_Params& params, | 1824 const PrintMsg_PrintPage_Params& params, |
1824 blink::WebLocalFrame* frame, | 1825 blink::WebLocalFrame* frame, |
1825 PdfMetafileSkia* metafile, | 1826 PdfMetafileSkia* metafile, |
1826 gfx::Size* page_size_in_dpi, | 1827 gfx::Size* page_size_in_dpi, |
1827 gfx::Rect* content_area_in_dpi) { | 1828 gfx::Rect* content_area_in_dpi) { |
1828 PageSizeMargins page_layout_in_points; | 1829 PageSizeMargins page_layout_in_points; |
1829 | 1830 |
1830 double css_scale_factor = 1.0f; | 1831 double css_scale_factor = 1.0f; |
1831 #if defined(ENABLE_PRINT_PREVIEW) | 1832 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) |
1832 if (params.params.scale_factor >= kEpsilon) | 1833 if (params.params.scale_factor >= kEpsilon) |
1833 css_scale_factor = params.params.scale_factor; | 1834 css_scale_factor = params.params.scale_factor; |
1834 #endif | 1835 #endif |
1835 ComputePageLayoutInPointsForCss(frame, params.page_number, params.params, | 1836 ComputePageLayoutInPointsForCss(frame, params.page_number, params.params, |
1836 ignore_css_margins_, &css_scale_factor, | 1837 ignore_css_margins_, &css_scale_factor, |
1837 &page_layout_in_points); | 1838 &page_layout_in_points); |
1838 gfx::Size page_size; | 1839 gfx::Size page_size; |
1839 gfx::Rect content_area; | 1840 gfx::Rect content_area; |
1840 GetPageSizeAndContentAreaFromPageLayout(page_layout_in_points, &page_size, | 1841 GetPageSizeAndContentAreaFromPageLayout(page_layout_in_points, &page_size, |
1841 &content_area); | 1842 &content_area); |
(...skipping 25 matching lines...) Expand all Loading... |
1867 float scale_factor = css_scale_factor; | 1868 float scale_factor = css_scale_factor; |
1868 #endif | 1869 #endif |
1869 | 1870 |
1870 SkCanvas* canvas = metafile->GetVectorCanvasForNewPage( | 1871 SkCanvas* canvas = metafile->GetVectorCanvasForNewPage( |
1871 page_size, canvas_area, scale_factor); | 1872 page_size, canvas_area, scale_factor); |
1872 if (!canvas) | 1873 if (!canvas) |
1873 return; | 1874 return; |
1874 | 1875 |
1875 MetafileSkiaWrapper::SetMetafileOnCanvas(*canvas, metafile); | 1876 MetafileSkiaWrapper::SetMetafileOnCanvas(*canvas, metafile); |
1876 | 1877 |
1877 #if defined(ENABLE_PRINT_PREVIEW) | 1878 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) |
1878 if (params.params.display_header_footer) { | 1879 if (params.params.display_header_footer) { |
1879 // TODO(thestig): Figure out why Linux needs this. It is almost certainly | 1880 // TODO(thestig): Figure out why Linux needs this. It is almost certainly |
1880 // |printingMinimumShrinkFactor| from Blink. | 1881 // |printingMinimumShrinkFactor| from Blink. |
1881 #if defined(OS_WIN) | 1882 #if defined(OS_WIN) |
1882 const float fudge_factor = 1; | 1883 const float fudge_factor = 1; |
1883 #else | 1884 #else |
1884 const float fudge_factor = kPrintingMinimumShrinkFactor; | 1885 const float fudge_factor = kPrintingMinimumShrinkFactor; |
1885 #endif | 1886 #endif |
1886 // |page_number| is 0-based, so 1 is added. | 1887 // |page_number| is 0-based, so 1 is added. |
1887 PrintHeaderAndFooter(canvas, params.page_number + 1, | 1888 PrintHeaderAndFooter(canvas, params.page_number + 1, |
1888 print_preview_context_.total_page_count(), *frame, | 1889 print_preview_context_.total_page_count(), *frame, |
1889 scale_factor / fudge_factor, page_layout_in_points, | 1890 scale_factor / fudge_factor, page_layout_in_points, |
1890 params.params); | 1891 params.params); |
1891 } | 1892 } |
1892 #endif // defined(ENABLE_PRINT_PREVIEW) | 1893 #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW) |
1893 | 1894 |
1894 float webkit_scale_factor = | 1895 float webkit_scale_factor = |
1895 RenderPageContent(frame, params.page_number, canvas_area, content_area, | 1896 RenderPageContent(frame, params.page_number, canvas_area, content_area, |
1896 scale_factor, canvas); | 1897 scale_factor, canvas); |
1897 DCHECK_GT(webkit_scale_factor, 0.0f); | 1898 DCHECK_GT(webkit_scale_factor, 0.0f); |
1898 | 1899 |
1899 // Done printing. Close the canvas to retrieve the compiled metafile. | 1900 // Done printing. Close the canvas to retrieve the compiled metafile. |
1900 if (!metafile->FinishPage()) | 1901 if (!metafile->FinishPage()) |
1901 NOTREACHED() << "metafile failed"; | 1902 NOTREACHED() << "metafile failed"; |
1902 } | 1903 } |
(...skipping 15 matching lines...) Expand all Loading... |
1918 return false; | 1919 return false; |
1919 | 1920 |
1920 if (!metafile.GetData(shared_buf->memory(), buf_size)) | 1921 if (!metafile.GetData(shared_buf->memory(), buf_size)) |
1921 return false; | 1922 return false; |
1922 | 1923 |
1923 *shared_mem_handle = | 1924 *shared_mem_handle = |
1924 base::SharedMemory::DuplicateHandle(shared_buf->handle()); | 1925 base::SharedMemory::DuplicateHandle(shared_buf->handle()); |
1925 return true; | 1926 return true; |
1926 } | 1927 } |
1927 | 1928 |
1928 #if defined(ENABLE_PRINT_PREVIEW) | 1929 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) |
1929 void PrintWebViewHelper::ShowScriptedPrintPreview() { | 1930 void PrintWebViewHelper::ShowScriptedPrintPreview() { |
1930 if (is_scripted_preview_delayed_) { | 1931 if (is_scripted_preview_delayed_) { |
1931 is_scripted_preview_delayed_ = false; | 1932 is_scripted_preview_delayed_ = false; |
1932 Send(new PrintHostMsg_ShowScriptedPrintPreview( | 1933 Send(new PrintHostMsg_ShowScriptedPrintPreview( |
1933 routing_id(), print_preview_context_.IsModifiable())); | 1934 routing_id(), print_preview_context_.IsModifiable())); |
1934 } | 1935 } |
1935 } | 1936 } |
1936 | 1937 |
1937 void PrintWebViewHelper::RequestPrintPreview(PrintPreviewRequestType type) { | 1938 void PrintWebViewHelper::RequestPrintPreview(PrintPreviewRequestType type) { |
1938 const bool is_modifiable = print_preview_context_.IsModifiable(); | 1939 const bool is_modifiable = print_preview_context_.IsModifiable(); |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2046 return false; | 2047 return false; |
2047 } | 2048 } |
2048 preview_page_params.data_size = metafile->GetDataSize(); | 2049 preview_page_params.data_size = metafile->GetDataSize(); |
2049 preview_page_params.page_number = page_number; | 2050 preview_page_params.page_number = page_number; |
2050 preview_page_params.preview_request_id = | 2051 preview_page_params.preview_request_id = |
2051 print_pages_params_->params.preview_request_id; | 2052 print_pages_params_->params.preview_request_id; |
2052 | 2053 |
2053 Send(new PrintHostMsg_DidPreviewPage(routing_id(), preview_page_params)); | 2054 Send(new PrintHostMsg_DidPreviewPage(routing_id(), preview_page_params)); |
2054 return true; | 2055 return true; |
2055 } | 2056 } |
2056 #endif // defined(ENABLE_PRINT_PREVIEW) | 2057 #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW) |
2057 | 2058 |
2058 PrintWebViewHelper::PrintPreviewContext::PrintPreviewContext() | 2059 PrintWebViewHelper::PrintPreviewContext::PrintPreviewContext() |
2059 : total_page_count_(0), | 2060 : total_page_count_(0), |
2060 current_page_index_(0), | 2061 current_page_index_(0), |
2061 generate_draft_pages_(true), | 2062 generate_draft_pages_(true), |
2062 print_ready_metafile_page_count_(0), | 2063 print_ready_metafile_page_count_(0), |
2063 error_(PREVIEW_ERROR_NONE), | 2064 error_(PREVIEW_ERROR_NONE), |
2064 state_(UNINITIALIZED) { | 2065 state_(UNINITIALIZED) { |
2065 } | 2066 } |
2066 | 2067 |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2334 blink::WebConsoleMessage::LevelWarning, message)); | 2335 blink::WebConsoleMessage::LevelWarning, message)); |
2335 return false; | 2336 return false; |
2336 } | 2337 } |
2337 | 2338 |
2338 void PrintWebViewHelper::ScriptingThrottler::Reset() { | 2339 void PrintWebViewHelper::ScriptingThrottler::Reset() { |
2339 // Reset counter on successful print. | 2340 // Reset counter on successful print. |
2340 count_ = 0; | 2341 count_ = 0; |
2341 } | 2342 } |
2342 | 2343 |
2343 } // namespace printing | 2344 } // namespace printing |
OLD | NEW |