| 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_)); | |
| 31 } | 30 } |
| 32 | 31 |
| 33 PrintViewManager::~PrintViewManager() { | 32 PrintViewManager::~PrintViewManager() { |
| 34 } | 33 } |
| 35 | 34 |
| 36 void PrintViewManager::Destroy() { | 35 void PrintViewManager::Destroy() { |
| 37 DisconnectFromCurrentPrintJob(); | 36 DisconnectFromCurrentPrintJob(); |
| 38 } | 37 } |
| 39 | 38 |
| 40 void PrintViewManager::Stop() { | 39 void PrintViewManager::Stop() { |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 } | 232 } |
| 234 default: { | 233 default: { |
| 235 NOTREACHED(); | 234 NOTREACHED(); |
| 236 break; | 235 break; |
| 237 } | 236 } |
| 238 } | 237 } |
| 239 } | 238 } |
| 240 | 239 |
| 241 void PrintViewManager::OnNotifyPrintJobInitEvent( | 240 void PrintViewManager::OnNotifyPrintJobInitEvent( |
| 242 const JobEventDetails& event_details) { | 241 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 | |
| 262 // Continue even if owner_.render_view_host() is dead because we may already | 242 // Continue even if owner_.render_view_host() is dead because we may already |
| 263 // have buffered all the necessary pages. | 243 // have buffered all the necessary pages. |
| 264 switch (event_details.type()) { | 244 switch (event_details.type()) { |
| 265 case JobEventDetails::USER_INIT_DONE: { | 245 case JobEventDetails::USER_INIT_DONE: { |
| 266 // The user clicked the "Print" button in the Print... dialog. | 246 // The user clicked the "Print" button in the Print... dialog. |
| 267 // Time to print. | 247 // Time to print. |
| 268 DCHECK_EQ(waiting_to_print_, false); | 248 DCHECK_EQ(waiting_to_print_, false); |
| 269 DCHECK_EQ(waiting_to_show_print_dialog_, false); | 249 DCHECK_EQ(waiting_to_show_print_dialog_, false); |
| 270 waiting_to_print_ = true; | 250 waiting_to_print_ = true; |
| 271 PrintNowInternal(); | 251 PrintNowInternal(); |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 453 if (!print_job_.get()) | 433 if (!print_job_.get()) |
| 454 return; | 434 return; |
| 455 NotificationService::current()->RemoveObserver( | 435 NotificationService::current()->RemoveObserver( |
| 456 this, | 436 this, |
| 457 NotificationType::PRINT_JOB_EVENT, | 437 NotificationType::PRINT_JOB_EVENT, |
| 458 Source<PrintJob>(print_job_.get())); | 438 Source<PrintJob>(print_job_.get())); |
| 459 | 439 |
| 460 print_job_->DisconnectSource(); | 440 print_job_->DisconnectSource(); |
| 461 // Don't close the worker thread. | 441 // Don't close the worker thread. |
| 462 print_job_ = NULL; | 442 print_job_ = NULL; |
| 463 memset(&print_params_, 0, sizeof(print_params_)); | |
| 464 } | 443 } |
| 465 | 444 |
| 466 void PrintViewManager::PrintNowInternal() { | 445 void PrintViewManager::PrintNowInternal() { |
| 467 DCHECK(waiting_to_print_); | 446 DCHECK(waiting_to_print_); |
| 468 | 447 |
| 469 // Settings are already loaded. Go ahead. This will set | 448 // Settings are already loaded. Go ahead. This will set |
| 470 // print_job_->is_job_pending() to true. | 449 // print_job_->is_job_pending() to true. |
| 471 print_job_->StartPrinting(); | 450 print_job_->StartPrinting(); |
| 472 | 451 |
| 473 if (!print_job_->document() || | 452 if (!print_job_->document() || |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 538 } | 517 } |
| 539 | 518 |
| 540 // Settings are already loaded. Go ahead. This will set | 519 // Settings are already loaded. Go ahead. This will set |
| 541 // print_job_->is_job_pending() to true. | 520 // print_job_->is_job_pending() to true. |
| 542 print_job_->StartPrinting(); | 521 print_job_->StartPrinting(); |
| 543 return true; | 522 return true; |
| 544 } | 523 } |
| 545 | 524 |
| 546 } // namespace printing | 525 } // namespace printing |
| 547 | 526 |
| OLD | NEW |