| 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 "chrome/browser/browser_process.h" | 7 #include "chrome/browser/browser_process.h" |
| 8 #include "chrome/browser/printing/print_job.h" | 8 #include "chrome/browser/printing/print_job.h" |
| 9 #include "chrome/browser/printing/print_job_manager.h" | 9 #include "chrome/browser/printing/print_job_manager.h" |
| 10 #include "chrome/browser/printing/printed_document.h" | 10 #include "chrome/browser/printing/printed_document.h" |
| 11 #include "chrome/browser/printing/printer_query.h" | 11 #include "chrome/browser/printing/printer_query.h" |
| 12 #include "chrome/browser/renderer_host/render_view_host.h" | 12 #include "chrome/browser/renderer_host/render_view_host.h" |
| 13 #include "chrome/browser/tab_contents/navigation_entry.h" | 13 #include "chrome/browser/tab_contents/navigation_entry.h" |
| 14 #include "chrome/browser/tab_contents/web_contents.h" | 14 #include "chrome/browser/tab_contents/web_contents.h" |
| 15 #include "chrome/common/gfx/emf.h" | 15 #include "chrome/common/gfx/emf.h" |
| 16 #include "chrome/common/l10n_util.h" | 16 #include "chrome/common/l10n_util.h" |
| 17 #include "chrome/common/notification_service.h" | 17 #include "chrome/common/notification_service.h" |
| 18 | 18 |
| 19 #include "generated_resources.h" | 19 #include "generated_resources.h" |
| 20 | 20 |
| 21 using base::TimeDelta; | 21 using base::TimeDelta; |
| 22 | 22 |
| 23 namespace printing { | 23 namespace printing { |
| 24 | 24 |
| 25 PrintViewManager::PrintViewManager(WebContents& owner) | 25 PrintViewManager::PrintViewManager(WebContents& owner) |
| 26 : owner_(owner), | 26 : owner_(owner), |
| 27 waiting_to_print_(false), | 27 waiting_to_print_(false), |
| 28 inside_inner_message_loop_(false), | 28 inside_inner_message_loop_(false), |
| 29 waiting_to_show_print_dialog_(false) { | 29 waiting_to_show_print_dialog_(false) { |
| 30 memset(&print_params_, 0, sizeof(print_params_)); |
| 30 } | 31 } |
| 31 | 32 |
| 32 PrintViewManager::~PrintViewManager() { | 33 PrintViewManager::~PrintViewManager() { |
| 33 } | 34 } |
| 34 | 35 |
| 35 void PrintViewManager::Destroy() { | 36 void PrintViewManager::Destroy() { |
| 36 DisconnectFromCurrentPrintJob(); | 37 DisconnectFromCurrentPrintJob(); |
| 37 } | 38 } |
| 38 | 39 |
| 39 void PrintViewManager::Stop() { | 40 void PrintViewManager::Stop() { |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 } | 233 } |
| 233 default: { | 234 default: { |
| 234 NOTREACHED(); | 235 NOTREACHED(); |
| 235 break; | 236 break; |
| 236 } | 237 } |
| 237 } | 238 } |
| 238 } | 239 } |
| 239 | 240 |
| 240 void PrintViewManager::OnNotifyPrintJobInitEvent( | 241 void PrintViewManager::OnNotifyPrintJobInitEvent( |
| 241 const JobEventDetails& event_details) { | 242 const JobEventDetails& event_details) { |
| 243 ViewMsg_Print_Params old_print_params(print_params_); |
| 244 |
| 245 // Backup the print settings relevant to the renderer. |
| 246 DCHECK_EQ(print_job_->document(), event_details.document()); |
| 247 event_details.document()->settings().RenderParams(&print_params_); |
| 248 print_params_.document_cookie = event_details.document()->cookie(); |
| 249 DCHECK_GT(print_params_.document_cookie, 0); |
| 250 |
| 251 // If settings changed |
| 252 DCHECK(owner_.render_view_host()); |
| 253 // Equals() doesn't compare the cookie value. |
| 254 if (owner_.render_view_host() && |
| 255 owner_.render_view_host()->IsRenderViewLive() && |
| 256 (!old_print_params.Equals(print_params_) || |
| 257 !event_details.document()->page_count())) { |
| 258 // TODO(maruel): Will never happen, this code is about to be deleted. |
| 259 NOTREACHED(); |
| 260 } |
| 261 |
| 242 // Continue even if owner_.render_view_host() is dead because we may already | 262 // Continue even if owner_.render_view_host() is dead because we may already |
| 243 // have buffered all the necessary pages. | 263 // have buffered all the necessary pages. |
| 244 switch (event_details.type()) { | 264 switch (event_details.type()) { |
| 245 case JobEventDetails::USER_INIT_DONE: { | 265 case JobEventDetails::USER_INIT_DONE: { |
| 246 // The user clicked the "Print" button in the Print... dialog. | 266 // The user clicked the "Print" button in the Print... dialog. |
| 247 // Time to print. | 267 // Time to print. |
| 248 DCHECK_EQ(waiting_to_print_, false); | 268 DCHECK_EQ(waiting_to_print_, false); |
| 249 DCHECK_EQ(waiting_to_show_print_dialog_, false); | 269 DCHECK_EQ(waiting_to_show_print_dialog_, false); |
| 250 waiting_to_print_ = true; | 270 waiting_to_print_ = true; |
| 251 PrintNowInternal(); | 271 PrintNowInternal(); |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 433 if (!print_job_.get()) | 453 if (!print_job_.get()) |
| 434 return; | 454 return; |
| 435 NotificationService::current()->RemoveObserver( | 455 NotificationService::current()->RemoveObserver( |
| 436 this, | 456 this, |
| 437 NotificationType::PRINT_JOB_EVENT, | 457 NotificationType::PRINT_JOB_EVENT, |
| 438 Source<PrintJob>(print_job_.get())); | 458 Source<PrintJob>(print_job_.get())); |
| 439 | 459 |
| 440 print_job_->DisconnectSource(); | 460 print_job_->DisconnectSource(); |
| 441 // Don't close the worker thread. | 461 // Don't close the worker thread. |
| 442 print_job_ = NULL; | 462 print_job_ = NULL; |
| 463 memset(&print_params_, 0, sizeof(print_params_)); |
| 443 } | 464 } |
| 444 | 465 |
| 445 void PrintViewManager::PrintNowInternal() { | 466 void PrintViewManager::PrintNowInternal() { |
| 446 DCHECK(waiting_to_print_); | 467 DCHECK(waiting_to_print_); |
| 447 | 468 |
| 448 // Settings are already loaded. Go ahead. This will set | 469 // Settings are already loaded. Go ahead. This will set |
| 449 // print_job_->is_job_pending() to true. | 470 // print_job_->is_job_pending() to true. |
| 450 print_job_->StartPrinting(); | 471 print_job_->StartPrinting(); |
| 451 | 472 |
| 452 if (!print_job_->document() || | 473 if (!print_job_->document() || |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 517 } | 538 } |
| 518 | 539 |
| 519 // Settings are already loaded. Go ahead. This will set | 540 // Settings are already loaded. Go ahead. This will set |
| 520 // print_job_->is_job_pending() to true. | 541 // print_job_->is_job_pending() to true. |
| 521 print_job_->StartPrinting(); | 542 print_job_->StartPrinting(); |
| 522 return true; | 543 return true; |
| 523 } | 544 } |
| 524 | 545 |
| 525 } // namespace printing | 546 } // namespace printing |
| 526 | 547 |
| OLD | NEW |