OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/print_web_view_helper.h" | 5 #include "chrome/renderer/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/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "base/process_util.h" | 10 #include "base/process_util.h" |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 // The printPage method may take a reference to the canvas we pass down, so it | 188 // The printPage method may take a reference to the canvas we pass down, so it |
189 // can't be a stack object. | 189 // can't be a stack object. |
190 SkRefPtr<skia::VectorCanvas> canvas = new skia::VectorCanvas(device); | 190 SkRefPtr<skia::VectorCanvas> canvas = new skia::VectorCanvas(device); |
191 canvas->unref(); // SkRefPtr and new both took a reference. | 191 canvas->unref(); // SkRefPtr and new both took a reference. |
192 if (is_preview) { | 192 if (is_preview) { |
193 printing::MetafileSkiaWrapper::SetMetafileOnCanvas(canvas.get(), | 193 printing::MetafileSkiaWrapper::SetMetafileOnCanvas(canvas.get(), |
194 metafile->get()); | 194 metafile->get()); |
195 } | 195 } |
196 | 196 |
197 float webkit_scale_factor = frame->printPage(page_number, canvas.get()); | 197 float webkit_scale_factor = frame->printPage(page_number, canvas.get()); |
| 198 |
| 199 if (is_preview && params.display_header_footer) { |
| 200 // |page_number| is 0-based, so 1 is added. |
| 201 PrintHeaderAndFooter(device, *canvas, page_number + 1, |
| 202 print_preview_context_.total_page_count(), |
| 203 webkit_scale_factor, page_layout_in_points, |
| 204 *header_footer_info_); |
| 205 } |
| 206 |
198 if (*scale_factor <= 0 || webkit_scale_factor <= 0) { | 207 if (*scale_factor <= 0 || webkit_scale_factor <= 0) { |
199 NOTREACHED() << "Printing page " << page_number << " failed."; | 208 NOTREACHED() << "Printing page " << page_number << " failed."; |
200 } else { | 209 } else { |
201 // Update the dpi adjustment with the "page |scale_factor|" calculated in | 210 // Update the dpi adjustment with the "page |scale_factor|" calculated in |
202 // webkit. | 211 // webkit. |
203 *scale_factor /= webkit_scale_factor; | 212 *scale_factor /= webkit_scale_factor; |
204 } | 213 } |
205 | 214 |
206 bool result = (*metafile)->FinishPage(); | 215 bool result = (*metafile)->FinishPage(); |
207 DCHECK(result); | 216 DCHECK(result); |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 shared_buf.Unmap(); | 295 shared_buf.Unmap(); |
287 return false; | 296 return false; |
288 } | 297 } |
289 shared_buf.GiveToProcess(base::GetCurrentProcessHandle(), shared_mem_handle); | 298 shared_buf.GiveToProcess(base::GetCurrentProcessHandle(), shared_mem_handle); |
290 shared_buf.Unmap(); | 299 shared_buf.Unmap(); |
291 | 300 |
292 Send(new PrintHostMsg_DuplicateSection(routing_id(), *shared_mem_handle, | 301 Send(new PrintHostMsg_DuplicateSection(routing_id(), *shared_mem_handle, |
293 shared_mem_handle)); | 302 shared_mem_handle)); |
294 return true; | 303 return true; |
295 } | 304 } |
OLD | NEW |