| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 #import <AppKit/AppKit.h> | 7 #import <AppKit/AppKit.h> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "chrome/common/render_messages.h" | 10 #include "chrome/common/render_messages.h" |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 return; | 62 return; |
| 63 } | 63 } |
| 64 | 64 |
| 65 page_params.data_size = metafile.GetDataSize(); | 65 page_params.data_size = metafile.GetDataSize(); |
| 66 Send(new ViewHostMsg_DidPrintPage(routing_id(), page_params)); | 66 Send(new ViewHostMsg_DidPrintPage(routing_id(), page_params)); |
| 67 } | 67 } |
| 68 | 68 |
| 69 void PrintWebViewHelper::CreatePreviewDocument( | 69 void PrintWebViewHelper::CreatePreviewDocument( |
| 70 const ViewMsg_PrintPages_Params& params, | 70 const ViewMsg_PrintPages_Params& params, |
| 71 WebFrame* frame, | 71 WebFrame* frame, |
| 72 ViewHostMsg_DidPreviewDocument_Params* print_params) { | 72 ViewHostMsg_DidPreviewDocument_Params* preview_params) { |
| 73 ViewMsg_Print_Params printParams = params.params; | 73 ViewMsg_Print_Params printParams = params.params; |
| 74 UpdatePrintableSizeInPrintParameters(frame, NULL, &printParams); | 74 UpdatePrintableSizeInPrintParameters(frame, NULL, &printParams); |
| 75 | 75 |
| 76 PrepareFrameAndViewForPrint prep_frame_view(printParams, | 76 PrepareFrameAndViewForPrint prep_frame_view(printParams, |
| 77 frame, NULL, frame->view()); | 77 frame, NULL, frame->view()); |
| 78 int page_count = prep_frame_view.GetExpectedPageCount(); | 78 int page_count = prep_frame_view.GetExpectedPageCount(); |
| 79 | 79 |
| 80 if (!page_count) | 80 if (!page_count) |
| 81 return; | 81 return; |
| 82 | 82 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 99 for (size_t i = 0; i < params.pages.size(); ++i) { | 99 for (size_t i = 0; i < params.pages.size(); ++i) { |
| 100 if (params.pages[i] >= page_count) | 100 if (params.pages[i] >= page_count) |
| 101 break; | 101 break; |
| 102 RenderPage(printParams.page_size, origin, scale_factor, | 102 RenderPage(printParams.page_size, origin, scale_factor, |
| 103 static_cast<int>(params.pages[i]), frame, &metafile); | 103 static_cast<int>(params.pages[i]), frame, &metafile); |
| 104 } | 104 } |
| 105 } | 105 } |
| 106 metafile.Close(); | 106 metafile.Close(); |
| 107 // Ask the browser to create the shared memory for us. | 107 // Ask the browser to create the shared memory for us. |
| 108 if (!CopyMetafileDataToSharedMem(&metafile, | 108 if (!CopyMetafileDataToSharedMem(&metafile, |
| 109 &(print_params->metafile_data_handle))) { | 109 &(preview_params->metafile_data_handle))) { |
| 110 NOTREACHED(); | 110 NOTREACHED(); |
| 111 return; | 111 return; |
| 112 } | 112 } |
| 113 print_params->document_cookie = params.params.document_cookie; | 113 preview_params->document_cookie = params.params.document_cookie; |
| 114 print_params->data_size = metafile.GetDataSize(); | 114 preview_params->data_size = metafile.GetDataSize(); |
| 115 } | 115 } |
| 116 | 116 |
| 117 void PrintWebViewHelper::RenderPage( | 117 void PrintWebViewHelper::RenderPage( |
| 118 const gfx::Size& page_size, const gfx::Point& content_origin, | 118 const gfx::Size& page_size, const gfx::Point& content_origin, |
| 119 const float& scale_factor, int page_number, WebFrame* frame, | 119 const float& scale_factor, int page_number, WebFrame* frame, |
| 120 printing::NativeMetafile* metafile) { | 120 printing::NativeMetafile* metafile) { |
| 121 CGContextRef context = metafile->StartPage(page_size, content_origin, | 121 CGContextRef context = metafile->StartPage(page_size, content_origin, |
| 122 scale_factor); | 122 scale_factor); |
| 123 DCHECK(context); | 123 DCHECK(context); |
| 124 | 124 |
| 125 // printPage can create autoreleased references to |context|. PDF contexts | 125 // printPage can create autoreleased references to |context|. PDF contexts |
| 126 // don't write all their data until they are destroyed, so we need to make | 126 // don't write all their data until they are destroyed, so we need to make |
| 127 // certain that there are no lingering references. | 127 // certain that there are no lingering references. |
| 128 NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; | 128 NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; |
| 129 frame->printPage(page_number, context); | 129 frame->printPage(page_number, context); |
| 130 [pool release]; | 130 [pool release]; |
| 131 | 131 |
| 132 // Done printing. Close the device context to retrieve the compiled metafile. | 132 // Done printing. Close the device context to retrieve the compiled metafile. |
| 133 metafile->FinishPage(); | 133 metafile->FinishPage(); |
| 134 } | 134 } |
| OLD | NEW |