| 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 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| (...skipping 17 matching lines...) Expand all Loading... |
| 28 #include "content/public/common/web_preferences.h" | 28 #include "content/public/common/web_preferences.h" |
| 29 #include "content/public/renderer/render_frame.h" | 29 #include "content/public/renderer/render_frame.h" |
| 30 #include "content/public/renderer/render_thread.h" | 30 #include "content/public/renderer/render_thread.h" |
| 31 #include "content/public/renderer/render_view.h" | 31 #include "content/public/renderer/render_view.h" |
| 32 #include "grit/components_resources.h" | 32 #include "grit/components_resources.h" |
| 33 #include "net/base/escape.h" | 33 #include "net/base/escape.h" |
| 34 #include "printing/features/features.h" | 34 #include "printing/features/features.h" |
| 35 #include "printing/metafile_skia_wrapper.h" | 35 #include "printing/metafile_skia_wrapper.h" |
| 36 #include "printing/pdf_metafile_skia.h" | 36 #include "printing/pdf_metafile_skia.h" |
| 37 #include "printing/units.h" | 37 #include "printing/units.h" |
| 38 #include "skia/ext/cdl_canvas.h" |
| 38 #include "third_party/WebKit/public/platform/WebDoubleSize.h" | 39 #include "third_party/WebKit/public/platform/WebDoubleSize.h" |
| 39 #include "third_party/WebKit/public/platform/WebSize.h" | 40 #include "third_party/WebKit/public/platform/WebSize.h" |
| 40 #include "third_party/WebKit/public/platform/WebURLRequest.h" | 41 #include "third_party/WebKit/public/platform/WebURLRequest.h" |
| 41 #include "third_party/WebKit/public/web/WebConsoleMessage.h" | 42 #include "third_party/WebKit/public/web/WebConsoleMessage.h" |
| 42 #include "third_party/WebKit/public/web/WebDocument.h" | 43 #include "third_party/WebKit/public/web/WebDocument.h" |
| 43 #include "third_party/WebKit/public/web/WebElement.h" | 44 #include "third_party/WebKit/public/web/WebElement.h" |
| 44 #include "third_party/WebKit/public/web/WebFrameClient.h" | 45 #include "third_party/WebKit/public/web/WebFrameClient.h" |
| 45 #include "third_party/WebKit/public/web/WebFrameOwnerProperties.h" | 46 #include "third_party/WebKit/public/web/WebFrameOwnerProperties.h" |
| 46 #include "third_party/WebKit/public/web/WebFrameWidget.h" | 47 #include "third_party/WebKit/public/web/WebFrameWidget.h" |
| 47 #include "third_party/WebKit/public/web/WebLocalFrame.h" | 48 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
| (...skipping 514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 562 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) | 563 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) |
| 563 // static - Not anonymous so that platform implementations can use it. | 564 // static - Not anonymous so that platform implementations can use it. |
| 564 void PrintWebViewHelper::PrintHeaderAndFooter( | 565 void PrintWebViewHelper::PrintHeaderAndFooter( |
| 565 blink::WebCanvas* canvas, | 566 blink::WebCanvas* canvas, |
| 566 int page_number, | 567 int page_number, |
| 567 int total_pages, | 568 int total_pages, |
| 568 const blink::WebFrame& source_frame, | 569 const blink::WebFrame& source_frame, |
| 569 float webkit_scale_factor, | 570 float webkit_scale_factor, |
| 570 const PageSizeMargins& page_layout, | 571 const PageSizeMargins& page_layout, |
| 571 const PrintMsg_Print_Params& params) { | 572 const PrintMsg_Print_Params& params) { |
| 572 SkAutoCanvasRestore auto_restore(canvas, true); | 573 CdlAutoCanvasRestore auto_restore(canvas, true); |
| 573 canvas->scale(1 / webkit_scale_factor, 1 / webkit_scale_factor); | 574 canvas->scale(1 / webkit_scale_factor, 1 / webkit_scale_factor); |
| 574 | 575 |
| 575 blink::WebSize page_size(page_layout.margin_left + page_layout.margin_right + | 576 blink::WebSize page_size(page_layout.margin_left + page_layout.margin_right + |
| 576 page_layout.content_width, | 577 page_layout.content_width, |
| 577 page_layout.margin_top + page_layout.margin_bottom + | 578 page_layout.margin_top + page_layout.margin_bottom + |
| 578 page_layout.content_height); | 579 page_layout.content_height); |
| 579 | 580 |
| 580 blink::WebView* web_view = | 581 blink::WebView* web_view = |
| 581 blink::WebView::create(nullptr, blink::WebPageVisibilityStateVisible); | 582 blink::WebView::create(nullptr, blink::WebPageVisibilityStateVisible); |
| 582 web_view->settings()->setJavaScriptEnabled(true); | 583 web_view->settings()->setJavaScriptEnabled(true); |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 619 } | 620 } |
| 620 #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW) | 621 #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW) |
| 621 | 622 |
| 622 // static - Not anonymous so that platform implementations can use it. | 623 // static - Not anonymous so that platform implementations can use it. |
| 623 float PrintWebViewHelper::RenderPageContent(blink::WebFrame* frame, | 624 float PrintWebViewHelper::RenderPageContent(blink::WebFrame* frame, |
| 624 int page_number, | 625 int page_number, |
| 625 const gfx::Rect& canvas_area, | 626 const gfx::Rect& canvas_area, |
| 626 const gfx::Rect& content_area, | 627 const gfx::Rect& content_area, |
| 627 double scale_factor, | 628 double scale_factor, |
| 628 blink::WebCanvas* canvas) { | 629 blink::WebCanvas* canvas) { |
| 629 SkAutoCanvasRestore auto_restore(canvas, true); | 630 CdlAutoCanvasRestore auto_restore(canvas, true); |
| 630 canvas->translate((content_area.x() - canvas_area.x()) / scale_factor, | 631 canvas->translate((content_area.x() - canvas_area.x()) / scale_factor, |
| 631 (content_area.y() - canvas_area.y()) / scale_factor); | 632 (content_area.y() - canvas_area.y()) / scale_factor); |
| 632 return frame->printPage(page_number, canvas); | 633 return frame->printPage(page_number, canvas); |
| 633 } | 634 } |
| 634 | 635 |
| 635 // Class that calls the Begin and End print functions on the frame and changes | 636 // Class that calls the Begin and End print functions on the frame and changes |
| 636 // the size of the view temporarily to support full page printing.. | 637 // the size of the view temporarily to support full page printing.. |
| 637 class PrepareFrameAndViewForPrint : public blink::WebViewClient, | 638 class PrepareFrameAndViewForPrint : public blink::WebViewClient, |
| 638 public blink::WebFrameClient { | 639 public blink::WebFrameClient { |
| 639 public: | 640 public: |
| (...skipping 1225 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1865 | 1866 |
| 1866 // TODO(thestig): Figure out why Linux is different. | 1867 // TODO(thestig): Figure out why Linux is different. |
| 1867 #if defined(OS_WIN) | 1868 #if defined(OS_WIN) |
| 1868 float webkit_page_shrink_factor = | 1869 float webkit_page_shrink_factor = |
| 1869 frame->getPrintPageShrink(params.page_number); | 1870 frame->getPrintPageShrink(params.page_number); |
| 1870 float scale_factor = css_scale_factor * webkit_page_shrink_factor; | 1871 float scale_factor = css_scale_factor * webkit_page_shrink_factor; |
| 1871 #else | 1872 #else |
| 1872 float scale_factor = css_scale_factor; | 1873 float scale_factor = css_scale_factor; |
| 1873 #endif | 1874 #endif |
| 1874 | 1875 |
| 1875 SkCanvas* canvas = metafile->GetVectorCanvasForNewPage( | 1876 CdlCanvas* canvas = |
| 1876 page_size, canvas_area, scale_factor); | 1877 metafile->GetVectorCanvasForNewPage(page_size, canvas_area, scale_factor); |
| 1877 if (!canvas) | 1878 if (!canvas) |
| 1878 return; | 1879 return; |
| 1879 | 1880 |
| 1880 MetafileSkiaWrapper::SetMetafileOnCanvas(*canvas, metafile); | 1881 MetafileSkiaWrapper::SetMetafileOnCanvas(*canvas, metafile); |
| 1881 | 1882 |
| 1882 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) | 1883 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) |
| 1883 if (params.params.display_header_footer) { | 1884 if (params.params.display_header_footer) { |
| 1884 // TODO(thestig): Figure out why Linux needs this. It is almost certainly | 1885 // TODO(thestig): Figure out why Linux needs this. It is almost certainly |
| 1885 // |printingMinimumShrinkFactor| from Blink. | 1886 // |printingMinimumShrinkFactor| from Blink. |
| 1886 #if defined(OS_WIN) | 1887 #if defined(OS_WIN) |
| (...skipping 455 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2342 blink::WebConsoleMessage::LevelWarning, message)); | 2343 blink::WebConsoleMessage::LevelWarning, message)); |
| 2343 return false; | 2344 return false; |
| 2344 } | 2345 } |
| 2345 | 2346 |
| 2346 void PrintWebViewHelper::ScriptingThrottler::Reset() { | 2347 void PrintWebViewHelper::ScriptingThrottler::Reset() { |
| 2347 // Reset counter on successful print. | 2348 // Reset counter on successful print. |
| 2348 count_ = 0; | 2349 count_ = 0; |
| 2349 } | 2350 } |
| 2350 | 2351 |
| 2351 } // namespace printing | 2352 } // namespace printing |
| OLD | NEW |