OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 <gtk/gtkprintjob.h> | 7 #include <gtk/gtkprintjob.h> |
8 #include <gtk/gtkprintunixdialog.h> | 8 #include <gtk/gtkprintunixdialog.h> |
9 #include <gtk/gtkpagesetupunixdialog.h> | 9 #include <gtk/gtkpagesetupunixdialog.h> |
10 | 10 |
11 #include "base/file_util.h" | 11 #include "base/file_util.h" |
12 #include "base/file_util_proxy.h" | 12 #include "base/file_util_proxy.h" |
13 #include "base/lazy_instance.h" | 13 #include "base/lazy_instance.h" |
14 #include "base/lock.h" | |
15 #include "base/logging.h" | 14 #include "base/logging.h" |
| 15 #include "base/synchronization/lock.h" |
16 #include "base/threading/thread_restrictions.h" | 16 #include "base/threading/thread_restrictions.h" |
17 #include "base/utf_string_conversions.h" | 17 #include "base/utf_string_conversions.h" |
18 #include "chrome/browser/browser_list.h" | 18 #include "chrome/browser/browser_list.h" |
19 #include "chrome/browser/browser_thread.h" | 19 #include "chrome/browser/browser_thread.h" |
20 #include "chrome/browser/browser_window.h" | 20 #include "chrome/browser/browser_window.h" |
21 #include "chrome/browser/tab_contents/infobar_delegate.h" | 21 #include "chrome/browser/tab_contents/infobar_delegate.h" |
22 #include "chrome/browser/tab_contents/tab_contents.h" | 22 #include "chrome/browser/tab_contents/tab_contents.h" |
23 | 23 |
24 namespace { | 24 namespace { |
25 | 25 |
26 PrintDialogGtk* g_print_dialog = NULL; | 26 PrintDialogGtk* g_print_dialog = NULL; |
27 | 27 |
28 // Used to make accesses to the above thread safe. | 28 // Used to make accesses to the above thread safe. |
29 Lock& DialogLock() { | 29 base::Lock& DialogLock() { |
30 static base::LazyInstance<Lock> dialog_lock(base::LINKER_INITIALIZED); | 30 static base::LazyInstance<base::Lock> dialog_lock(base::LINKER_INITIALIZED); |
31 return dialog_lock.Get(); | 31 return dialog_lock.Get(); |
32 } | 32 } |
33 | 33 |
34 // This is a temporary infobar designed to help gauge how many users are trying | 34 // This is a temporary infobar designed to help gauge how many users are trying |
35 // to print to printers that don't support PDF. | 35 // to print to printers that don't support PDF. |
36 class PdfUnsupportedInfoBarDelegate : public LinkInfoBarDelegate { | 36 class PdfUnsupportedInfoBarDelegate : public LinkInfoBarDelegate { |
37 public: | 37 public: |
38 explicit PdfUnsupportedInfoBarDelegate(Browser* browser) | 38 explicit PdfUnsupportedInfoBarDelegate(Browser* browser) |
39 : LinkInfoBarDelegate(NULL), | 39 : LinkInfoBarDelegate(NULL), |
40 browser_(browser) { | 40 browser_(browser) { |
(...skipping 29 matching lines...) Expand all Loading... |
70 | 70 |
71 // static | 71 // static |
72 void PrintDialogGtk::CreatePrintDialogForPdf(const FilePath& path) { | 72 void PrintDialogGtk::CreatePrintDialogForPdf(const FilePath& path) { |
73 BrowserThread::PostTask( | 73 BrowserThread::PostTask( |
74 BrowserThread::UI, FROM_HERE, | 74 BrowserThread::UI, FROM_HERE, |
75 NewRunnableFunction(&PrintDialogGtk::CreateDialogImpl, path)); | 75 NewRunnableFunction(&PrintDialogGtk::CreateDialogImpl, path)); |
76 } | 76 } |
77 | 77 |
78 // static | 78 // static |
79 bool PrintDialogGtk::DialogShowing() { | 79 bool PrintDialogGtk::DialogShowing() { |
80 AutoLock lock(DialogLock()); | 80 base::AutoLock lock(DialogLock()); |
81 return !!g_print_dialog; | 81 return !!g_print_dialog; |
82 } | 82 } |
83 | 83 |
84 // static | 84 // static |
85 void PrintDialogGtk::CreateDialogImpl(const FilePath& path) { | 85 void PrintDialogGtk::CreateDialogImpl(const FilePath& path) { |
86 // Only show one print dialog at once. This is to prevent a page from | 86 // Only show one print dialog at once. This is to prevent a page from |
87 // locking up the system with | 87 // locking up the system with |
88 // | 88 // |
89 // while(true){print();} | 89 // while(true){print();} |
90 AutoLock lock(DialogLock()); | 90 base::AutoLock lock(DialogLock()); |
91 if (g_print_dialog) | 91 if (g_print_dialog) |
92 return; | 92 return; |
93 | 93 |
94 g_print_dialog = new PrintDialogGtk(path); | 94 g_print_dialog = new PrintDialogGtk(path); |
95 } | 95 } |
96 | 96 |
97 PrintDialogGtk::PrintDialogGtk(const FilePath& path_to_pdf) | 97 PrintDialogGtk::PrintDialogGtk(const FilePath& path_to_pdf) |
98 : path_to_pdf_(path_to_pdf), | 98 : path_to_pdf_(path_to_pdf), |
99 browser_(BrowserList::GetLastActive()) { | 99 browser_(BrowserList::GetLastActive()) { |
100 GtkWindow* parent = browser_->window()->GetNativeHandle(); | 100 GtkWindow* parent = browser_->window()->GetNativeHandle(); |
101 | 101 |
102 // TODO(estade): We need a window title here. | 102 // TODO(estade): We need a window title here. |
103 dialog_ = gtk_print_unix_dialog_new(NULL, parent); | 103 dialog_ = gtk_print_unix_dialog_new(NULL, parent); |
104 g_signal_connect(dialog_, "response", G_CALLBACK(OnResponseThunk), this); | 104 g_signal_connect(dialog_, "response", G_CALLBACK(OnResponseThunk), this); |
105 | 105 |
106 gtk_widget_show(dialog_); | 106 gtk_widget_show(dialog_); |
107 } | 107 } |
108 | 108 |
109 PrintDialogGtk::~PrintDialogGtk() { | 109 PrintDialogGtk::~PrintDialogGtk() { |
110 AutoLock lock(DialogLock()); | 110 base::AutoLock lock(DialogLock()); |
111 DCHECK_EQ(this, g_print_dialog); | 111 DCHECK_EQ(this, g_print_dialog); |
112 g_print_dialog = NULL; | 112 g_print_dialog = NULL; |
113 } | 113 } |
114 | 114 |
115 void PrintDialogGtk::OnResponse(GtkWidget* dialog, gint response_id) { | 115 void PrintDialogGtk::OnResponse(GtkWidget* dialog, gint response_id) { |
116 gtk_widget_hide(dialog_); | 116 gtk_widget_hide(dialog_); |
117 | 117 |
118 switch (response_id) { | 118 switch (response_id) { |
119 case GTK_RESPONSE_OK: { | 119 case GTK_RESPONSE_OK: { |
120 GtkPrinter* printer = | 120 GtkPrinter* printer = |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 g_object_unref(job); | 172 g_object_unref(job); |
173 | 173 |
174 base::FileUtilProxy::Delete( | 174 base::FileUtilProxy::Delete( |
175 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE), | 175 BrowserThread::GetMessageLoopProxyForThread(BrowserThread::FILE), |
176 path_to_pdf_, | 176 path_to_pdf_, |
177 false, | 177 false, |
178 NULL); | 178 NULL); |
179 | 179 |
180 delete this; | 180 delete this; |
181 } | 181 } |
OLD | NEW |