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/browser/printing/print_view_manager.h" | 5 #include "chrome/browser/printing/print_view_manager.h" |
6 | 6 |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/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" |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 scoped_refptr<PrintedDocument> document(print_job_->document()); | 53 scoped_refptr<PrintedDocument> document(print_job_->document()); |
54 if (document) { | 54 if (document) { |
55 // If IsComplete() returns false, the document isn't completely rendered. | 55 // If IsComplete() returns false, the document isn't completely rendered. |
56 // Since our renderer is gone, there's nothing to do, cancel it. Otherwise, | 56 // Since our renderer is gone, there's nothing to do, cancel it. Otherwise, |
57 // the print job may finish without problem. | 57 // the print job may finish without problem. |
58 TerminatePrintJob(!document->IsComplete()); | 58 TerminatePrintJob(!document->IsComplete()); |
59 } | 59 } |
60 } | 60 } |
61 | 61 |
62 string16 PrintViewManager::RenderSourceName() { | 62 string16 PrintViewManager::RenderSourceName() { |
63 string16 name(tab_contents()->GetTitle()); | 63 if (job_title_.empty()) { |
64 if (name.empty()) | 64 string16 name(tab_contents()->GetTitle()); |
65 name = l10n_util::GetStringUTF16(IDS_DEFAULT_PRINT_DOCUMENT_TITLE); | 65 if (name.empty()) |
66 return name; | 66 job_title_ = l10n_util::GetStringUTF16(IDS_DEFAULT_PRINT_DOCUMENT_TITLE); |
| 67 else |
| 68 job_title_ = name; |
| 69 } |
| 70 return job_title_; |
67 } | 71 } |
68 | 72 |
69 GURL PrintViewManager::RenderSourceUrl() { | 73 GURL PrintViewManager::RenderSourceUrl() { |
70 NavigationEntry* entry = tab_contents()->controller().GetActiveEntry(); | 74 NavigationEntry* entry = tab_contents()->controller().GetActiveEntry(); |
71 if (entry) | 75 if (entry) |
72 return entry->virtual_url(); | 76 return entry->virtual_url(); |
73 else | 77 else |
74 return GURL(); | 78 return GURL(); |
75 } | 79 } |
76 | 80 |
77 void PrintViewManager::OnDidGetPrintedPagesCount(int cookie, int number_pages) { | 81 void PrintViewManager::OnDidGetBasicPrintJobInfo( |
| 82 int cookie, int number_pages, const string16& job_title) { |
78 DCHECK_GT(cookie, 0); | 83 DCHECK_GT(cookie, 0); |
79 DCHECK_GT(number_pages, 0); | 84 DCHECK_GT(number_pages, 0); |
80 number_pages_ = number_pages; | 85 number_pages_ = number_pages; |
| 86 job_title_ = job_title; |
| 87 |
81 if (!OpportunisticallyCreatePrintJob(cookie)) | 88 if (!OpportunisticallyCreatePrintJob(cookie)) |
82 return; | 89 return; |
83 | 90 |
84 PrintedDocument* document = print_job_->document(); | 91 PrintedDocument* document = print_job_->document(); |
85 if (!document || cookie != document->cookie()) { | 92 if (!document || cookie != document->cookie()) { |
86 // Out of sync. It may happens since we are completely asynchronous. Old | 93 // Out of sync. It may happens since we are completely asynchronous. Old |
87 // spurious message can happen if one of the processes is overloaded. | 94 // spurious message can happen if one of the processes is overloaded. |
88 return; | 95 return; |
89 } | 96 } |
90 } | 97 } |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 params.page_size, | 152 params.page_size, |
146 params.content_area, | 153 params.content_area, |
147 params.has_visible_overlays); | 154 params.has_visible_overlays); |
148 | 155 |
149 ShouldQuitFromInnerMessageLoop(); | 156 ShouldQuitFromInnerMessageLoop(); |
150 } | 157 } |
151 | 158 |
152 bool PrintViewManager::OnMessageReceived(const IPC::Message& message) { | 159 bool PrintViewManager::OnMessageReceived(const IPC::Message& message) { |
153 bool handled = true; | 160 bool handled = true; |
154 IPC_BEGIN_MESSAGE_MAP(PrintViewManager, message) | 161 IPC_BEGIN_MESSAGE_MAP(PrintViewManager, message) |
155 IPC_MESSAGE_HANDLER(PrintHostMsg_DidGetPrintedPagesCount, | 162 IPC_MESSAGE_HANDLER(PrintHostMsg_DidGetBasicPrintJobInfo, |
156 OnDidGetPrintedPagesCount) | 163 OnDidGetBasicPrintJobInfo) |
157 IPC_MESSAGE_HANDLER(PrintHostMsg_DidPrintPage, OnDidPrintPage) | 164 IPC_MESSAGE_HANDLER(PrintHostMsg_DidPrintPage, OnDidPrintPage) |
158 IPC_MESSAGE_UNHANDLED(handled = false) | 165 IPC_MESSAGE_UNHANDLED(handled = false) |
159 IPC_END_MESSAGE_MAP() | 166 IPC_END_MESSAGE_MAP() |
160 return handled; | 167 return handled; |
161 } | 168 } |
162 | 169 |
163 void PrintViewManager::Observe(NotificationType type, | 170 void PrintViewManager::Observe(NotificationType type, |
164 const NotificationSource& source, | 171 const NotificationSource& source, |
165 const NotificationDetails& details) { | 172 const NotificationDetails& details) { |
166 switch (type.value) { | 173 switch (type.value) { |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
426 return false; | 433 return false; |
427 } | 434 } |
428 | 435 |
429 // Settings are already loaded. Go ahead. This will set | 436 // Settings are already loaded. Go ahead. This will set |
430 // print_job_->is_job_pending() to true. | 437 // print_job_->is_job_pending() to true. |
431 print_job_->StartPrinting(); | 438 print_job_->StartPrinting(); |
432 return true; | 439 return true; |
433 } | 440 } |
434 | 441 |
435 } // namespace printing | 442 } // namespace printing |
OLD | NEW |