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 403 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
445 | 444 |
446 // static - Not anonymous so that platform implementations can use it. | 445 // static - Not anonymous so that platform implementations can use it. |
447 void PrintWebViewHelper::PrintHeaderAndFooter( | 446 void PrintWebViewHelper::PrintHeaderAndFooter( |
448 blink::WebCanvas* canvas, | 447 blink::WebCanvas* canvas, |
449 int page_number, | 448 int page_number, |
450 int total_pages, | 449 int total_pages, |
451 const blink::WebFrame& source_frame, | 450 const blink::WebFrame& source_frame, |
452 float webkit_scale_factor, | 451 float webkit_scale_factor, |
453 const PageSizeMargins& page_layout, | 452 const PageSizeMargins& page_layout, |
454 const PrintMsg_Print_Params& params) { | 453 const PrintMsg_Print_Params& params) { |
455 skia::VectorPlatformDeviceSkia* device = | |
456 static_cast<skia::VectorPlatformDeviceSkia*>(canvas->getTopDevice()); | |
457 device->setDrawingArea(SkPDFDevice::kMargin_DrawingArea); | |
458 | |
459 SkAutoCanvasRestore auto_restore(canvas, true); | 454 SkAutoCanvasRestore auto_restore(canvas, true); |
460 canvas->scale(1 / webkit_scale_factor, 1 / webkit_scale_factor); | 455 canvas->scale(1 / webkit_scale_factor, 1 / webkit_scale_factor); |
461 | 456 |
462 blink::WebSize page_size(page_layout.margin_left + page_layout.margin_right + | 457 blink::WebSize page_size(page_layout.margin_left + page_layout.margin_right + |
463 page_layout.content_width, | 458 page_layout.content_width, |
464 page_layout.margin_top + page_layout.margin_bottom + | 459 page_layout.margin_top + page_layout.margin_bottom + |
465 page_layout.content_height); | 460 page_layout.content_height); |
466 | 461 |
467 blink::WebView* web_view = blink::WebView::create(NULL); | 462 blink::WebView* web_view = blink::WebView::create(NULL); |
468 web_view->settings()->setJavaScriptEnabled(true); | 463 web_view->settings()->setJavaScriptEnabled(true); |
(...skipping 26 matching lines...) Expand all Loading... |
495 | 490 |
496 blink::WebPrintParams webkit_params(page_size); | 491 blink::WebPrintParams webkit_params(page_size); |
497 webkit_params.printerDPI = GetDPI(¶ms); | 492 webkit_params.printerDPI = GetDPI(¶ms); |
498 | 493 |
499 frame->printBegin(webkit_params); | 494 frame->printBegin(webkit_params); |
500 frame->printPage(0, canvas); | 495 frame->printPage(0, canvas); |
501 frame->printEnd(); | 496 frame->printEnd(); |
502 | 497 |
503 web_view->close(); | 498 web_view->close(); |
504 frame->close(); | 499 frame->close(); |
505 | |
506 device->setDrawingArea(SkPDFDevice::kContent_DrawingArea); | |
507 } | 500 } |
508 | 501 |
509 // static - Not anonymous so that platform implementations can use it. | 502 // static - Not anonymous so that platform implementations can use it. |
510 float PrintWebViewHelper::RenderPageContent(blink::WebFrame* frame, | 503 float PrintWebViewHelper::RenderPageContent(blink::WebFrame* frame, |
511 int page_number, | 504 int page_number, |
512 const gfx::Rect& canvas_area, | 505 const gfx::Rect& canvas_area, |
513 const gfx::Rect& content_area, | 506 const gfx::Rect& content_area, |
514 double scale_factor, | 507 double scale_factor, |
515 blink::WebCanvas* canvas) { | 508 blink::WebCanvas* canvas) { |
516 SkAutoCanvasRestore auto_restore(canvas, true); | 509 SkAutoCanvasRestore auto_restore(canvas, true); |
(...skipping 1504 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2021 blink::WebConsoleMessage::LevelWarning, message)); | 2014 blink::WebConsoleMessage::LevelWarning, message)); |
2022 return false; | 2015 return false; |
2023 } | 2016 } |
2024 | 2017 |
2025 void PrintWebViewHelper::ScriptingThrottler::Reset() { | 2018 void PrintWebViewHelper::ScriptingThrottler::Reset() { |
2026 // Reset counter on successful print. | 2019 // Reset counter on successful print. |
2027 count_ = 0; | 2020 count_ = 0; |
2028 } | 2021 } |
2029 | 2022 |
2030 } // namespace printing | 2023 } // namespace printing |
OLD | NEW |