| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/ui/libgtk2ui/print_dialog_gtk2.h" | 5 #include "chrome/browser/ui/libgtk2ui/print_dialog_gtk2.h" |
| 6 | 6 |
| 7 #include <gtk/gtkunixprint.h> | 7 #include <gtk/gtkunixprint.h> |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <cmath> | 10 #include <cmath> |
| (...skipping 470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 481 callback_.Reset(); | 481 callback_.Reset(); |
| 482 return; | 482 return; |
| 483 } | 483 } |
| 484 case GTK_RESPONSE_APPLY: | 484 case GTK_RESPONSE_APPLY: |
| 485 default: { | 485 default: { |
| 486 NOTREACHED(); | 486 NOTREACHED(); |
| 487 } | 487 } |
| 488 } | 488 } |
| 489 } | 489 } |
| 490 | 490 |
| 491 |
| 492 |
| 493 static void OnJobCompletedThunk(GtkPrintJob* print_job, |
| 494 gpointer user_data, |
| 495 #if GTK_MAJOR_VERSION == 2 |
| 496 GError* error |
| 497 #else |
| 498 const GError* error |
| 499 #endif |
| 500 ) { |
| 501 static_cast<PrintDialogGtk2*>(user_data)->OnJobCompleted(print_job, error); |
| 502 } |
| 491 void PrintDialogGtk2::SendDocumentToPrinter( | 503 void PrintDialogGtk2::SendDocumentToPrinter( |
| 492 const base::string16& document_name) { | 504 const base::string16& document_name) { |
| 493 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 505 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 494 | 506 |
| 495 // If |printer_| is NULL then somehow the GTK printer list changed out under | 507 // If |printer_| is NULL then somehow the GTK printer list changed out under |
| 496 // us. In which case, just bail out. | 508 // us. In which case, just bail out. |
| 497 if (!printer_) { | 509 if (!printer_) { |
| 498 // Matches AddRef() in PrintDocument(); | 510 // Matches AddRef() in PrintDocument(); |
| 499 Release(); | 511 Release(); |
| 500 return; | 512 return; |
| 501 } | 513 } |
| 502 | 514 |
| 503 // Save the settings for next time. | 515 // Save the settings for next time. |
| 504 g_last_used_settings.Get().SetLastUsedSettings(gtk_settings_); | 516 g_last_used_settings.Get().SetLastUsedSettings(gtk_settings_); |
| 505 | 517 |
| 506 GtkPrintJob* print_job = gtk_print_job_new( | 518 GtkPrintJob* print_job = gtk_print_job_new( |
| 507 base::UTF16ToUTF8(document_name).c_str(), | 519 base::UTF16ToUTF8(document_name).c_str(), |
| 508 printer_, | 520 printer_, |
| 509 gtk_settings_, | 521 gtk_settings_, |
| 510 page_setup_); | 522 page_setup_); |
| 511 gtk_print_job_set_source_file(print_job, path_to_pdf_.value().c_str(), NULL); | 523 gtk_print_job_set_source_file(print_job, path_to_pdf_.value().c_str(), NULL); |
| 512 gtk_print_job_send(print_job, OnJobCompletedThunk, this, NULL); | 524 gtk_print_job_send(print_job, OnJobCompletedThunk, this, NULL); |
| 513 } | 525 } |
| 514 | 526 |
| 515 // static | 527 void PrintDialogGtk2::OnJobCompleted(GtkPrintJob* print_job, const GError* error
) { |
| 516 void PrintDialogGtk2::OnJobCompletedThunk(GtkPrintJob* print_job, | |
| 517 gpointer user_data, | |
| 518 GError* error) { | |
| 519 static_cast<PrintDialogGtk2*>(user_data)->OnJobCompleted(print_job, error); | |
| 520 } | |
| 521 | |
| 522 void PrintDialogGtk2::OnJobCompleted(GtkPrintJob* print_job, GError* error) { | |
| 523 if (error) | 528 if (error) |
| 524 LOG(ERROR) << "Printing failed: " << error->message; | 529 LOG(ERROR) << "Printing failed: " << error->message; |
| 525 if (print_job) | 530 if (print_job) |
| 526 g_object_unref(print_job); | 531 g_object_unref(print_job); |
| 527 base::FileUtilProxy::DeleteFile( | 532 base::FileUtilProxy::DeleteFile( |
| 528 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE).get(), | 533 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE).get(), |
| 529 path_to_pdf_, | 534 path_to_pdf_, |
| 530 false, | 535 false, |
| 531 base::FileUtilProxy::StatusCallback()); | 536 base::FileUtilProxy::StatusCallback()); |
| 532 // Printing finished. Matches AddRef() in PrintDocument(); | 537 // Printing finished. Matches AddRef() in PrintDocument(); |
| 533 Release(); | 538 Release(); |
| 534 } | 539 } |
| 535 | 540 |
| 536 void PrintDialogGtk2::InitPrintSettings(PrintSettings* settings) { | 541 void PrintDialogGtk2::InitPrintSettings(PrintSettings* settings) { |
| 537 InitPrintSettingsGtk(gtk_settings_, page_setup_, settings); | 542 InitPrintSettingsGtk(gtk_settings_, page_setup_, settings); |
| 538 context_->InitWithSettings(*settings); | 543 context_->InitWithSettings(*settings); |
| 539 } | 544 } |
| 540 | 545 |
| 541 void PrintDialogGtk2::OnWindowDestroying(aura::Window* window) { | 546 void PrintDialogGtk2::OnWindowDestroying(aura::Window* window) { |
| 542 DCHECK_EQ(libgtk2ui::GetAuraTransientParent(dialog_), window); | 547 DCHECK_EQ(libgtk2ui::GetAuraTransientParent(dialog_), window); |
| 543 | 548 |
| 544 libgtk2ui::ClearAuraTransientParent(dialog_); | 549 libgtk2ui::ClearAuraTransientParent(dialog_); |
| 545 window->RemoveObserver(this); | 550 window->RemoveObserver(this); |
| 546 Release(); | 551 Release(); |
| 547 } | 552 } |
| OLD | NEW |