| 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 10 matching lines...) Expand all Loading... |
| 21 #include "chrome/common/render_messages.h" | 21 #include "chrome/common/render_messages.h" |
| 22 #include "chrome/grit/browser_resources.h" | 22 #include "chrome/grit/browser_resources.h" |
| 23 #include "chrome/renderer/prerender/prerender_helper.h" | 23 #include "chrome/renderer/prerender/prerender_helper.h" |
| 24 #include "content/public/common/web_preferences.h" | 24 #include "content/public/common/web_preferences.h" |
| 25 #include "content/public/renderer/render_frame.h" | 25 #include "content/public/renderer/render_frame.h" |
| 26 #include "content/public/renderer/render_thread.h" | 26 #include "content/public/renderer/render_thread.h" |
| 27 #include "content/public/renderer/render_view.h" | 27 #include "content/public/renderer/render_view.h" |
| 28 #include "net/base/escape.h" | 28 #include "net/base/escape.h" |
| 29 #include "printing/pdf_metafile_skia.h" | 29 #include "printing/pdf_metafile_skia.h" |
| 30 #include "printing/units.h" | 30 #include "printing/units.h" |
| 31 #include "skia/ext/vector_platform_device_skia.h" | |
| 32 #include "third_party/WebKit/public/platform/WebSize.h" | 31 #include "third_party/WebKit/public/platform/WebSize.h" |
| 33 #include "third_party/WebKit/public/platform/WebURLRequest.h" | 32 #include "third_party/WebKit/public/platform/WebURLRequest.h" |
| 34 #include "third_party/WebKit/public/web/WebConsoleMessage.h" | 33 #include "third_party/WebKit/public/web/WebConsoleMessage.h" |
| 35 #include "third_party/WebKit/public/web/WebDocument.h" | 34 #include "third_party/WebKit/public/web/WebDocument.h" |
| 36 #include "third_party/WebKit/public/web/WebElement.h" | 35 #include "third_party/WebKit/public/web/WebElement.h" |
| 37 #include "third_party/WebKit/public/web/WebFrameClient.h" | 36 #include "third_party/WebKit/public/web/WebFrameClient.h" |
| 38 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 37 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| 39 #include "third_party/WebKit/public/web/WebPlugin.h" | 38 #include "third_party/WebKit/public/web/WebPlugin.h" |
| 40 #include "third_party/WebKit/public/web/WebPluginDocument.h" | 39 #include "third_party/WebKit/public/web/WebPluginDocument.h" |
| 41 #include "third_party/WebKit/public/web/WebPrintParams.h" | 40 #include "third_party/WebKit/public/web/WebPrintParams.h" |
| (...skipping 404 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 446 #if defined(ENABLE_PRINT_PREVIEW) | 445 #if defined(ENABLE_PRINT_PREVIEW) |
| 447 // static - Not anonymous so that platform implementations can use it. | 446 // static - Not anonymous so that platform implementations can use it. |
| 448 void PrintWebViewHelper::PrintHeaderAndFooter( | 447 void PrintWebViewHelper::PrintHeaderAndFooter( |
| 449 blink::WebCanvas* canvas, | 448 blink::WebCanvas* canvas, |
| 450 int page_number, | 449 int page_number, |
| 451 int total_pages, | 450 int total_pages, |
| 452 const blink::WebFrame& source_frame, | 451 const blink::WebFrame& source_frame, |
| 453 float webkit_scale_factor, | 452 float webkit_scale_factor, |
| 454 const PageSizeMargins& page_layout, | 453 const PageSizeMargins& page_layout, |
| 455 const PrintMsg_Print_Params& params) { | 454 const PrintMsg_Print_Params& params) { |
| 456 skia::VectorPlatformDeviceSkia* device = | |
| 457 static_cast<skia::VectorPlatformDeviceSkia*>(canvas->getTopDevice()); | |
| 458 device->setDrawingArea(SkPDFDevice::kMargin_DrawingArea); | |
| 459 | |
| 460 SkAutoCanvasRestore auto_restore(canvas, true); | 455 SkAutoCanvasRestore auto_restore(canvas, true); |
| 461 canvas->scale(1 / webkit_scale_factor, 1 / webkit_scale_factor); | 456 canvas->scale(1 / webkit_scale_factor, 1 / webkit_scale_factor); |
| 462 | 457 |
| 463 blink::WebSize page_size(page_layout.margin_left + page_layout.margin_right + | 458 blink::WebSize page_size(page_layout.margin_left + page_layout.margin_right + |
| 464 page_layout.content_width, | 459 page_layout.content_width, |
| 465 page_layout.margin_top + page_layout.margin_bottom + | 460 page_layout.margin_top + page_layout.margin_bottom + |
| 466 page_layout.content_height); | 461 page_layout.content_height); |
| 467 | 462 |
| 468 blink::WebView* web_view = blink::WebView::create(NULL); | 463 blink::WebView* web_view = blink::WebView::create(NULL); |
| 469 web_view->settings()->setJavaScriptEnabled(true); | 464 web_view->settings()->setJavaScriptEnabled(true); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 496 | 491 |
| 497 blink::WebPrintParams webkit_params(page_size); | 492 blink::WebPrintParams webkit_params(page_size); |
| 498 webkit_params.printerDPI = GetDPI(¶ms); | 493 webkit_params.printerDPI = GetDPI(¶ms); |
| 499 | 494 |
| 500 frame->printBegin(webkit_params); | 495 frame->printBegin(webkit_params); |
| 501 frame->printPage(0, canvas); | 496 frame->printPage(0, canvas); |
| 502 frame->printEnd(); | 497 frame->printEnd(); |
| 503 | 498 |
| 504 web_view->close(); | 499 web_view->close(); |
| 505 frame->close(); | 500 frame->close(); |
| 506 | |
| 507 device->setDrawingArea(SkPDFDevice::kContent_DrawingArea); | |
| 508 } | 501 } |
| 509 #endif // defined(ENABLE_PRINT_PREVIEW) | 502 #endif // defined(ENABLE_PRINT_PREVIEW) |
| 510 | 503 |
| 511 // static - Not anonymous so that platform implementations can use it. | 504 // static - Not anonymous so that platform implementations can use it. |
| 512 float PrintWebViewHelper::RenderPageContent(blink::WebFrame* frame, | 505 float PrintWebViewHelper::RenderPageContent(blink::WebFrame* frame, |
| 513 int page_number, | 506 int page_number, |
| 514 const gfx::Rect& canvas_area, | 507 const gfx::Rect& canvas_area, |
| 515 const gfx::Rect& content_area, | 508 const gfx::Rect& content_area, |
| 516 double scale_factor, | 509 double scale_factor, |
| 517 blink::WebCanvas* canvas) { | 510 blink::WebCanvas* canvas) { |
| (...skipping 1505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2023 blink::WebConsoleMessage::LevelWarning, message)); | 2016 blink::WebConsoleMessage::LevelWarning, message)); |
| 2024 return false; | 2017 return false; |
| 2025 } | 2018 } |
| 2026 | 2019 |
| 2027 void PrintWebViewHelper::ScriptingThrottler::Reset() { | 2020 void PrintWebViewHelper::ScriptingThrottler::Reset() { |
| 2028 // Reset counter on successful print. | 2021 // Reset counter on successful print. |
| 2029 count_ = 0; | 2022 count_ = 0; |
| 2030 } | 2023 } |
| 2031 | 2024 |
| 2032 } // namespace printing | 2025 } // namespace printing |
| OLD | NEW |