OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_dialog_gtk.h" | 5 #include "chrome/browser/printing/print_dialog_gtk.h" |
6 | 6 |
7 #include <fcntl.h> | 7 #include <fcntl.h> |
8 #include <gtk/gtkpagesetupunixdialog.h> | 8 #include <gtk/gtkpagesetupunixdialog.h> |
9 #include <gtk/gtkprintjob.h> | 9 #include <gtk/gtkprintjob.h> |
10 #include <sys/stat.h> | 10 #include <sys/stat.h> |
11 #include <sys/types.h> | 11 #include <sys/types.h> |
12 | 12 |
13 #include "base/file_util.h" | 13 #include "base/file_util.h" |
14 #include "base/file_util_proxy.h" | 14 #include "base/file_util_proxy.h" |
15 #include "base/logging.h" | 15 #include "base/logging.h" |
16 #include "base/synchronization/waitable_event.h" | 16 #include "base/synchronization/waitable_event.h" |
17 #include "base/utf_string_conversions.h" | 17 #include "base/utf_string_conversions.h" |
18 #include "chrome/browser/ui/browser_list.h" | 18 #include "chrome/browser/ui/browser_list.h" |
19 #include "chrome/browser/ui/browser_window.h" | 19 #include "chrome/browser/ui/browser_window.h" |
| 20 #include "printing/metafile.h" |
20 #include "printing/print_settings_initializer_gtk.h" | 21 #include "printing/print_settings_initializer_gtk.h" |
21 | 22 |
22 // static | 23 // static |
23 printing::PrintDialogGtkInterface* PrintDialogGtk::CreatePrintDialog( | 24 printing::PrintDialogGtkInterface* PrintDialogGtk::CreatePrintDialog( |
24 PrintingContextCairo* context) { | 25 PrintingContextCairo* context) { |
25 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 26 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
26 return new PrintDialogGtk(context); | 27 return new PrintDialogGtk(context); |
27 } | 28 } |
28 | 29 |
29 PrintDialogGtk::PrintDialogGtk(PrintingContextCairo* context) | 30 PrintDialogGtk::PrintDialogGtk(PrintingContextCairo* context) |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 gtk_print_unix_dialog_set_manual_capabilities(GTK_PRINT_UNIX_DIALOG(dialog_), | 79 gtk_print_unix_dialog_set_manual_capabilities(GTK_PRINT_UNIX_DIALOG(dialog_), |
79 cap); | 80 cap); |
80 #if GTK_CHECK_VERSION(2, 18, 0) | 81 #if GTK_CHECK_VERSION(2, 18, 0) |
81 gtk_print_unix_dialog_set_embed_page_setup(GTK_PRINT_UNIX_DIALOG(dialog_), | 82 gtk_print_unix_dialog_set_embed_page_setup(GTK_PRINT_UNIX_DIALOG(dialog_), |
82 TRUE); | 83 TRUE); |
83 #endif | 84 #endif |
84 g_signal_connect(dialog_, "response", G_CALLBACK(OnResponseThunk), this); | 85 g_signal_connect(dialog_, "response", G_CALLBACK(OnResponseThunk), this); |
85 gtk_widget_show(dialog_); | 86 gtk_widget_show(dialog_); |
86 } | 87 } |
87 | 88 |
88 void PrintDialogGtk::PrintDocument(const NativeMetafile* metafile, | 89 void PrintDialogGtk::PrintDocument(const printing::Metafile* metafile, |
89 const string16& document_name) { | 90 const string16& document_name) { |
90 // This runs on the print worker thread, does not block the UI thread. | 91 // This runs on the print worker thread, does not block the UI thread. |
91 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI)); | 92 DCHECK(!BrowserThread::CurrentlyOn(BrowserThread::UI)); |
92 | 93 |
93 // The document printing tasks can outlive the PrintingContext that created | 94 // The document printing tasks can outlive the PrintingContext that created |
94 // this dialog. | 95 // this dialog. |
95 AddRef(); | 96 AddRef(); |
96 DCHECK(!save_document_event_.get()); | 97 DCHECK(!save_document_event_.get()); |
97 save_document_event_.reset(new base::WaitableEvent(false, false)); | 98 save_document_event_.reset(new base::WaitableEvent(false, false)); |
98 | 99 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 callback_ = NULL; | 158 callback_ = NULL; |
158 return; | 159 return; |
159 } | 160 } |
160 case GTK_RESPONSE_APPLY: | 161 case GTK_RESPONSE_APPLY: |
161 default: { | 162 default: { |
162 NOTREACHED(); | 163 NOTREACHED(); |
163 } | 164 } |
164 } | 165 } |
165 } | 166 } |
166 | 167 |
167 void PrintDialogGtk::SaveDocumentToDisk(const NativeMetafile* metafile, | 168 void PrintDialogGtk::SaveDocumentToDisk(const printing::Metafile* metafile, |
168 const string16& document_name) { | 169 const string16& document_name) { |
169 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); | 170 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); |
170 | 171 |
171 bool error = false; | 172 bool error = false; |
172 if (!file_util::CreateTemporaryFile(&path_to_pdf_)) { | 173 if (!file_util::CreateTemporaryFile(&path_to_pdf_)) { |
173 LOG(ERROR) << "Creating temporary file failed"; | 174 LOG(ERROR) << "Creating temporary file failed"; |
174 error = true; | 175 error = true; |
175 } | 176 } |
176 | 177 |
177 if (!error && !metafile->SaveTo(path_to_pdf_)) { | 178 if (!error && !metafile->SaveTo(path_to_pdf_)) { |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 if (print_job) | 221 if (print_job) |
221 g_object_unref(print_job); | 222 g_object_unref(print_job); |
222 base::FileUtilProxy::Delete( | 223 base::FileUtilProxy::Delete( |
223 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE), | 224 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE), |
224 path_to_pdf_, | 225 path_to_pdf_, |
225 false, | 226 false, |
226 NULL); | 227 NULL); |
227 // Printing finished. Matches AddRef() in PrintDocument(); | 228 // Printing finished. Matches AddRef() in PrintDocument(); |
228 Release(); | 229 Release(); |
229 } | 230 } |
OLD | NEW |