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 "chrome/renderer/printing/print_web_view_helper.h" | 5 #include "chrome/renderer/printing/print_web_view_helper.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
55 enum PrintPreviewHelperEvents { | 55 enum PrintPreviewHelperEvents { |
56 PREVIEW_EVENT_REQUESTED, | 56 PREVIEW_EVENT_REQUESTED, |
57 PREVIEW_EVENT_CACHE_HIT, // Unused | 57 PREVIEW_EVENT_CACHE_HIT, // Unused |
58 PREVIEW_EVENT_CREATE_DOCUMENT, | 58 PREVIEW_EVENT_CREATE_DOCUMENT, |
59 PREVIEW_EVENT_NEW_SETTINGS, // Unused | 59 PREVIEW_EVENT_NEW_SETTINGS, // Unused |
60 PREVIEW_EVENT_MAX, | 60 PREVIEW_EVENT_MAX, |
61 }; | 61 }; |
62 | 62 |
63 const double kMinDpi = 1.0; | 63 const double kMinDpi = 1.0; |
64 | 64 |
65 #if defined(ENABLE_PRINT_PREVIEW) | |
65 const char kPageLoadScriptFormat[] = | 66 const char kPageLoadScriptFormat[] = |
66 "document.open(); document.write(%s); document.close();"; | 67 "document.open(); document.write(%s); document.close();"; |
67 | 68 |
68 const char kPageSetupScriptFormat[] = "setup(%s);"; | 69 const char kPageSetupScriptFormat[] = "setup(%s);"; |
69 | 70 |
70 #if defined(ENABLE_PRINT_PREVIEW) | |
71 bool g_is_preview_enabled_ = true; | 71 bool g_is_preview_enabled_ = true; |
72 #else | 72 #else |
73 bool g_is_preview_enabled_ = false; | 73 bool g_is_preview_enabled_ = false; |
74 #endif | 74 #endif |
75 | 75 |
Vitaly Buka (NO REVIEWS)
2014/11/06 19:34:24
why not to combine both blocks?
newt (away)
2014/11/06 19:50:38
Done.
| |
76 #if defined(ENABLE_PRINT_PREVIEW) | |
76 void ExecuteScript(blink::WebFrame* frame, | 77 void ExecuteScript(blink::WebFrame* frame, |
77 const char* script_format, | 78 const char* script_format, |
78 const base::Value& parameters) { | 79 const base::Value& parameters) { |
79 std::string json; | 80 std::string json; |
80 base::JSONWriter::Write(¶meters, &json); | 81 base::JSONWriter::Write(¶meters, &json); |
81 std::string script = base::StringPrintf(script_format, json.c_str()); | 82 std::string script = base::StringPrintf(script_format, json.c_str()); |
82 frame->executeScript(blink::WebString(base::UTF8ToUTF16(script))); | 83 frame->executeScript(blink::WebString(base::UTF8ToUTF16(script))); |
83 } | 84 } |
85 #endif // defined(ENABLE_PRINT_PREVIEW) | |
84 | 86 |
85 int GetDPI(const PrintMsg_Print_Params* print_params) { | 87 int GetDPI(const PrintMsg_Print_Params* print_params) { |
86 #if defined(OS_MACOSX) | 88 #if defined(OS_MACOSX) |
87 // On the Mac, the printable area is in points, don't do any scaling based | 89 // On the Mac, the printable area is in points, don't do any scaling based |
88 // on dpi. | 90 // on dpi. |
89 return kPointsPerInch; | 91 return kPointsPerInch; |
90 #else | 92 #else |
91 return static_cast<int>(print_params->dpi); | 93 return static_cast<int>(print_params->dpi); |
92 #endif // defined(OS_MACOSX) | 94 #endif // defined(OS_MACOSX) |
93 } | 95 } |
(...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
436 if (frame == frame_) | 438 if (frame == frame_) |
437 return frame_; | 439 return frame_; |
438 } | 440 } |
439 return NULL; | 441 return NULL; |
440 } | 442 } |
441 | 443 |
442 blink::WebView* FrameReference::view() { | 444 blink::WebView* FrameReference::view() { |
443 return view_; | 445 return view_; |
444 } | 446 } |
445 | 447 |
448 #if defined(ENABLE_PRINT_PREVIEW) | |
446 // static - Not anonymous so that platform implementations can use it. | 449 // static - Not anonymous so that platform implementations can use it. |
447 void PrintWebViewHelper::PrintHeaderAndFooter( | 450 void PrintWebViewHelper::PrintHeaderAndFooter( |
448 blink::WebCanvas* canvas, | 451 blink::WebCanvas* canvas, |
449 int page_number, | 452 int page_number, |
450 int total_pages, | 453 int total_pages, |
451 const blink::WebFrame& source_frame, | 454 const blink::WebFrame& source_frame, |
452 float webkit_scale_factor, | 455 float webkit_scale_factor, |
453 const PageSizeMargins& page_layout, | 456 const PageSizeMargins& page_layout, |
454 const PrintMsg_Print_Params& params) { | 457 const PrintMsg_Print_Params& params) { |
455 skia::VectorPlatformDeviceSkia* device = | 458 skia::VectorPlatformDeviceSkia* device = |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
498 | 501 |
499 frame->printBegin(webkit_params); | 502 frame->printBegin(webkit_params); |
500 frame->printPage(0, canvas); | 503 frame->printPage(0, canvas); |
501 frame->printEnd(); | 504 frame->printEnd(); |
502 | 505 |
503 web_view->close(); | 506 web_view->close(); |
504 frame->close(); | 507 frame->close(); |
505 | 508 |
506 device->setDrawingArea(SkPDFDevice::kContent_DrawingArea); | 509 device->setDrawingArea(SkPDFDevice::kContent_DrawingArea); |
507 } | 510 } |
511 #endif // defined(ENABLE_PRINT_PREVIEW) | |
508 | 512 |
509 // static - Not anonymous so that platform implementations can use it. | 513 // static - Not anonymous so that platform implementations can use it. |
510 float PrintWebViewHelper::RenderPageContent(blink::WebFrame* frame, | 514 float PrintWebViewHelper::RenderPageContent(blink::WebFrame* frame, |
511 int page_number, | 515 int page_number, |
512 const gfx::Rect& canvas_area, | 516 const gfx::Rect& canvas_area, |
513 const gfx::Rect& content_area, | 517 const gfx::Rect& content_area, |
514 double scale_factor, | 518 double scale_factor, |
515 blink::WebCanvas* canvas) { | 519 blink::WebCanvas* canvas) { |
516 SkAutoCanvasRestore auto_restore(canvas, true); | 520 SkAutoCanvasRestore auto_restore(canvas, true); |
517 if (content_area != canvas_area) { | 521 if (content_area != canvas_area) { |
(...skipping 1503 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2021 blink::WebConsoleMessage::LevelWarning, message)); | 2025 blink::WebConsoleMessage::LevelWarning, message)); |
2022 return false; | 2026 return false; |
2023 } | 2027 } |
2024 | 2028 |
2025 void PrintWebViewHelper::ScriptingThrottler::Reset() { | 2029 void PrintWebViewHelper::ScriptingThrottler::Reset() { |
2026 // Reset counter on successful print. | 2030 // Reset counter on successful print. |
2027 count_ = 0; | 2031 count_ = 0; |
2028 } | 2032 } |
2029 | 2033 |
2030 } // namespace printing | 2034 } // namespace printing |
OLD | NEW |