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 "base/scoped_ptr.h" | 7 #include "base/scoped_ptr.h" |
8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.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_details.h" | 16 #include "chrome/common/notification_details.h" |
17 #include "chrome/common/notification_source.h" | 17 #include "chrome/common/notification_source.h" |
| 18 #include "chrome/common/render_messages.h" |
18 #include "chrome/common/render_messages_params.h" | 19 #include "chrome/common/render_messages_params.h" |
19 #include "grit/generated_resources.h" | 20 #include "grit/generated_resources.h" |
20 #include "printing/native_metafile.h" | 21 #include "printing/native_metafile.h" |
21 #include "printing/printed_document.h" | 22 #include "printing/printed_document.h" |
22 #include "ui/base/l10n/l10n_util.h" | 23 #include "ui/base/l10n/l10n_util.h" |
23 | 24 |
24 using base::TimeDelta; | 25 using base::TimeDelta; |
25 | 26 |
26 namespace printing { | 27 namespace printing { |
27 | 28 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 } | 67 } |
67 | 68 |
68 GURL PrintViewManager::RenderSourceUrl() { | 69 GURL PrintViewManager::RenderSourceUrl() { |
69 NavigationEntry* entry = owner_.controller().GetActiveEntry(); | 70 NavigationEntry* entry = owner_.controller().GetActiveEntry(); |
70 if (entry) | 71 if (entry) |
71 return entry->virtual_url(); | 72 return entry->virtual_url(); |
72 else | 73 else |
73 return GURL(); | 74 return GURL(); |
74 } | 75 } |
75 | 76 |
76 void PrintViewManager::DidGetPrintedPagesCount(int cookie, int number_pages) { | 77 void PrintViewManager::OnDidGetPrintedPagesCount(int cookie, int number_pages) { |
77 DCHECK_GT(cookie, 0); | 78 DCHECK_GT(cookie, 0); |
78 if (!OpportunisticallyCreatePrintJob(cookie)) | 79 if (!OpportunisticallyCreatePrintJob(cookie)) |
79 return; | 80 return; |
80 | 81 |
81 PrintedDocument* document = print_job_->document(); | 82 PrintedDocument* document = print_job_->document(); |
82 if (!document || cookie != document->cookie()) { | 83 if (!document || cookie != document->cookie()) { |
83 // Out of sync. It may happens since we are completely asynchronous. Old | 84 // Out of sync. It may happens since we are completely asynchronous. Old |
84 // spurious message can happen if one of the processes is overloaded. | 85 // spurious message can happen if one of the processes is overloaded. |
85 return; | 86 return; |
86 } | 87 } |
87 | 88 |
88 // Time to inform our print job. Make sure it is for the right document. | 89 // Time to inform our print job. Make sure it is for the right document. |
89 if (!document->page_count()) { | 90 if (!document->page_count()) { |
90 document->set_page_count(number_pages); | 91 document->set_page_count(number_pages); |
91 } | 92 } |
92 } | 93 } |
93 | 94 |
94 void PrintViewManager::DidPrintPage( | 95 void PrintViewManager::OnDidPrintPage( |
95 const ViewHostMsg_DidPrintPage_Params& params) { | 96 const ViewHostMsg_DidPrintPage_Params& params) { |
96 if (!OpportunisticallyCreatePrintJob(params.document_cookie)) | 97 if (!OpportunisticallyCreatePrintJob(params.document_cookie)) |
97 return; | 98 return; |
98 | 99 |
99 PrintedDocument* document = print_job_->document(); | 100 PrintedDocument* document = print_job_->document(); |
100 if (!document || params.document_cookie != document->cookie()) { | 101 if (!document || params.document_cookie != document->cookie()) { |
101 // Out of sync. It may happen since we are completely asynchronous. Old | 102 // Out of sync. It may happen since we are completely asynchronous. Old |
102 // spurious messages can be received if one of the processes is overloaded. | 103 // spurious messages can be received if one of the processes is overloaded. |
103 return; | 104 return; |
104 } | 105 } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
136 document->SetPage(params.page_number, | 137 document->SetPage(params.page_number, |
137 metafile.release(), | 138 metafile.release(), |
138 params.actual_shrink, | 139 params.actual_shrink, |
139 params.page_size, | 140 params.page_size, |
140 params.content_area, | 141 params.content_area, |
141 params.has_visible_overlays); | 142 params.has_visible_overlays); |
142 #endif | 143 #endif |
143 ShouldQuitFromInnerMessageLoop(); | 144 ShouldQuitFromInnerMessageLoop(); |
144 } | 145 } |
145 | 146 |
| 147 bool PrintViewManager::OnMessageReceived(const IPC::Message& message) { |
| 148 bool handled = true; |
| 149 IPC_BEGIN_MESSAGE_MAP(PrintViewManager, message) |
| 150 IPC_MESSAGE_HANDLER(ViewHostMsg_DidGetPrintedPagesCount, |
| 151 OnDidGetPrintedPagesCount) |
| 152 IPC_MESSAGE_HANDLER(ViewHostMsg_DidPrintPage, OnDidPrintPage) |
| 153 IPC_MESSAGE_UNHANDLED(handled = false) |
| 154 IPC_END_MESSAGE_MAP() |
| 155 return handled; |
| 156 } |
| 157 |
146 void PrintViewManager::Observe(NotificationType type, | 158 void PrintViewManager::Observe(NotificationType type, |
147 const NotificationSource& source, | 159 const NotificationSource& source, |
148 const NotificationDetails& details) { | 160 const NotificationDetails& details) { |
149 switch (type.value) { | 161 switch (type.value) { |
150 case NotificationType::PRINT_JOB_EVENT: { | 162 case NotificationType::PRINT_JOB_EVENT: { |
151 OnNotifyPrintJobEvent(*Details<JobEventDetails>(details).ptr()); | 163 OnNotifyPrintJobEvent(*Details<JobEventDetails>(details).ptr()); |
152 break; | 164 break; |
153 } | 165 } |
154 default: { | 166 default: { |
155 NOTREACHED(); | 167 NOTREACHED(); |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
405 return false; | 417 return false; |
406 } | 418 } |
407 | 419 |
408 // Settings are already loaded. Go ahead. This will set | 420 // Settings are already loaded. Go ahead. This will set |
409 // print_job_->is_job_pending() to true. | 421 // print_job_->is_job_pending() to true. |
410 print_job_->StartPrinting(); | 422 print_job_->StartPrinting(); |
411 return true; | 423 return true; |
412 } | 424 } |
413 | 425 |
414 } // namespace printing | 426 } // namespace printing |
OLD | NEW |