| 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_END_MESSAGE_MAP() |
| 154 return handled; |
| 155 } |
| 156 |
| 146 void PrintViewManager::Observe(NotificationType type, | 157 void PrintViewManager::Observe(NotificationType type, |
| 147 const NotificationSource& source, | 158 const NotificationSource& source, |
| 148 const NotificationDetails& details) { | 159 const NotificationDetails& details) { |
| 149 switch (type.value) { | 160 switch (type.value) { |
| 150 case NotificationType::PRINT_JOB_EVENT: { | 161 case NotificationType::PRINT_JOB_EVENT: { |
| 151 OnNotifyPrintJobEvent(*Details<JobEventDetails>(details).ptr()); | 162 OnNotifyPrintJobEvent(*Details<JobEventDetails>(details).ptr()); |
| 152 break; | 163 break; |
| 153 } | 164 } |
| 154 default: { | 165 default: { |
| 155 NOTREACHED(); | 166 NOTREACHED(); |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 405 return false; | 416 return false; |
| 406 } | 417 } |
| 407 | 418 |
| 408 // Settings are already loaded. Go ahead. This will set | 419 // Settings are already loaded. Go ahead. This will set |
| 409 // print_job_->is_job_pending() to true. | 420 // print_job_->is_job_pending() to true. |
| 410 print_job_->StartPrinting(); | 421 print_job_->StartPrinting(); |
| 411 return true; | 422 return true; |
| 412 } | 423 } |
| 413 | 424 |
| 414 } // namespace printing | 425 } // namespace printing |
| OLD | NEW |