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/file_descriptor_posix.h" | 7 #include "base/file_descriptor_posix.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 page_params.page_number = page_number; | 31 page_params.page_number = page_number; |
32 | 32 |
33 base::TimeTicks begin_time = base::TimeTicks::Now(); | 33 base::TimeTicks begin_time = base::TimeTicks::Now(); |
34 PrintPageInternal(page_params, | 34 PrintPageInternal(page_params, |
35 print_preview_context_.GetPrintCanvasSize(), | 35 print_preview_context_.GetPrintCanvasSize(), |
36 print_preview_context_.frame(), | 36 print_preview_context_.frame(), |
37 print_preview_context_.metafile()); | 37 print_preview_context_.metafile()); |
38 | 38 |
39 print_preview_context_.RenderedPreviewPage( | 39 print_preview_context_.RenderedPreviewPage( |
40 base::TimeTicks::Now() - begin_time); | 40 base::TimeTicks::Now() - begin_time); |
41 printing::Metafile* page_metafile = NULL; | 41 scoped_ptr<printing::Metafile> page_metafile; |
42 if (print_preview_context_.IsModifiable()) { | 42 if (print_preview_context_.IsModifiable()) { |
43 page_metafile = reinterpret_cast<printing::PreviewMetafile*>( | 43 page_metafile.reset(reinterpret_cast<printing::PreviewMetafile*>( |
44 print_preview_context_.metafile())->GetMetafileForCurrentPage(); | 44 print_preview_context_.metafile())->GetMetafileForCurrentPage()); |
45 } | 45 } |
46 PreviewPageRendered(page_number, page_metafile); | 46 PreviewPageRendered(page_number, page_metafile.get()); |
47 } | 47 } |
48 | 48 |
49 bool PrintWebViewHelper::PrintPages(const PrintMsg_PrintPages_Params& params, | 49 bool PrintWebViewHelper::PrintPages(const PrintMsg_PrintPages_Params& params, |
50 WebFrame* frame, | 50 WebFrame* frame, |
51 WebNode* node, | 51 WebNode* node, |
52 PrepareFrameAndViewForPrint* prepare) { | 52 PrepareFrameAndViewForPrint* prepare) { |
53 printing::NativeMetafile metafile; | 53 printing::NativeMetafile metafile; |
54 if (!metafile.Init()) | 54 if (!metafile.Init()) |
55 return false; | 55 return false; |
56 | 56 |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 canvas->unref(); // SkRefPtr and new both took a reference. | 208 canvas->unref(); // SkRefPtr and new both took a reference. |
209 printing::MetafileSkiaWrapper::SetMetafileOnCanvas(canvas.get(), metafile); | 209 printing::MetafileSkiaWrapper::SetMetafileOnCanvas(canvas.get(), metafile); |
210 frame->printPage(params.page_number, canvas.get()); | 210 frame->printPage(params.page_number, canvas.get()); |
211 | 211 |
212 // TODO(myhuang): We should render the header and the footer. | 212 // TODO(myhuang): We should render the header and the footer. |
213 | 213 |
214 // Done printing. Close the device context to retrieve the compiled metafile. | 214 // Done printing. Close the device context to retrieve the compiled metafile. |
215 if (!metafile->FinishPage()) | 215 if (!metafile->FinishPage()) |
216 NOTREACHED() << "metafile failed"; | 216 NOTREACHED() << "metafile failed"; |
217 } | 217 } |
OLD | NEW |