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 "base/scoped_ptr.h" |
9 #include "chrome/browser/browser_process.h" | 9 #include "chrome/browser/browser_process.h" |
10 #include "chrome/browser/printing/print_job.h" | 10 #include "chrome/browser/printing/print_job.h" |
11 #include "chrome/browser/printing/print_job_manager.h" | 11 #include "chrome/browser/printing/print_job_manager.h" |
12 #include "chrome/browser/printing/printer_query.h" | 12 #include "chrome/browser/printing/printer_query.h" |
13 #include "chrome/browser/renderer_host/render_view_host.h" | 13 #include "chrome/browser/renderer_host/render_view_host.h" |
14 #include "chrome/browser/tab_contents/navigation_entry.h" | 14 #include "chrome/browser/tab_contents/navigation_entry.h" |
15 #include "chrome/browser/tab_contents/tab_contents.h" | 15 #include "chrome/browser/tab_contents/tab_contents.h" |
16 #include "chrome/common/notification_service.h" | 16 #include "chrome/common/notification_service.h" |
17 #include "chrome/common/render_messages.h" | 17 #include "chrome/common/render_messages.h" |
18 #include "grit/generated_resources.h" | 18 #include "grit/generated_resources.h" |
19 #include "printing/native_metafile.h" | 19 #include "printing/native_metafile.h" |
20 #include "printing/printed_document.h" | 20 #include "printing/printed_document.h" |
21 | 21 |
22 using base::TimeDelta; | 22 using base::TimeDelta; |
23 | 23 |
24 namespace printing { | 24 namespace printing { |
25 | 25 |
26 PrintViewManager::PrintViewManager(TabContents& owner) | 26 PrintViewManager::PrintViewManager(TabContents& owner) |
27 : owner_(owner), | 27 : waiting_to_print_(false), |
28 waiting_to_print_(false), | |
29 printing_succeeded_(false), | 28 printing_succeeded_(false), |
30 inside_inner_message_loop_(false) { | 29 inside_inner_message_loop_(false), |
| 30 owner_(owner) { |
31 } | 31 } |
32 | 32 |
33 PrintViewManager::~PrintViewManager() { | 33 PrintViewManager::~PrintViewManager() { |
34 DisconnectFromCurrentPrintJob(); | 34 DisconnectFromCurrentPrintJob(); |
35 } | 35 } |
36 | 36 |
37 void PrintViewManager::Stop() { | 37 void PrintViewManager::Stop() { |
38 // Cancel the current job, wait for the worker to finish. | 38 // Cancel the current job, wait for the worker to finish. |
39 TerminatePrintJob(true); | 39 TerminatePrintJob(true); |
40 } | 40 } |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
94 if (!OpportunisticallyCreatePrintJob(params.document_cookie)) | 94 if (!OpportunisticallyCreatePrintJob(params.document_cookie)) |
95 return; | 95 return; |
96 | 96 |
97 PrintedDocument* document = print_job_->document(); | 97 PrintedDocument* document = print_job_->document(); |
98 if (!document || params.document_cookie != document->cookie()) { | 98 if (!document || params.document_cookie != document->cookie()) { |
99 // Out of sync. It may happen since we are completely asynchronous. Old | 99 // Out of sync. It may happen since we are completely asynchronous. Old |
100 // spurious messages can be received if one of the processes is overloaded. | 100 // spurious messages can be received if one of the processes is overloaded. |
101 return; | 101 return; |
102 } | 102 } |
103 | 103 |
| 104 #if defined(OS_WIN) |
104 // http://msdn2.microsoft.com/en-us/library/ms535522.aspx | 105 // http://msdn2.microsoft.com/en-us/library/ms535522.aspx |
105 // Windows 2000/XP: When a page in a spooled file exceeds approximately 350 | 106 // Windows 2000/XP: When a page in a spooled file exceeds approximately 350 |
106 // MB, it can fail to print and not send an error message. | 107 // MB, it can fail to print and not send an error message. |
107 if (params.data_size && params.data_size >= 350*1024*1024) { | 108 if (params.data_size && params.data_size >= 350*1024*1024) { |
108 NOTREACHED() << "size:" << params.data_size; | 109 NOTREACHED() << "size:" << params.data_size; |
109 TerminatePrintJob(true); | 110 TerminatePrintJob(true); |
110 owner_.Stop(); | 111 owner_.Stop(); |
111 return; | 112 return; |
112 } | 113 } |
| 114 #endif |
113 | 115 |
114 base::SharedMemory shared_buf(params.metafile_data_handle, true); | 116 base::SharedMemory shared_buf(params.metafile_data_handle, true); |
115 if (!shared_buf.Map(params.data_size)) { | 117 if (!shared_buf.Map(params.data_size)) { |
116 NOTREACHED() << "couldn't map"; | 118 NOTREACHED() << "couldn't map"; |
117 owner_.Stop(); | 119 owner_.Stop(); |
118 return; | 120 return; |
119 } | 121 } |
120 | 122 |
121 scoped_ptr<NativeMetafile> metafile(new NativeMetafile()); | 123 scoped_ptr<NativeMetafile> metafile(new NativeMetafile()); |
122 if (!metafile->CreateFromData(shared_buf.memory(), params.data_size)) { | 124 if (!metafile->CreateFromData(shared_buf.memory(), params.data_size)) { |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
405 return false; | 407 return false; |
406 } | 408 } |
407 | 409 |
408 // Settings are already loaded. Go ahead. This will set | 410 // Settings are already loaded. Go ahead. This will set |
409 // print_job_->is_job_pending() to true. | 411 // print_job_->is_job_pending() to true. |
410 print_job_->StartPrinting(); | 412 print_job_->StartPrinting(); |
411 return true; | 413 return true; |
412 } | 414 } |
413 | 415 |
414 } // namespace printing | 416 } // namespace printing |
OLD | NEW |