Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(144)

Side by Side Diff: chrome/browser/ui/libgtk2ui/print_dialog_gtk2.cc

Issue 1234223005: Initial gtk3 support (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Silence gtk memory leak Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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,
516 void PrintDialogGtk2::OnJobCompletedThunk(GtkPrintJob* print_job, 528 const GError* error) {
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) 529 if (error)
524 LOG(ERROR) << "Printing failed: " << error->message; 530 LOG(ERROR) << "Printing failed: " << error->message;
525 if (print_job) 531 if (print_job)
526 g_object_unref(print_job); 532 g_object_unref(print_job);
527 base::FileUtilProxy::DeleteFile( 533 base::FileUtilProxy::DeleteFile(
528 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE).get(), 534 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE).get(),
529 path_to_pdf_, 535 path_to_pdf_,
530 false, 536 false,
531 base::FileUtilProxy::StatusCallback()); 537 base::FileUtilProxy::StatusCallback());
532 // Printing finished. Matches AddRef() in PrintDocument(); 538 // Printing finished. Matches AddRef() in PrintDocument();
533 Release(); 539 Release();
534 } 540 }
535 541
536 void PrintDialogGtk2::InitPrintSettings(PrintSettings* settings) { 542 void PrintDialogGtk2::InitPrintSettings(PrintSettings* settings) {
537 InitPrintSettingsGtk(gtk_settings_, page_setup_, settings); 543 InitPrintSettingsGtk(gtk_settings_, page_setup_, settings);
538 context_->InitWithSettings(*settings); 544 context_->InitWithSettings(*settings);
539 } 545 }
540 546
541 void PrintDialogGtk2::OnWindowDestroying(aura::Window* window) { 547 void PrintDialogGtk2::OnWindowDestroying(aura::Window* window) {
542 DCHECK_EQ(libgtk2ui::GetAuraTransientParent(dialog_), window); 548 DCHECK_EQ(libgtk2ui::GetAuraTransientParent(dialog_), window);
543 549
544 libgtk2ui::ClearAuraTransientParent(dialog_); 550 libgtk2ui::ClearAuraTransientParent(dialog_);
545 window->RemoveObserver(this); 551 window->RemoveObserver(this);
546 Release(); 552 Release();
547 } 553 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/libgtk2ui/print_dialog_gtk2.h ('k') | chrome/browser/ui/libgtk2ui/select_file_dialog_impl_gtk2.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698