Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(192)

Side by Side Diff: components/printing/renderer/print_web_view_helper.cc

Issue 2829973002: add customized printing setting for headless (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 1330 matching lines...) Expand 10 before | Expand all | Expand 10 after
1341 const PrintMsg_Print_Params& print_params) { 1341 const PrintMsg_Print_Params& print_params) {
1342 std::unique_ptr<PdfMetafileSkia> draft_metafile; 1342 std::unique_ptr<PdfMetafileSkia> draft_metafile;
1343 PdfMetafileSkia* initial_render_metafile = print_preview_context_.metafile(); 1343 PdfMetafileSkia* initial_render_metafile = print_preview_context_.metafile();
1344 if (print_preview_context_.IsModifiable() && is_print_ready_metafile_sent_) { 1344 if (print_preview_context_.IsModifiable() && is_print_ready_metafile_sent_) {
1345 draft_metafile = base::MakeUnique<PdfMetafileSkia>(PDF_SKIA_DOCUMENT_TYPE); 1345 draft_metafile = base::MakeUnique<PdfMetafileSkia>(PDF_SKIA_DOCUMENT_TYPE);
1346 initial_render_metafile = draft_metafile.get(); 1346 initial_render_metafile = draft_metafile.get();
1347 } 1347 }
1348 1348
1349 base::TimeTicks begin_time = base::TimeTicks::Now(); 1349 base::TimeTicks begin_time = base::TimeTicks::Now();
1350 PrintPageInternal(print_params, page_number, 1350 PrintPageInternal(print_params, page_number,
1351 print_preview_context_.total_page_count(),
1351 print_preview_context_.prepared_frame(), 1352 print_preview_context_.prepared_frame(),
1352 initial_render_metafile, nullptr, nullptr, nullptr); 1353 initial_render_metafile, nullptr, nullptr, nullptr);
1353 print_preview_context_.RenderedPreviewPage( 1354 print_preview_context_.RenderedPreviewPage(
1354 base::TimeTicks::Now() - begin_time); 1355 base::TimeTicks::Now() - begin_time);
1355 if (draft_metafile.get()) { 1356 if (draft_metafile.get()) {
1356 draft_metafile->FinishDocument(); 1357 draft_metafile->FinishDocument();
1357 } else if (print_preview_context_.IsModifiable() && 1358 } else if (print_preview_context_.IsModifiable() &&
1358 print_preview_context_.generate_draft_pages()) { 1359 print_preview_context_.generate_draft_pages()) {
1359 DCHECK(!draft_metafile.get()); 1360 DCHECK(!draft_metafile.get());
1360 draft_metafile = 1361 draft_metafile =
(...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after
1841 render_frame()->GetWebkitPreferences(), 1842 render_frame()->GetWebkitPreferences(),
1842 base::Bind(&PrintWebViewHelper::OnFramePreparedForPrintPages, 1843 base::Bind(&PrintWebViewHelper::OnFramePreparedForPrintPages,
1843 base::Unretained(this))); 1844 base::Unretained(this)));
1844 return true; 1845 return true;
1845 } 1846 }
1846 #endif // BUILDFLAG(ENABLE_BASIC_PRINTING) 1847 #endif // BUILDFLAG(ENABLE_BASIC_PRINTING)
1847 1848
1848 #if !defined(OS_MACOSX) 1849 #if !defined(OS_MACOSX)
1849 void PrintWebViewHelper::PrintPageInternal(const PrintMsg_Print_Params& params, 1850 void PrintWebViewHelper::PrintPageInternal(const PrintMsg_Print_Params& params,
1850 int page_number, 1851 int page_number,
1852 int page_count,
1851 blink::WebLocalFrame* frame, 1853 blink::WebLocalFrame* frame,
1852 PdfMetafileSkia* metafile, 1854 PdfMetafileSkia* metafile,
1853 gfx::Size* page_size_in_dpi, 1855 gfx::Size* page_size_in_dpi,
1854 gfx::Rect* content_area_in_dpi, 1856 gfx::Rect* content_area_in_dpi,
1855 gfx::Rect* printable_area_in_dpi) { 1857 gfx::Rect* printable_area_in_dpi) {
1856 PageSizeMargins page_layout_in_points; 1858 PageSizeMargins page_layout_in_points;
1857 1859
1858 double css_scale_factor = 1.0f; 1860 double css_scale_factor = 1.0f;
1859 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) 1861 #if BUILDFLAG(ENABLE_PRINT_PREVIEW)
1860 if (params.scale_factor >= kEpsilon) 1862 if (params.scale_factor >= kEpsilon)
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
1909 #if BUILDFLAG(ENABLE_PRINT_PREVIEW) 1911 #if BUILDFLAG(ENABLE_PRINT_PREVIEW)
1910 if (params.display_header_footer) { 1912 if (params.display_header_footer) {
1911 // TODO(thestig): Figure out why Linux needs this. It is almost certainly 1913 // TODO(thestig): Figure out why Linux needs this. It is almost certainly
1912 // |printingMinimumShrinkFactor| from Blink. 1914 // |printingMinimumShrinkFactor| from Blink.
1913 #if defined(OS_WIN) 1915 #if defined(OS_WIN)
1914 const float fudge_factor = 1; 1916 const float fudge_factor = 1;
1915 #else 1917 #else
1916 const float fudge_factor = kPrintingMinimumShrinkFactor; 1918 const float fudge_factor = kPrintingMinimumShrinkFactor;
1917 #endif 1919 #endif
1918 // |page_number| is 0-based, so 1 is added. 1920 // |page_number| is 0-based, so 1 is added.
1919 PrintHeaderAndFooter( 1921 PrintHeaderAndFooter(canvas, page_number + 1, page_count, *frame,
1920 canvas, page_number + 1, print_preview_context_.total_page_count(), 1922 scale_factor / fudge_factor, page_layout_in_points,
1921 *frame, scale_factor / fudge_factor, page_layout_in_points, params); 1923 params);
1922 } 1924 }
1923 #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW) 1925 #endif // BUILDFLAG(ENABLE_PRINT_PREVIEW)
1924 1926
1925 float webkit_scale_factor = RenderPageContent( 1927 float webkit_scale_factor = RenderPageContent(
1926 frame, page_number, canvas_area, content_area, scale_factor, canvas); 1928 frame, page_number, canvas_area, content_area, scale_factor, canvas);
1927 DCHECK_GT(webkit_scale_factor, 0.0f); 1929 DCHECK_GT(webkit_scale_factor, 0.0f);
1928 1930
1929 // Done printing. Close the canvas to retrieve the compiled metafile. 1931 // Done printing. Close the canvas to retrieve the compiled metafile.
1930 if (!metafile->FinishPage()) 1932 if (!metafile->FinishPage())
1931 NOTREACHED() << "metafile failed"; 1933 NOTREACHED() << "metafile failed";
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after
2368 blink::WebConsoleMessage::kLevelWarning, message)); 2370 blink::WebConsoleMessage::kLevelWarning, message));
2369 return false; 2371 return false;
2370 } 2372 }
2371 2373
2372 void PrintWebViewHelper::ScriptingThrottler::Reset() { 2374 void PrintWebViewHelper::ScriptingThrottler::Reset() {
2373 // Reset counter on successful print. 2375 // Reset counter on successful print.
2374 count_ = 0; 2376 count_ = 0;
2375 } 2377 }
2376 2378
2377 } // namespace printing 2379 } // namespace printing
OLDNEW
« no previous file with comments | « components/printing/renderer/print_web_view_helper.h ('k') | components/printing/renderer/print_web_view_helper_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698