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