| 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" |
| 11 #include "chrome/browser/printing/print_job_manager.h" | 11 #include "chrome/browser/printing/print_job_manager.h" |
| 12 #include "chrome/browser/printing/print_preview_tab_controller.h" | 12 #include "chrome/browser/printing/print_preview_tab_controller.h" |
| 13 #include "chrome/browser/printing/printer_query.h" | 13 #include "chrome/browser/printing/printer_query.h" |
| 14 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" |
| 14 #include "chrome/browser/ui/webui/print_preview_ui.h" | 15 #include "chrome/browser/ui/webui/print_preview_ui.h" |
| 15 #include "chrome/common/print_messages.h" | 16 #include "chrome/common/print_messages.h" |
| 16 #include "content/browser/renderer_host/render_view_host.h" | 17 #include "content/browser/renderer_host/render_view_host.h" |
| 17 #include "content/browser/tab_contents/navigation_entry.h" | 18 #include "content/browser/tab_contents/navigation_entry.h" |
| 18 #include "content/browser/tab_contents/tab_contents.h" | 19 #include "content/browser/tab_contents/tab_contents.h" |
| 19 #include "content/common/notification_details.h" | 20 #include "content/common/notification_details.h" |
| 20 #include "content/common/notification_service.h" | 21 #include "content/common/notification_service.h" |
| 21 #include "content/common/notification_source.h" | 22 #include "content/common/notification_source.h" |
| 22 #include "grit/generated_resources.h" | 23 #include "grit/generated_resources.h" |
| 23 #include "printing/metafile.h" | 24 #include "printing/metafile.h" |
| 24 #include "printing/metafile_impl.h" | 25 #include "printing/metafile_impl.h" |
| 25 #include "printing/printed_document.h" | 26 #include "printing/printed_document.h" |
| 26 #include "ui/base/l10n/l10n_util.h" | 27 #include "ui/base/l10n/l10n_util.h" |
| 27 | 28 |
| 28 using base::TimeDelta; | 29 using base::TimeDelta; |
| 29 | 30 |
| 30 namespace { | 31 namespace { |
| 31 | 32 |
| 32 string16 GenerateRenderSourceName(TabContents* tab_contents) { | 33 string16 GenerateRenderSourceName(TabContents* tab_contents) { |
| 33 string16 name(tab_contents->GetTitle()); | 34 string16 name(tab_contents->GetTitle()); |
| 34 if (name.empty()) | 35 if (name.empty()) |
| 35 name = l10n_util::GetStringUTF16(IDS_DEFAULT_PRINT_DOCUMENT_TITLE); | 36 name = l10n_util::GetStringUTF16(IDS_DEFAULT_PRINT_DOCUMENT_TITLE); |
| 36 return name; | 37 return name; |
| 37 } | 38 } |
| 38 | 39 |
| 39 } // namespace | 40 } // namespace |
| 40 | 41 |
| 41 namespace printing { | 42 namespace printing { |
| 42 | 43 |
| 43 PrintViewManager::PrintViewManager(TabContents* tab_contents) | 44 PrintViewManager::PrintViewManager(TabContentsWrapper* tab) |
| 44 : TabContentsObserver(tab_contents), | 45 : TabContentsObserver(tab->tab_contents()), |
| 46 tab_(tab), |
| 45 number_pages_(0), | 47 number_pages_(0), |
| 46 printing_succeeded_(false), | 48 printing_succeeded_(false), |
| 47 inside_inner_message_loop_(false), | 49 inside_inner_message_loop_(false), |
| 48 is_title_overridden_(false) { | 50 is_title_overridden_(false) { |
| 49 #if defined(OS_POSIX) && !defined(OS_MACOSX) | 51 #if defined(OS_POSIX) && !defined(OS_MACOSX) |
| 50 expecting_first_page_ = true; | 52 expecting_first_page_ = true; |
| 51 #endif | 53 #endif |
| 52 } | 54 } |
| 53 | 55 |
| 54 PrintViewManager::~PrintViewManager() { | 56 PrintViewManager::~PrintViewManager() { |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 219 } | 221 } |
| 220 | 222 |
| 221 void PrintViewManager::OnNotifyPrintJobEvent( | 223 void PrintViewManager::OnNotifyPrintJobEvent( |
| 222 const JobEventDetails& event_details) { | 224 const JobEventDetails& event_details) { |
| 223 switch (event_details.type()) { | 225 switch (event_details.type()) { |
| 224 case JobEventDetails::FAILED: { | 226 case JobEventDetails::FAILED: { |
| 225 TerminatePrintJob(true); | 227 TerminatePrintJob(true); |
| 226 | 228 |
| 227 NotificationService::current()->Notify( | 229 NotificationService::current()->Notify( |
| 228 NotificationType::PRINT_JOB_RELEASED, | 230 NotificationType::PRINT_JOB_RELEASED, |
| 229 Source<TabContents>(tab_contents()), | 231 Source<TabContentsWrapper>(tab_), |
| 230 NotificationService::NoDetails()); | 232 NotificationService::NoDetails()); |
| 231 break; | 233 break; |
| 232 } | 234 } |
| 233 case JobEventDetails::USER_INIT_DONE: | 235 case JobEventDetails::USER_INIT_DONE: |
| 234 case JobEventDetails::DEFAULT_INIT_DONE: | 236 case JobEventDetails::DEFAULT_INIT_DONE: |
| 235 case JobEventDetails::USER_INIT_CANCELED: { | 237 case JobEventDetails::USER_INIT_CANCELED: { |
| 236 NOTREACHED(); | 238 NOTREACHED(); |
| 237 break; | 239 break; |
| 238 } | 240 } |
| 239 case JobEventDetails::ALL_PAGES_REQUESTED: { | 241 case JobEventDetails::ALL_PAGES_REQUESTED: { |
| 240 ShouldQuitFromInnerMessageLoop(); | 242 ShouldQuitFromInnerMessageLoop(); |
| 241 break; | 243 break; |
| 242 } | 244 } |
| 243 case JobEventDetails::NEW_DOC: | 245 case JobEventDetails::NEW_DOC: |
| 244 case JobEventDetails::NEW_PAGE: | 246 case JobEventDetails::NEW_PAGE: |
| 245 case JobEventDetails::PAGE_DONE: | 247 case JobEventDetails::PAGE_DONE: |
| 246 case JobEventDetails::DOC_DONE: { | 248 case JobEventDetails::DOC_DONE: { |
| 247 // Don't care about the actual printing process. | 249 // Don't care about the actual printing process. |
| 248 break; | 250 break; |
| 249 } | 251 } |
| 250 case JobEventDetails::JOB_DONE: { | 252 case JobEventDetails::JOB_DONE: { |
| 251 // Printing is done, we don't need it anymore. | 253 // Printing is done, we don't need it anymore. |
| 252 // print_job_->is_job_pending() may still be true, depending on the order | 254 // print_job_->is_job_pending() may still be true, depending on the order |
| 253 // of object registration. | 255 // of object registration. |
| 254 printing_succeeded_ = true; | 256 printing_succeeded_ = true; |
| 255 ReleasePrintJob(); | 257 ReleasePrintJob(); |
| 256 | 258 |
| 257 NotificationService::current()->Notify( | 259 NotificationService::current()->Notify( |
| 258 NotificationType::PRINT_JOB_RELEASED, | 260 NotificationType::PRINT_JOB_RELEASED, |
| 259 Source<TabContents>(tab_contents()), | 261 Source<TabContentsWrapper>(tab_), |
| 260 NotificationService::NoDetails()); | 262 NotificationService::NoDetails()); |
| 261 break; | 263 break; |
| 262 } | 264 } |
| 263 default: { | 265 default: { |
| 264 NOTREACHED(); | 266 NOTREACHED(); |
| 265 break; | 267 break; |
| 266 } | 268 } |
| 267 } | 269 } |
| 268 } | 270 } |
| 269 | 271 |
| (...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 464 return false; | 466 return false; |
| 465 } | 467 } |
| 466 | 468 |
| 467 // Settings are already loaded. Go ahead. This will set | 469 // Settings are already loaded. Go ahead. This will set |
| 468 // print_job_->is_job_pending() to true. | 470 // print_job_->is_job_pending() to true. |
| 469 print_job_->StartPrinting(); | 471 print_job_->StartPrinting(); |
| 470 return true; | 472 return true; |
| 471 } | 473 } |
| 472 | 474 |
| 473 } // namespace printing | 475 } // namespace printing |
| OLD | NEW |