Chromium Code Reviews| 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 11 matching lines...) Expand all Loading... | |
| 22 #include "base/process_util.h" | 22 #include "base/process_util.h" |
| 23 #endif // !defined(OS_CHROMEOS) | 23 #endif // !defined(OS_CHROMEOS) |
| 24 | 24 |
| 25 using WebKit::WebFrame; | 25 using WebKit::WebFrame; |
| 26 using WebKit::WebNode; | 26 using WebKit::WebNode; |
| 27 | 27 |
| 28 void PrintWebViewHelper::RenderPreviewPage(int page_number) { | 28 void PrintWebViewHelper::RenderPreviewPage(int page_number) { |
| 29 PrintMsg_PrintPage_Params page_params; | 29 PrintMsg_PrintPage_Params page_params; |
| 30 page_params.params = print_preview_context_.print_params(); | 30 page_params.params = print_preview_context_.print_params(); |
| 31 page_params.page_number = page_number; | 31 page_params.page_number = page_number; |
| 32 printing::Metafile* initial_render_metafile = | |
| 33 is_complete_metafile_already_sent_ ? new printing::PreviewMetafile() : | |
|
vandebo (ex-Chrome)
2011/08/03 20:48:21
It looks like metafile will leak in the first case
kmadhusu
2011/08/04 20:47:53
Done.
| |
| 34 print_preview_context_.metafile(); | |
| 32 | 35 |
| 33 base::TimeTicks begin_time = base::TimeTicks::Now(); | 36 base::TimeTicks begin_time = base::TimeTicks::Now(); |
| 34 PrintPageInternal(page_params, | 37 PrintPageInternal(page_params, |
| 35 print_preview_context_.GetPrintCanvasSize(), | 38 print_preview_context_.GetPrintCanvasSize(), |
| 36 print_preview_context_.frame(), | 39 print_preview_context_.frame(), initial_render_metafile); |
| 37 print_preview_context_.metafile()); | |
| 38 | |
| 39 print_preview_context_.RenderedPreviewPage( | 40 print_preview_context_.RenderedPreviewPage( |
| 40 base::TimeTicks::Now() - begin_time); | 41 base::TimeTicks::Now() - begin_time); |
| 41 printing::Metafile* page_metafile = NULL; | 42 printing::Metafile* page_metafile = NULL; |
|
vandebo (ex-Chrome)
2011/08/03 20:48:21
page_metafile = initial_render_metafile;
kmadhusu
2011/08/04 20:47:53
Done.
| |
| 42 if (print_preview_context_.IsModifiable()) { | 43 if (print_preview_context_.IsModifiable()) { |
|
vandebo (ex-Chrome)
2011/08/03 20:48:21
if (.... & !is_complete_metafile_already_sent) {
kmadhusu
2011/08/04 20:47:53
Done.
| |
| 43 page_metafile = reinterpret_cast<printing::PreviewMetafile*>( | 44 page_metafile = reinterpret_cast<printing::PreviewMetafile*>( |
| 44 print_preview_context_.metafile())->GetMetafileForCurrentPage(); | 45 initial_render_metafile)->GetMetafileForCurrentPage(); |
| 45 } | 46 } |
| 46 PreviewPageRendered(page_number, page_metafile); | 47 PreviewPageRendered(page_number, page_metafile); |
| 47 } | 48 } |
| 48 | 49 |
| 49 bool PrintWebViewHelper::PrintPages(const PrintMsg_PrintPages_Params& params, | 50 bool PrintWebViewHelper::PrintPages(const PrintMsg_PrintPages_Params& params, |
| 50 WebFrame* frame, | 51 WebFrame* frame, |
| 51 WebNode* node, | 52 WebNode* node, |
| 52 PrepareFrameAndViewForPrint* prepare) { | 53 PrepareFrameAndViewForPrint* prepare) { |
| 53 printing::NativeMetafile metafile; | 54 printing::NativeMetafile metafile; |
| 54 if (!metafile.Init()) | 55 if (!metafile.Init()) |
| (...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 200 SkDevice* device = metafile->StartPageForVectorCanvas( | 201 SkDevice* device = metafile->StartPageForVectorCanvas( |
| 201 page_size, content_area, 1.0f); | 202 page_size, content_area, 1.0f); |
| 202 if (!device) | 203 if (!device) |
| 203 return; | 204 return; |
| 204 | 205 |
| 205 // The printPage method take a reference to the canvas we pass down, so it | 206 // The printPage method take a reference to the canvas we pass down, so it |
| 206 // can't be a stack object. | 207 // can't be a stack object. |
| 207 SkRefPtr<skia::VectorCanvas> canvas = new skia::VectorCanvas(device); | 208 SkRefPtr<skia::VectorCanvas> canvas = new skia::VectorCanvas(device); |
| 208 canvas->unref(); // SkRefPtr and new both took a reference. | 209 canvas->unref(); // SkRefPtr and new both took a reference. |
| 209 printing::MetafileSkiaWrapper::SetMetafileOnCanvas(canvas.get(), metafile); | 210 printing::MetafileSkiaWrapper::SetMetafileOnCanvas(canvas.get(), metafile); |
| 211 bool draft_mode = is_complete_metafile_already_sent_; | |
| 212 printing::MetafileSkiaWrapper::SetDraftMode(canvas.get(), draft_mode); | |
| 210 frame->printPage(params.page_number, canvas.get()); | 213 frame->printPage(params.page_number, canvas.get()); |
| 211 | 214 |
| 212 // TODO(myhuang): We should render the header and the footer. | 215 // TODO(myhuang): We should render the header and the footer. |
| 213 | 216 |
| 214 // Done printing. Close the device context to retrieve the compiled metafile. | 217 // Done printing. Close the device context to retrieve the compiled metafile. |
| 215 if (!metafile->FinishPage()) | 218 if (!metafile->FinishPage()) |
| 216 NOTREACHED() << "metafile failed"; | 219 NOTREACHED() << "metafile failed"; |
| 217 } | 220 } |
| OLD | NEW |