summaryrefslogtreecommitdiffstats
path: root/chrome/browser/printing
diff options
context:
space:
mode:
authorestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-18 02:20:30 +0000
committerestade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-06-18 02:20:30 +0000
commitccd0226c79553e318657d6285c2feacebd105996 (patch)
tree0760118cbe4818320ad7afa2f0f06a8b6a132a9d /chrome/browser/printing
parent20ce516dc41e836279baba3a214f1b4e4dbcc22d (diff)
downloadchromium_src-ccd0226c79553e318657d6285c2feacebd105996.zip
chromium_src-ccd0226c79553e318657d6285c2feacebd105996.tar.gz
chromium_src-ccd0226c79553e318657d6285c2feacebd105996.tar.bz2
Don't allow more than one pending print dialog per browser instance.
As a future TODO, it might be nice to limit it per-tab instead of per-app. BUG=46575 TEST=manual Review URL: http://codereview.chromium.org/2848011 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@50203 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/printing')
-rw-r--r--chrome/browser/printing/print_dialog_gtk.cc29
-rw-r--r--chrome/browser/printing/print_dialog_gtk.h2
2 files changed, 30 insertions, 1 deletions
diff --git a/chrome/browser/printing/print_dialog_gtk.cc b/chrome/browser/printing/print_dialog_gtk.cc
index 1428ed7..5cc203d 100644
--- a/chrome/browser/printing/print_dialog_gtk.cc
+++ b/chrome/browser/printing/print_dialog_gtk.cc
@@ -9,6 +9,8 @@
#include <gtk/gtkpagesetupunixdialog.h>
#include "base/file_util.h"
+#include "base/lazy_instance.h"
+#include "base/lock.h"
#include "base/logging.h"
#include "chrome/browser/browser_list.h"
#include "chrome/browser/browser_window.h"
@@ -18,6 +20,14 @@
namespace {
+PrintDialogGtk* g_print_dialog = NULL;
+
+// Used to make accesses to the above thread safe.
+Lock& DialogLock() {
+ static base::LazyInstance<Lock> dialog_lock(base::LINKER_INITIALIZED);
+ return dialog_lock.Get();
+}
+
// This is a temporary infobar designed to help gauge how many users are trying
// to print to printers that don't support PDF.
class PdfUnsupportedInfoBarDelegate : public LinkInfoBarDelegate {
@@ -65,8 +75,22 @@ void PrintDialogGtk::CreatePrintDialogForPdf(const FilePath& path) {
}
// static
+bool PrintDialogGtk::DialogShowing() {
+ AutoLock lock(DialogLock());
+ return !!g_print_dialog;
+}
+
+// static
void PrintDialogGtk::CreateDialogImpl(const FilePath& path) {
- new PrintDialogGtk(path);
+ // Only show one print dialog at once. This is to prevent a page from
+ // locking up the system with
+ //
+ // while(true){print();}
+ AutoLock lock(DialogLock());
+ if (g_print_dialog)
+ return;
+
+ g_print_dialog = new PrintDialogGtk(path);
}
PrintDialogGtk::PrintDialogGtk(const FilePath& path_to_pdf)
@@ -82,6 +106,9 @@ PrintDialogGtk::PrintDialogGtk(const FilePath& path_to_pdf)
}
PrintDialogGtk::~PrintDialogGtk() {
+ AutoLock lock(DialogLock());
+ DCHECK_EQ(this, g_print_dialog);
+ g_print_dialog = NULL;
}
void PrintDialogGtk::OnResponse(gint response_id) {
diff --git a/chrome/browser/printing/print_dialog_gtk.h b/chrome/browser/printing/print_dialog_gtk.h
index 589af80..0c1087f 100644
--- a/chrome/browser/printing/print_dialog_gtk.h
+++ b/chrome/browser/printing/print_dialog_gtk.h
@@ -17,6 +17,8 @@ typedef struct _GtkPrintJob GtkPrintJob;
// Currently this dialog only allows the user to choose a printer.
class PrintDialogGtk {
public:
+ static bool DialogShowing();
+
// Called on the IO thread.
static void CreatePrintDialogForPdf(const FilePath& path);