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 "base/file_descriptor_posix.h" | |
8 #include "base/logging.h" | 7 #include "base/logging.h" |
9 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
10 #include "base/metrics/histogram.h" | |
11 #include "chrome/common/print_messages.h" | 9 #include "chrome/common/print_messages.h" |
12 #include "content/public/renderer/render_thread.h" | 10 #include "content/public/renderer/render_thread.h" |
13 #include "printing/metafile.h" | 11 #include "printing/metafile.h" |
14 #include "printing/metafile_impl.h" | 12 #include "printing/metafile_impl.h" |
15 #include "printing/metafile_skia_wrapper.h" | 13 #include "printing/metafile_skia_wrapper.h" |
16 #include "printing/page_size_margins.h" | 14 #include "printing/page_size_margins.h" |
17 #include "skia/ext/platform_device.h" | 15 #include "skia/ext/platform_device.h" |
18 #include "skia/ext/vector_canvas.h" | 16 #include "skia/ext/vector_canvas.h" |
19 #include "third_party/WebKit/public/web/WebFrame.h" | 17 #include "third_party/WebKit/public/web/WebFrame.h" |
20 | 18 |
21 #if !defined(OS_CHROMEOS) | 19 #if !defined(OS_CHROMEOS) && !defined(OS_ANDROID) |
22 #include "base/process/process_handle.h" | 20 #include "base/process/process_handle.h" |
23 #endif // !defined(OS_CHROMEOS) | 21 #else |
| 22 #include "base/file_descriptor_posix.h" |
| 23 #endif // !defined(OS_CHROMEOS) && !defined(OS_ANDROID) |
24 | 24 |
25 namespace printing { | 25 namespace printing { |
26 | 26 |
27 using WebKit::WebFrame; | 27 using WebKit::WebFrame; |
28 using WebKit::WebNode; | 28 using WebKit::WebNode; |
29 | 29 |
30 bool PrintWebViewHelper::RenderPreviewPage( | 30 bool PrintWebViewHelper::RenderPreviewPage( |
31 int page_number, | 31 int page_number, |
32 const PrintMsg_Print_Params& print_params) { | 32 const PrintMsg_Print_Params& print_params) { |
33 PrintMsg_PrintPage_Params page_params; | 33 PrintMsg_PrintPage_Params page_params; |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 | 94 |
95 // WebKit::printEnd() for PDF should be called before metafile is closed. | 95 // WebKit::printEnd() for PDF should be called before metafile is closed. |
96 FinishFramePrinting(); | 96 FinishFramePrinting(); |
97 | 97 |
98 metafile.FinishDocument(); | 98 metafile.FinishDocument(); |
99 | 99 |
100 // Get the size of the resulting metafile. | 100 // Get the size of the resulting metafile. |
101 uint32 buf_size = metafile.GetDataSize(); | 101 uint32 buf_size = metafile.GetDataSize(); |
102 DCHECK_GT(buf_size, 0u); | 102 DCHECK_GT(buf_size, 0u); |
103 | 103 |
104 #if defined(OS_CHROMEOS) | 104 #if defined(OS_CHROMEOS) || defined(OS_ANDROID) |
105 int sequence_number = -1; | 105 int sequence_number = -1; |
106 base::FileDescriptor fd; | 106 base::FileDescriptor fd; |
107 | 107 |
108 // Ask the browser to open a file for us. | 108 // Ask the browser to open a file for us. |
109 Send(new PrintHostMsg_AllocateTempFileForPrinting(&fd, &sequence_number)); | 109 Send(new PrintHostMsg_AllocateTempFileForPrinting(routing_id(), |
| 110 &fd, |
| 111 &sequence_number)); |
110 if (!metafile.SaveToFD(fd)) | 112 if (!metafile.SaveToFD(fd)) |
111 return false; | 113 return false; |
112 | 114 |
113 // Tell the browser we've finished writing the file. | 115 // Tell the browser we've finished writing the file. |
114 Send(new PrintHostMsg_TempFileForPrintingWritten(routing_id(), | 116 Send(new PrintHostMsg_TempFileForPrintingWritten(routing_id(), |
115 sequence_number)); | 117 sequence_number)); |
116 return true; | 118 return true; |
117 #else | 119 #else |
118 PrintHostMsg_DidPrintPage_Params printed_page_params; | 120 PrintHostMsg_DidPrintPage_Params printed_page_params; |
119 printed_page_params.data_size = 0; | 121 printed_page_params.data_size = 0; |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 } | 190 } |
189 RenderPageContent(frame, params.page_number, canvas_area, content_area, | 191 RenderPageContent(frame, params.page_number, canvas_area, content_area, |
190 scale_factor, canvas.get()); | 192 scale_factor, canvas.get()); |
191 | 193 |
192 // Done printing. Close the device context to retrieve the compiled metafile. | 194 // Done printing. Close the device context to retrieve the compiled metafile. |
193 if (!metafile->FinishPage()) | 195 if (!metafile->FinishPage()) |
194 NOTREACHED() << "metafile failed"; | 196 NOTREACHED() << "metafile failed"; |
195 } | 197 } |
196 | 198 |
197 } // namespace printing | 199 } // namespace printing |
OLD | NEW |