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

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

Issue 1556463003: Mark printing code as basic printing and/or print preview code. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 11 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 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/memory/scoped_ptr.h" 10 #include "base/memory/scoped_ptr.h"
11 #include "build/build_config.h" 11 #include "build/build_config.h"
12 #include "components/printing/common/print_messages.h" 12 #include "components/printing/common/print_messages.h"
13 #include "content/public/renderer/render_thread.h" 13 #include "content/public/renderer/render_thread.h"
14 #include "printing/metafile_skia_wrapper.h" 14 #include "printing/metafile_skia_wrapper.h"
15 #include "printing/page_size_margins.h" 15 #include "printing/page_size_margins.h"
16 #include "printing/pdf_metafile_skia.h" 16 #include "printing/pdf_metafile_skia.h"
17 #include "third_party/WebKit/public/web/WebLocalFrame.h" 17 #include "third_party/WebKit/public/web/WebLocalFrame.h"
18 18
19 #if defined(OS_CHROMEOS) || defined(OS_ANDROID) 19 #if defined(OS_ANDROID)
20 #include "base/file_descriptor_posix.h" 20 #include "base/file_descriptor_posix.h"
21 #else 21 #else
22 #include "base/process/process_handle.h" 22 #include "base/process/process_handle.h"
23 #endif // defined(OS_CHROMEOS) || defined(OS_ANDROID) 23 #endif // defined(OS_ANDROID)
24 24
25 namespace printing { 25 namespace printing {
26 26
27 using blink::WebFrame; 27 #if defined(ENABLE_PRINT_PREVIEW)
28
29 bool PrintWebViewHelper::RenderPreviewPage( 28 bool PrintWebViewHelper::RenderPreviewPage(
30 int page_number, 29 int page_number,
31 const PrintMsg_Print_Params& print_params) { 30 const PrintMsg_Print_Params& print_params) {
32 PrintMsg_PrintPage_Params page_params; 31 PrintMsg_PrintPage_Params page_params;
33 page_params.params = print_params; 32 page_params.params = print_params;
34 page_params.page_number = page_number; 33 page_params.page_number = page_number;
35 scoped_ptr<PdfMetafileSkia> draft_metafile; 34 scoped_ptr<PdfMetafileSkia> draft_metafile;
36 PdfMetafileSkia* initial_render_metafile = print_preview_context_.metafile(); 35 PdfMetafileSkia* initial_render_metafile = print_preview_context_.metafile();
37 if (print_preview_context_.IsModifiable() && is_print_ready_metafile_sent_) { 36 if (print_preview_context_.IsModifiable() && is_print_ready_metafile_sent_) {
38 draft_metafile.reset(new PdfMetafileSkia); 37 draft_metafile.reset(new PdfMetafileSkia);
39 initial_render_metafile = draft_metafile.get(); 38 initial_render_metafile = draft_metafile.get();
40 } 39 }
41 40
42 base::TimeTicks begin_time = base::TimeTicks::Now(); 41 base::TimeTicks begin_time = base::TimeTicks::Now();
43 PrintPageInternal(page_params, 42 PrintPageInternal(page_params,
44 print_preview_context_.prepared_frame(), 43 print_preview_context_.prepared_frame(),
45 initial_render_metafile); 44 initial_render_metafile);
46 print_preview_context_.RenderedPreviewPage( 45 print_preview_context_.RenderedPreviewPage(
47 base::TimeTicks::Now() - begin_time); 46 base::TimeTicks::Now() - begin_time);
48 if (draft_metafile.get()) { 47 if (draft_metafile.get()) {
49 draft_metafile->FinishDocument(); 48 draft_metafile->FinishDocument();
50 } else if (print_preview_context_.IsModifiable() && 49 } else if (print_preview_context_.IsModifiable() &&
51 print_preview_context_.generate_draft_pages()) { 50 print_preview_context_.generate_draft_pages()) {
52 DCHECK(!draft_metafile.get()); 51 DCHECK(!draft_metafile.get());
53 draft_metafile = 52 draft_metafile =
54 print_preview_context_.metafile()->GetMetafileForCurrentPage(); 53 print_preview_context_.metafile()->GetMetafileForCurrentPage();
55 } 54 }
56 return PreviewPageRendered(page_number, draft_metafile.get()); 55 return PreviewPageRendered(page_number, draft_metafile.get());
57 } 56 }
57 #endif
58 58
59 #if defined(ENABLE_BASIC_PRINTING)
59 bool PrintWebViewHelper::PrintPagesNative(blink::WebFrame* frame, 60 bool PrintWebViewHelper::PrintPagesNative(blink::WebFrame* frame,
60 int page_count) { 61 int page_count) {
61 PdfMetafileSkia metafile; 62 PdfMetafileSkia metafile;
62 if (!metafile.Init()) 63 if (!metafile.Init())
63 return false; 64 return false;
64 65
65 const PrintMsg_PrintPages_Params& params = *print_pages_params_; 66 const PrintMsg_PrintPages_Params& params = *print_pages_params_;
66 std::vector<int> printed_pages = GetPrintedPages(params, page_count); 67 std::vector<int> printed_pages = GetPrintedPages(params, page_count);
67 if (printed_pages.empty()) 68 if (printed_pages.empty())
68 return false; 69 return false;
69 70
70 PrintMsg_PrintPage_Params page_params; 71 PrintMsg_PrintPage_Params page_params;
71 page_params.params = params.params; 72 page_params.params = params.params;
72 for (int page_number : printed_pages) { 73 for (int page_number : printed_pages) {
73 page_params.page_number = page_number; 74 page_params.page_number = page_number;
74 PrintPageInternal(page_params, frame, &metafile); 75 PrintPageInternal(page_params, frame, &metafile);
75 } 76 }
76 77
77 // blink::printEnd() for PDF should be called before metafile is closed. 78 // blink::printEnd() for PDF should be called before metafile is closed.
78 FinishFramePrinting(); 79 FinishFramePrinting();
79 80
80 metafile.FinishDocument(); 81 metafile.FinishDocument();
81 82
82 #if defined(OS_CHROMEOS) 83 #if defined(OS_ANDROID)
83 NOTREACHED();
84 return false;
85 #elif defined(OS_ANDROID)
86 int sequence_number = -1; 84 int sequence_number = -1;
87 base::FileDescriptor fd; 85 base::FileDescriptor fd;
88 86
89 // Ask the browser to open a file for us. 87 // Ask the browser to open a file for us.
90 Send(new PrintHostMsg_AllocateTempFileForPrinting(routing_id(), 88 Send(new PrintHostMsg_AllocateTempFileForPrinting(routing_id(),
91 &fd, 89 &fd,
92 &sequence_number)); 90 &sequence_number));
93 if (!metafile.SaveToFD(fd)) 91 if (!metafile.SaveToFD(fd))
94 return false; 92 return false;
95 93
(...skipping 12 matching lines...) Expand all
108 printed_page_params.data_size = metafile.GetDataSize(); 106 printed_page_params.data_size = metafile.GetDataSize();
109 printed_page_params.document_cookie = params.params.document_cookie; 107 printed_page_params.document_cookie = params.params.document_cookie;
110 108
111 for (size_t i = 0; i < printed_pages.size(); ++i) { 109 for (size_t i = 0; i < printed_pages.size(); ++i) {
112 printed_page_params.page_number = printed_pages[i]; 110 printed_page_params.page_number = printed_pages[i];
113 Send(new PrintHostMsg_DidPrintPage(routing_id(), printed_page_params)); 111 Send(new PrintHostMsg_DidPrintPage(routing_id(), printed_page_params));
114 // Send the rest of the pages with an invalid metafile handle. 112 // Send the rest of the pages with an invalid metafile handle.
115 printed_page_params.metafile_data_handle.fd = -1; 113 printed_page_params.metafile_data_handle.fd = -1;
116 } 114 }
117 return true; 115 return true;
118 #endif // defined(OS_CHROMEOS) 116 #endif // defined(OS_ANDROID)
119 } 117 }
118 #endif // defined(ENABLE_BASIC_PRINTING)
120 119
121 void PrintWebViewHelper::PrintPageInternal( 120 void PrintWebViewHelper::PrintPageInternal(
122 const PrintMsg_PrintPage_Params& params, 121 const PrintMsg_PrintPage_Params& params,
123 WebFrame* frame, 122 blink::WebFrame* frame,
124 PdfMetafileSkia* metafile) { 123 PdfMetafileSkia* metafile) {
125 PageSizeMargins page_layout_in_points; 124 PageSizeMargins page_layout_in_points;
126 double scale_factor = 1.0f; 125 double scale_factor = 1.0f;
127 ComputePageLayoutInPointsForCss(frame, params.page_number, params.params, 126 ComputePageLayoutInPointsForCss(frame, params.page_number, params.params,
128 ignore_css_margins_, &scale_factor, 127 ignore_css_margins_, &scale_factor,
129 &page_layout_in_points); 128 &page_layout_in_points);
130 gfx::Size page_size; 129 gfx::Size page_size;
131 gfx::Rect content_area; 130 gfx::Rect content_area;
132 GetPageSizeAndContentAreaFromPageLayout(page_layout_in_points, &page_size, 131 GetPageSizeAndContentAreaFromPageLayout(page_layout_in_points, &page_size,
133 &content_area); 132 &content_area);
(...skipping 20 matching lines...) Expand all
154 153
155 RenderPageContent(frame, params.page_number, canvas_area, content_area, 154 RenderPageContent(frame, params.page_number, canvas_area, content_area,
156 scale_factor, canvas); 155 scale_factor, canvas);
157 156
158 // Done printing. Close the canvas to retrieve the compiled metafile. 157 // Done printing. Close the canvas to retrieve the compiled metafile.
159 if (!metafile->FinishPage()) 158 if (!metafile->FinishPage())
160 NOTREACHED() << "metafile failed"; 159 NOTREACHED() << "metafile failed";
161 } 160 }
162 161
163 } // namespace printing 162 } // namespace printing
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698