| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/process/process_handle.h" | 9 #include "base/process/process_handle.h" |
| 10 #include "chrome/common/print_messages.h" | 10 #include "chrome/common/print_messages.h" |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 gfx::Rect(0, 0, page_size_in_dpi->width(), page_size_in_dpi->height()); | 172 gfx::Rect(0, 0, page_size_in_dpi->width(), page_size_in_dpi->height()); |
| 173 } | 173 } |
| 174 | 174 |
| 175 gfx::Rect canvas_area = | 175 gfx::Rect canvas_area = |
| 176 params.params.display_header_footer ? gfx::Rect(page_size) : content_area; | 176 params.params.display_header_footer ? gfx::Rect(page_size) : content_area; |
| 177 | 177 |
| 178 float webkit_page_shrink_factor = | 178 float webkit_page_shrink_factor = |
| 179 frame->getPrintPageShrink(params.page_number); | 179 frame->getPrintPageShrink(params.page_number); |
| 180 float scale_factor = css_scale_factor * webkit_page_shrink_factor; | 180 float scale_factor = css_scale_factor * webkit_page_shrink_factor; |
| 181 | 181 |
| 182 SkBaseDevice* device = metafile->StartPageForVectorCanvas(page_size, | 182 skia::VectorCanvas* canvas = metafile->GetVectorCanvasForNewPage( |
| 183 canvas_area, | 183 page_size, canvas_area, scale_factor); |
| 184 scale_factor); | 184 if (!canvas) |
| 185 if (!device) | |
| 186 return; | 185 return; |
| 187 | 186 |
| 188 // The printPage method take a reference to the canvas we pass down, so it | |
| 189 // can't be a stack object. | |
| 190 skia::RefPtr<skia::VectorCanvas> canvas = | |
| 191 skia::AdoptRef(new skia::VectorCanvas(device)); | |
| 192 MetafileSkiaWrapper::SetMetafileOnCanvas(*canvas, metafile); | 187 MetafileSkiaWrapper::SetMetafileOnCanvas(*canvas, metafile); |
| 193 skia::SetIsDraftMode(*canvas, is_print_ready_metafile_sent_); | 188 skia::SetIsDraftMode(*canvas, is_print_ready_metafile_sent_); |
| 194 | 189 |
| 195 if (params.params.display_header_footer) { | 190 if (params.params.display_header_footer) { |
| 196 // |page_number| is 0-based, so 1 is added. | 191 // |page_number| is 0-based, so 1 is added. |
| 197 PrintHeaderAndFooter(canvas.get(), | 192 PrintHeaderAndFooter(canvas, |
| 198 params.page_number + 1, | 193 params.page_number + 1, |
| 199 print_preview_context_.total_page_count(), | 194 print_preview_context_.total_page_count(), |
| 200 *frame, | 195 *frame, |
| 201 scale_factor, | 196 scale_factor, |
| 202 page_layout_in_points, | 197 page_layout_in_points, |
| 203 params.params); | 198 params.params); |
| 204 } | 199 } |
| 205 | 200 |
| 206 float webkit_scale_factor = RenderPageContent(frame, | 201 float webkit_scale_factor = RenderPageContent(frame, |
| 207 params.page_number, | 202 params.page_number, |
| 208 canvas_area, | 203 canvas_area, |
| 209 content_area, | 204 content_area, |
| 210 scale_factor, | 205 scale_factor, |
| 211 canvas.get()); | 206 canvas); |
| 212 DCHECK_GT(webkit_scale_factor, 0.0f); | 207 DCHECK_GT(webkit_scale_factor, 0.0f); |
| 213 // Done printing. Close the device context to retrieve the compiled metafile. | 208 // Done printing. Close the canvas to retrieve the compiled metafile. |
| 214 if (!metafile->FinishPage()) | 209 if (!metafile->FinishPage()) |
| 215 NOTREACHED() << "metafile failed"; | 210 NOTREACHED() << "metafile failed"; |
| 216 } | 211 } |
| 217 | 212 |
| 218 bool PrintWebViewHelper::CopyMetafileDataToSharedMem( | 213 bool PrintWebViewHelper::CopyMetafileDataToSharedMem( |
| 219 PdfMetafileSkia* metafile, | 214 PdfMetafileSkia* metafile, |
| 220 base::SharedMemoryHandle* shared_mem_handle) { | 215 base::SharedMemoryHandle* shared_mem_handle) { |
| 221 uint32 buf_size = metafile->GetDataSize(); | 216 uint32 buf_size = metafile->GetDataSize(); |
| 222 base::SharedMemory shared_buf; | 217 base::SharedMemory shared_buf; |
| 223 // Allocate a shared memory buffer to hold the generated metafile data. | 218 // Allocate a shared memory buffer to hold the generated metafile data. |
| (...skipping 10 matching lines...) Expand all Loading... |
| 234 } | 229 } |
| 235 shared_buf.GiveToProcess(base::GetCurrentProcessHandle(), shared_mem_handle); | 230 shared_buf.GiveToProcess(base::GetCurrentProcessHandle(), shared_mem_handle); |
| 236 shared_buf.Unmap(); | 231 shared_buf.Unmap(); |
| 237 | 232 |
| 238 Send(new PrintHostMsg_DuplicateSection(routing_id(), *shared_mem_handle, | 233 Send(new PrintHostMsg_DuplicateSection(routing_id(), *shared_mem_handle, |
| 239 shared_mem_handle)); | 234 shared_mem_handle)); |
| 240 return true; | 235 return true; |
| 241 } | 236 } |
| 242 | 237 |
| 243 } // namespace printing | 238 } // namespace printing |
| OLD | NEW |