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 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
180 page_size, content_area, frame->getPrintPageShrink(page_number)); | 180 page_size, content_area, frame->getPrintPageShrink(page_number)); |
181 DCHECK(device); | 181 DCHECK(device); |
182 // The printPage method may take a reference to the canvas we pass down, so it | 182 // The printPage method may take a reference to the canvas we pass down, so it |
183 // can't be a stack object. | 183 // can't be a stack object. |
184 SkRefPtr<skia::VectorCanvas> canvas = new skia::VectorCanvas(device); | 184 SkRefPtr<skia::VectorCanvas> canvas = new skia::VectorCanvas(device); |
185 canvas->unref(); // SkRefPtr and new both took a reference. | 185 canvas->unref(); // SkRefPtr and new both took a reference. |
186 if (is_preview) | 186 if (is_preview) |
187 printing::MetafileSkiaWrapper::SetMetafileOnCanvas(canvas.get(), metafile); | 187 printing::MetafileSkiaWrapper::SetMetafileOnCanvas(canvas.get(), metafile); |
188 | 188 |
189 float webkit_scale_factor = frame->printPage(page_number, canvas.get()); | 189 float webkit_scale_factor = frame->printPage(page_number, canvas.get()); |
190 | |
191 if (params.display_header_footer) { | |
192 // |page_number| is 0-based, so 1 is added. | |
193 PrintHeaderAndFooter(device, canvas.get(), page_number + 1, | |
194 print_preview_context_.total_page_count(), | |
195 webkit_scale_factor, page_layout_in_points, | |
196 *header_footer_info_); | |
197 } | |
198 | |
199 if (*scale_factor <= 0 || webkit_scale_factor <= 0) { | 190 if (*scale_factor <= 0 || webkit_scale_factor <= 0) { |
200 NOTREACHED() << "Printing page " << page_number << " failed."; | 191 NOTREACHED() << "Printing page " << page_number << " failed."; |
201 } else { | 192 } else { |
202 // Update the dpi adjustment with the "page |scale_factor|" calculated in | 193 // Update the dpi adjustment with the "page |scale_factor|" calculated in |
203 // webkit. | 194 // webkit. |
204 *scale_factor /= webkit_scale_factor; | 195 *scale_factor /= webkit_scale_factor; |
205 } | 196 } |
206 | 197 |
207 bool result = metafile->FinishPage(); | 198 bool result = metafile->FinishPage(); |
208 DCHECK(result); | 199 DCHECK(result); |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
287 shared_buf.Unmap(); | 278 shared_buf.Unmap(); |
288 return false; | 279 return false; |
289 } | 280 } |
290 shared_buf.GiveToProcess(base::GetCurrentProcessHandle(), shared_mem_handle); | 281 shared_buf.GiveToProcess(base::GetCurrentProcessHandle(), shared_mem_handle); |
291 shared_buf.Unmap(); | 282 shared_buf.Unmap(); |
292 | 283 |
293 Send(new PrintHostMsg_DuplicateSection(routing_id(), *shared_mem_handle, | 284 Send(new PrintHostMsg_DuplicateSection(routing_id(), *shared_mem_handle, |
294 shared_mem_handle)); | 285 shared_mem_handle)); |
295 return true; | 286 return true; |
296 } | 287 } |
OLD | NEW |