OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/browser/printing/print_view_manager.h" | 5 #include "chrome/browser/printing/print_view_manager.h" |
6 | 6 |
7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
| 8 #include "base/scoped_ptr.h" |
8 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
9 #include "chrome/browser/printing/print_job.h" | 10 #include "chrome/browser/printing/print_job.h" |
10 #include "chrome/browser/printing/print_job_manager.h" | 11 #include "chrome/browser/printing/print_job_manager.h" |
11 #include "chrome/browser/printing/printed_document.h" | 12 #include "chrome/browser/printing/printed_document.h" |
12 #include "chrome/browser/printing/printer_query.h" | 13 #include "chrome/browser/printing/printer_query.h" |
13 #include "chrome/browser/renderer_host/render_view_host.h" | 14 #include "chrome/browser/renderer_host/render_view_host.h" |
14 #include "chrome/browser/tab_contents/navigation_entry.h" | 15 #include "chrome/browser/tab_contents/navigation_entry.h" |
15 #include "chrome/browser/tab_contents/tab_contents.h" | 16 #include "chrome/browser/tab_contents/tab_contents.h" |
16 #include "chrome/common/gfx/emf.h" | |
17 #include "chrome/common/notification_service.h" | 17 #include "chrome/common/notification_service.h" |
18 #include "chrome/common/render_messages.h" | 18 #include "chrome/common/render_messages.h" |
19 #include "grit/generated_resources.h" | 19 #include "grit/generated_resources.h" |
| 20 #include "printing/native_metafile.h" |
20 | 21 |
21 using base::TimeDelta; | 22 using base::TimeDelta; |
22 | 23 |
23 namespace printing { | 24 namespace printing { |
24 | 25 |
25 PrintViewManager::PrintViewManager(TabContents& owner) | 26 PrintViewManager::PrintViewManager(TabContents& owner) |
26 : owner_(owner), | 27 : owner_(owner), |
27 waiting_to_print_(false), | 28 waiting_to_print_(false), |
28 printing_succeeded_(false), | 29 printing_succeeded_(false), |
29 inside_inner_message_loop_(false) { | 30 inside_inner_message_loop_(false) { |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 // http://msdn2.microsoft.com/en-us/library/ms535522.aspx | 89 // http://msdn2.microsoft.com/en-us/library/ms535522.aspx |
89 // Windows 2000/XP: When a page in a spooled file exceeds approximately 350 | 90 // Windows 2000/XP: When a page in a spooled file exceeds approximately 350 |
90 // MB, it can fail to print and not send an error message. | 91 // MB, it can fail to print and not send an error message. |
91 if (params.data_size && params.data_size >= 350*1024*1024) { | 92 if (params.data_size && params.data_size >= 350*1024*1024) { |
92 NOTREACHED() << "size:" << params.data_size; | 93 NOTREACHED() << "size:" << params.data_size; |
93 TerminatePrintJob(true); | 94 TerminatePrintJob(true); |
94 owner_.Stop(); | 95 owner_.Stop(); |
95 return; | 96 return; |
96 } | 97 } |
97 | 98 |
98 base::SharedMemory shared_buf(params.emf_data_handle, true); | 99 base::SharedMemory shared_buf(params.metafile_data_handle, true); |
99 if (!shared_buf.Map(params.data_size)) { | 100 if (!shared_buf.Map(params.data_size)) { |
100 NOTREACHED() << "couldn't map"; | 101 NOTREACHED() << "couldn't map"; |
101 owner_.Stop(); | 102 owner_.Stop(); |
102 return; | 103 return; |
103 } | 104 } |
104 | 105 |
105 gfx::Emf* emf = new gfx::Emf; | 106 scoped_ptr<NativeMetafile> metafile(new NativeMetafile()); |
106 if (!emf->CreateFromData(shared_buf.memory(), params.data_size)) { | 107 if (!metafile->CreateFromData(shared_buf.memory(), params.data_size)) { |
107 NOTREACHED() << "Invalid EMF header"; | 108 NOTREACHED() << "Invalid metafile header"; |
108 delete emf; | |
109 owner_.Stop(); | 109 owner_.Stop(); |
110 return; | 110 return; |
111 } | 111 } |
112 | 112 |
113 // Update the rendered document. It will send notifications to the listener. | 113 // Update the rendered document. It will send notifications to the listener. |
114 document->SetPage(params.page_number, emf, params.actual_shrink); | 114 document->SetPage(params.page_number, |
| 115 metafile.release(), |
| 116 params.actual_shrink); |
115 ShouldQuitFromInnerMessageLoop(); | 117 ShouldQuitFromInnerMessageLoop(); |
116 } | 118 } |
117 | 119 |
118 std::wstring PrintViewManager::RenderSourceName() { | 120 std::wstring PrintViewManager::RenderSourceName() { |
119 std::wstring name(UTF16ToWideHack(owner_.GetTitle())); | 121 std::wstring name(UTF16ToWideHack(owner_.GetTitle())); |
120 if (name.empty()) | 122 if (name.empty()) |
121 name = l10n_util::GetString(IDS_DEFAULT_PRINT_DOCUMENT_TITLE); | 123 name = l10n_util::GetString(IDS_DEFAULT_PRINT_DOCUMENT_TITLE); |
122 return name; | 124 return name; |
123 } | 125 } |
124 | 126 |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 if (print_job_.get()) { | 296 if (print_job_.get()) { |
295 owner_.PrintingDone(print_job_->cookie(), success); | 297 owner_.PrintingDone(print_job_->cookie(), success); |
296 } | 298 } |
297 } | 299 } |
298 | 300 |
299 void PrintViewManager::TerminatePrintJob(bool cancel) { | 301 void PrintViewManager::TerminatePrintJob(bool cancel) { |
300 if (!print_job_.get()) | 302 if (!print_job_.get()) |
301 return; | 303 return; |
302 | 304 |
303 if (cancel) { | 305 if (cancel) { |
304 // We don't need the EMF data anymore because the printing is canceled. | 306 // We don't need the metafile data anymore because the printing is canceled. |
305 print_job_->Cancel(); | 307 print_job_->Cancel(); |
306 waiting_to_print_ = false; | 308 waiting_to_print_ = false; |
307 inside_inner_message_loop_ = false; | 309 inside_inner_message_loop_ = false; |
308 } else { | 310 } else { |
309 DCHECK(!inside_inner_message_loop_); | 311 DCHECK(!inside_inner_message_loop_); |
310 DCHECK(!print_job_->document() || print_job_->document()->IsComplete() || | 312 DCHECK(!print_job_->document() || print_job_->document()->IsComplete() || |
311 !waiting_to_print_); | 313 !waiting_to_print_); |
312 | 314 |
313 // TabContents is either dying or navigating elsewhere. We need to render | 315 // TabContents is either dying or navigating elsewhere. We need to render |
314 // all the pages in an hurry if a print job is still pending. This does the | 316 // all the pages in an hurry if a print job is still pending. This does the |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
403 return false; | 405 return false; |
404 } | 406 } |
405 | 407 |
406 // Settings are already loaded. Go ahead. This will set | 408 // Settings are already loaded. Go ahead. This will set |
407 // print_job_->is_job_pending() to true. | 409 // print_job_->is_job_pending() to true. |
408 print_job_->StartPrinting(); | 410 print_job_->StartPrinting(); |
409 return true; | 411 return true; |
410 } | 412 } |
411 | 413 |
412 } // namespace printing | 414 } // namespace printing |
OLD | NEW |