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 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 gtk_settings_); | 354 gtk_settings_); |
355 g_signal_connect(dialog_, "response", G_CALLBACK(OnResponseThunk), this); | 355 g_signal_connect(dialog_, "response", G_CALLBACK(OnResponseThunk), this); |
356 gtk_widget_show(dialog_); | 356 gtk_widget_show(dialog_); |
357 | 357 |
358 // We need to call gtk_window_present after making the widgets visible to make | 358 // We need to call gtk_window_present after making the widgets visible to make |
359 // sure window gets correctly raised and gets focus. | 359 // sure window gets correctly raised and gets focus. |
360 int time = views::X11DesktopHandler::get()->wm_user_time_ms(); | 360 int time = views::X11DesktopHandler::get()->wm_user_time_ms(); |
361 gtk_window_present_with_time(GTK_WINDOW(dialog_), time); | 361 gtk_window_present_with_time(GTK_WINDOW(dialog_), time); |
362 } | 362 } |
363 | 363 |
364 void PrintDialogGtk2::PrintDocument(const printing::Metafile* metafile, | 364 void PrintDialogGtk2::PrintDocument(const printing::MetafilePlayer& metafile, |
365 const base::string16& document_name) { | 365 const base::string16& document_name) { |
366 // This runs on the print worker thread, does not block the UI thread. | 366 // This runs on the print worker thread, does not block the UI thread. |
367 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI)); | 367 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI)); |
368 | 368 |
369 // The document printing tasks can outlive the PrintingContext that created | 369 // The document printing tasks can outlive the PrintingContext that created |
370 // this dialog. | 370 // this dialog. |
371 AddRef(); | 371 AddRef(); |
372 | 372 |
373 bool error = false; | 373 bool success = base::CreateTemporaryFile(&path_to_pdf_); |
374 if (!base::CreateTemporaryFile(&path_to_pdf_)) { | 374 |
375 LOG(ERROR) << "Creating temporary file failed"; | 375 if (success) { |
376 error = true; | 376 base::File file; |
| 377 file.Initialize(path_to_pdf_, |
| 378 base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE); |
| 379 success = metafile.SaveTo(&file); |
| 380 file.Close(); |
| 381 if (!success) |
| 382 base::DeleteFile(path_to_pdf_, false); |
377 } | 383 } |
378 | 384 |
379 if (!error && !metafile->SaveTo(path_to_pdf_)) { | 385 if (!success) { |
380 LOG(ERROR) << "Saving metafile failed"; | 386 LOG(ERROR) << "Saving metafile failed"; |
381 base::DeleteFile(path_to_pdf_, false); | 387 // Matches AddRef() above. |
382 error = true; | 388 Release(); |
| 389 return; |
383 } | 390 } |
384 | 391 |
385 if (error) { | 392 // No errors, continue printing. |
386 // Matches AddRef() above. | 393 BrowserThread::PostTask( |
387 Release(); | 394 BrowserThread::UI, |
388 } else { | 395 FROM_HERE, |
389 // No errors, continue printing. | 396 base::Bind(&PrintDialogGtk2::SendDocumentToPrinter, this, document_name)); |
390 BrowserThread::PostTask( | |
391 BrowserThread::UI, FROM_HERE, | |
392 base::Bind(&PrintDialogGtk2::SendDocumentToPrinter, this, | |
393 document_name)); | |
394 } | |
395 } | 397 } |
396 | 398 |
397 void PrintDialogGtk2::AddRefToDialog() { | 399 void PrintDialogGtk2::AddRefToDialog() { |
398 AddRef(); | 400 AddRef(); |
399 } | 401 } |
400 | 402 |
401 void PrintDialogGtk2::ReleaseDialog() { | 403 void PrintDialogGtk2::ReleaseDialog() { |
402 Release(); | 404 Release(); |
403 } | 405 } |
404 | 406 |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
531 context_->InitWithSettings(*settings); | 533 context_->InitWithSettings(*settings); |
532 } | 534 } |
533 | 535 |
534 void PrintDialogGtk2::OnWindowDestroying(aura::Window* window) { | 536 void PrintDialogGtk2::OnWindowDestroying(aura::Window* window) { |
535 DCHECK_EQ(libgtk2ui::GetAuraTransientParent(dialog_), window); | 537 DCHECK_EQ(libgtk2ui::GetAuraTransientParent(dialog_), window); |
536 | 538 |
537 libgtk2ui::ClearAuraTransientParent(dialog_); | 539 libgtk2ui::ClearAuraTransientParent(dialog_); |
538 window->RemoveObserver(this); | 540 window->RemoveObserver(this); |
539 Release(); | 541 Release(); |
540 } | 542 } |
OLD | NEW |