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