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()) { |
stuartmorgan
2011/03/30 22:59:17
This is where some of that discussion should go. I
| |
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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
147 params.page_size, | 154 params.page_size, |
148 params.content_area, | 155 params.content_area, |
149 params.has_visible_overlays); | 156 params.has_visible_overlays); |
150 | 157 |
151 ShouldQuitFromInnerMessageLoop(); | 158 ShouldQuitFromInnerMessageLoop(); |
152 } | 159 } |
153 | 160 |
154 bool PrintViewManager::OnMessageReceived(const IPC::Message& message) { | 161 bool PrintViewManager::OnMessageReceived(const IPC::Message& message) { |
155 bool handled = true; | 162 bool handled = true; |
156 IPC_BEGIN_MESSAGE_MAP(PrintViewManager, message) | 163 IPC_BEGIN_MESSAGE_MAP(PrintViewManager, message) |
157 IPC_MESSAGE_HANDLER(PrintHostMsg_DidGetPrintedPagesCount, | 164 IPC_MESSAGE_HANDLER(PrintHostMsg_DidGetBasicPrintJobInfo, |
158 OnDidGetPrintedPagesCount) | 165 OnDidGetBasicPrintJobInfo) |
159 IPC_MESSAGE_HANDLER(PrintHostMsg_DidPrintPage, OnDidPrintPage) | 166 IPC_MESSAGE_HANDLER(PrintHostMsg_DidPrintPage, OnDidPrintPage) |
160 IPC_MESSAGE_UNHANDLED(handled = false) | 167 IPC_MESSAGE_UNHANDLED(handled = false) |
161 IPC_END_MESSAGE_MAP() | 168 IPC_END_MESSAGE_MAP() |
162 return handled; | 169 return handled; |
163 } | 170 } |
164 | 171 |
165 void PrintViewManager::Observe(NotificationType type, | 172 void PrintViewManager::Observe(NotificationType type, |
166 const NotificationSource& source, | 173 const NotificationSource& source, |
167 const NotificationDetails& details) { | 174 const NotificationDetails& details) { |
168 switch (type.value) { | 175 switch (type.value) { |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
428 return false; | 435 return false; |
429 } | 436 } |
430 | 437 |
431 // Settings are already loaded. Go ahead. This will set | 438 // Settings are already loaded. Go ahead. This will set |
432 // print_job_->is_job_pending() to true. | 439 // print_job_->is_job_pending() to true. |
433 print_job_->StartPrinting(); | 440 print_job_->StartPrinting(); |
434 return true; | 441 return true; |
435 } | 442 } |
436 | 443 |
437 } // namespace printing | 444 } // namespace printing |
OLD | NEW |