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 const GError* error) { | |
496 static_cast<PrintDialogGtk2*>(user_data)->OnJobCompleted(print_job, error); | |
497 } | |
Elliot Glaysher
2015/07/20 19:31:40
Why was the thunk moved here? If you left it as a
knthzh
2015/07/21 15:48:27
I think I just wanted to remove it from the public
| |
491 void PrintDialogGtk2::SendDocumentToPrinter( | 498 void PrintDialogGtk2::SendDocumentToPrinter( |
492 const base::string16& document_name) { | 499 const base::string16& document_name) { |
493 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 500 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
494 | 501 |
495 // If |printer_| is NULL then somehow the GTK printer list changed out under | 502 // If |printer_| is NULL then somehow the GTK printer list changed out under |
496 // us. In which case, just bail out. | 503 // us. In which case, just bail out. |
497 if (!printer_) { | 504 if (!printer_) { |
498 // Matches AddRef() in PrintDocument(); | 505 // Matches AddRef() in PrintDocument(); |
499 Release(); | 506 Release(); |
500 return; | 507 return; |
501 } | 508 } |
502 | 509 |
503 // Save the settings for next time. | 510 // Save the settings for next time. |
504 g_last_used_settings.Get().SetLastUsedSettings(gtk_settings_); | 511 g_last_used_settings.Get().SetLastUsedSettings(gtk_settings_); |
505 | 512 |
506 GtkPrintJob* print_job = gtk_print_job_new( | 513 GtkPrintJob* print_job = gtk_print_job_new( |
507 base::UTF16ToUTF8(document_name).c_str(), | 514 base::UTF16ToUTF8(document_name).c_str(), |
508 printer_, | 515 printer_, |
509 gtk_settings_, | 516 gtk_settings_, |
510 page_setup_); | 517 page_setup_); |
511 gtk_print_job_set_source_file(print_job, path_to_pdf_.value().c_str(), NULL); | 518 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); | 519 gtk_print_job_send(print_job, OnJobCompletedThunk, this, NULL); |
513 } | 520 } |
514 | 521 |
515 // static | 522 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) | 523 if (error) |
524 LOG(ERROR) << "Printing failed: " << error->message; | 524 LOG(ERROR) << "Printing failed: " << error->message; |
525 if (print_job) | 525 if (print_job) |
526 g_object_unref(print_job); | 526 g_object_unref(print_job); |
527 base::FileUtilProxy::DeleteFile( | 527 base::FileUtilProxy::DeleteFile( |
528 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE).get(), | 528 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE).get(), |
529 path_to_pdf_, | 529 path_to_pdf_, |
530 false, | 530 false, |
531 base::FileUtilProxy::StatusCallback()); | 531 base::FileUtilProxy::StatusCallback()); |
532 // Printing finished. Matches AddRef() in PrintDocument(); | 532 // Printing finished. Matches AddRef() in PrintDocument(); |
533 Release(); | 533 Release(); |
534 } | 534 } |
535 | 535 |
536 void PrintDialogGtk2::InitPrintSettings(PrintSettings* settings) { | 536 void PrintDialogGtk2::InitPrintSettings(PrintSettings* settings) { |
537 InitPrintSettingsGtk(gtk_settings_, page_setup_, settings); | 537 InitPrintSettingsGtk(gtk_settings_, page_setup_, settings); |
538 context_->InitWithSettings(*settings); | 538 context_->InitWithSettings(*settings); |
539 } | 539 } |
540 | 540 |
541 void PrintDialogGtk2::OnWindowDestroying(aura::Window* window) { | 541 void PrintDialogGtk2::OnWindowDestroying(aura::Window* window) { |
542 DCHECK_EQ(libgtk2ui::GetAuraTransientParent(dialog_), window); | 542 DCHECK_EQ(libgtk2ui::GetAuraTransientParent(dialog_), window); |
543 | 543 |
544 libgtk2ui::ClearAuraTransientParent(dialog_); | 544 libgtk2ui::ClearAuraTransientParent(dialog_); |
545 window->RemoveObserver(this); | 545 window->RemoveObserver(this); |
546 Release(); | 546 Release(); |
547 } | 547 } |
OLD | NEW |