summaryrefslogtreecommitdiffstats
path: root/chrome/browser/printing
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/printing')
-rw-r--r--chrome/browser/printing/print_job.cc7
-rw-r--r--chrome/browser/printing/print_job_worker.cc50
-rw-r--r--chrome/browser/printing/print_job_worker.h14
-rw-r--r--chrome/browser/printing/print_view_manager.cc8
-rw-r--r--chrome/browser/printing/printer_query.cc6
-rw-r--r--chrome/browser/printing/printer_query.h3
6 files changed, 73 insertions, 15 deletions
diff --git a/chrome/browser/printing/print_job.cc b/chrome/browser/printing/print_job.cc
index d65b7bf..8a1a5e2 100644
--- a/chrome/browser/printing/print_job.cc
+++ b/chrome/browser/printing/print_job.cc
@@ -21,8 +21,8 @@ namespace printing {
PrintJob::PrintJob()
: ui_message_loop_(MessageLoop::current()),
- worker_(),
source_(NULL),
+ worker_(),
settings_(),
is_job_pending_(false),
is_print_dialog_box_shown_(false),
@@ -284,6 +284,10 @@ void PrintJob::OnDocumentDone() {
void PrintJob::ControlledWorkerShutdown() {
DCHECK_EQ(ui_message_loop_, MessageLoop::current());
+
+ // The deadlock this code works around is specific to window messaging on
+ // Windows, so we aren't likely to need it on any other platforms.
+#if defined(OS_WIN)
// We could easily get into a deadlock case if worker_->Stop() is used; the
// printer driver created a window as a child of the browser window. By
// canceling the job, the printer driver initiated dialog box is destroyed,
@@ -323,6 +327,7 @@ void PrintJob::ControlledWorkerShutdown() {
break;
}
}
+#endif
// Now make sure the thread object is cleaned up.
worker_->Stop();
diff --git a/chrome/browser/printing/print_job_worker.cc b/chrome/browser/printing/print_job_worker.cc
index 375c2407..27a553d 100644
--- a/chrome/browser/printing/print_job_worker.cc
+++ b/chrome/browser/printing/print_job_worker.cc
@@ -5,6 +5,7 @@
#include "chrome/browser/printing/print_job_worker.h"
#include "base/message_loop.h"
+#include "chrome/browser/chrome_thread.h"
#include "chrome/browser/printing/print_job.h"
#include "chrome/common/notification_service.h"
#include "printing/printed_document.h"
@@ -64,7 +65,7 @@ void PrintJobWorker::SetNewOwner(PrintJobWorkerOwner* new_owner) {
}
void PrintJobWorker::GetSettings(bool ask_user_for_settings,
- HWND parent_window,
+ gfx::NativeWindow parent_window,
int document_page_count,
bool has_selection) {
DCHECK_EQ(message_loop(), MessageLoop::current());
@@ -74,15 +75,24 @@ void PrintJobWorker::GetSettings(bool ask_user_for_settings,
// destroyed by a task.
MessageLoop::current()->SetNestableTasksAllowed(true);
- PrintingContext::Result result;
if (ask_user_for_settings) {
- result = printing_context_.AskUserForSettings(parent_window,
- document_page_count,
- has_selection);
+#if defined(OS_MACOSX)
+ ChromeThread::GetMessageLoop(ChromeThread::UI)->PostTask(
+ FROM_HERE, NewRunnableMethod(this, &PrintJobWorker::GetSettingsWithUI,
+ parent_window, document_page_count,
+ has_selection));
+#else
+ PrintingContext::Result result = printing_context_.AskUserForSettings(
+ parent_window, document_page_count, has_selection);
+ GetSettingsDone(result);
+#endif
} else {
- result = printing_context_.UseDefaultSettings();
+ PrintingContext::Result result = printing_context_.UseDefaultSettings();
+ GetSettingsDone(result);
}
+}
+void PrintJobWorker::GetSettingsDone(PrintingContext::Result result) {
// Most PrintingContext functions may start a message loop and process
// message recursively, so disable recursive task processing.
MessageLoop::current()->SetNestableTasksAllowed(false);
@@ -97,13 +107,29 @@ void PrintJobWorker::GetSettings(bool ask_user_for_settings,
result));
}
+#if defined(OS_MACOSX)
+void PrintJobWorker::GetSettingsWithUI(gfx::NativeWindow parent_window,
+ int document_page_count,
+ bool has_selection) {
+ DCHECK_EQ(ChromeThread::GetMessageLoop(ChromeThread::UI),
+ MessageLoop::current());
+
+ PrintingContext::Result result = printing_context_.AskUserForSettings(
+ parent_window, document_page_count, has_selection);
+ message_loop()->PostTask(FROM_HERE, NewRunnableMethod(
+ this, &PrintJobWorker::GetSettingsDone, result));
+}
+#endif
+
void PrintJobWorker::StartPrinting(PrintedDocument* new_document) {
DCHECK_EQ(message_loop(), MessageLoop::current());
DCHECK_EQ(page_number_, PageNumber::npos());
DCHECK_EQ(document_, new_document);
DCHECK(document_.get());
DCHECK(new_document->settings().Equals(printing_context_.settings()));
+#if !defined(OS_MACOSX)
DCHECK(printing_context_.context());
+#endif
if (!document_.get() || page_number_ != PageNumber::npos() ||
document_ != new_document) {
return;
@@ -130,7 +156,9 @@ void PrintJobWorker::OnDocumentChanged(PrintedDocument* new_document) {
DCHECK_EQ(page_number_, PageNumber::npos());
DCHECK(!new_document ||
new_document->settings().Equals(printing_context_.settings()));
+#if !defined(OS_MACOSX)
DCHECK(printing_context_.context());
+#endif
if (page_number_ != PageNumber::npos())
return;
@@ -144,9 +172,11 @@ void PrintJobWorker::OnNewPage() {
}
// message_loop() could return NULL when the print job is cancelled.
DCHECK_EQ(message_loop(), MessageLoop::current());
+#if !defined(OS_MACOSX)
DCHECK(printing_context_.context());
if (!printing_context_.context())
return;
+#endif
if (page_number_ == PageNumber::npos()) {
// Find first page to print.
@@ -199,7 +229,9 @@ void PrintJobWorker::OnDocumentDone() {
DCHECK_EQ(message_loop(), MessageLoop::current());
DCHECK_EQ(page_number_, PageNumber::npos());
DCHECK(document_.get());
+#if !defined(OS_MACOSX)
DCHECK(printing_context_.context());
+#endif
if (printing_context_.DocumentDone() != PrintingContext::OK) {
OnFailure();
@@ -221,7 +253,9 @@ void PrintJobWorker::OnDocumentDone() {
void PrintJobWorker::SpoolPage(PrintedPage& page) {
DCHECK_EQ(message_loop(), MessageLoop::current());
DCHECK_NE(page_number_, PageNumber::npos());
+#if !defined(OS_MACOSX)
DCHECK(printing_context_.context());
+#endif
// Signal everyone that the page is about to be printed.
NotificationTask* task = new NotificationTask();
task->Init(owner_,
@@ -236,6 +270,10 @@ void PrintJobWorker::SpoolPage(PrintedPage& page) {
return;
}
+#if defined(OS_MACOSX)
+ // Context is only valid between NewPage and PageDone, so we only check here.
+ DCHECK(printing_context_.context());
+#endif
// Actual printing.
document_->RenderPrintedPage(page, printing_context_.context());
diff --git a/chrome/browser/printing/print_job_worker.h b/chrome/browser/printing/print_job_worker.h
index fce8912..56e7893 100644
--- a/chrome/browser/printing/print_job_worker.h
+++ b/chrome/browser/printing/print_job_worker.h
@@ -5,6 +5,7 @@
#ifndef CHROME_BROWSER_PRINTING_PRINT_JOB_WORKER_H__
#define CHROME_BROWSER_PRINTING_PRINT_JOB_WORKER_H__
+#include "app/gfx/native_widget_types.h"
#include "base/task.h"
#include "base/thread.h"
#include "printing/page_number.h"
@@ -33,7 +34,7 @@ class PrintJobWorker : public base::Thread {
// Initializes the print settings. If |ask_user_for_settings| is true, a
// Print... dialog box will be shown to ask the user his preference.
void GetSettings(bool ask_user_for_settings,
- HWND parent_window,
+ gfx::NativeWindow parent_window,
int document_page_count,
bool has_selection);
@@ -78,6 +79,17 @@ class PrintJobWorker : public base::Thread {
// context.
void OnFailure();
+#if defined(OS_MACOSX)
+ // Asks the user for print settings. Must be called on the UI thread.
+ // Mac-only since Windows can display UI from non-main threads.
+ void GetSettingsWithUI(gfx::NativeWindow parent_window,
+ int document_page_count,
+ bool has_selection);
+#endif
+
+ // Reports settings back to owner_.
+ void GetSettingsDone(PrintingContext::Result result);
+
// Information about the printer setting.
PrintingContext printing_context_;
diff --git a/chrome/browser/printing/print_view_manager.cc b/chrome/browser/printing/print_view_manager.cc
index 22f3abe..4f6e73a 100644
--- a/chrome/browser/printing/print_view_manager.cc
+++ b/chrome/browser/printing/print_view_manager.cc
@@ -24,10 +24,10 @@ using base::TimeDelta;
namespace printing {
PrintViewManager::PrintViewManager(TabContents& owner)
- : owner_(owner),
- waiting_to_print_(false),
+ : waiting_to_print_(false),
printing_succeeded_(false),
- inside_inner_message_loop_(false) {
+ inside_inner_message_loop_(false),
+ owner_(owner) {
}
PrintViewManager::~PrintViewManager() {
@@ -101,6 +101,7 @@ void PrintViewManager::DidPrintPage(
return;
}
+#if defined(OS_WIN)
// http://msdn2.microsoft.com/en-us/library/ms535522.aspx
// Windows 2000/XP: When a page in a spooled file exceeds approximately 350
// MB, it can fail to print and not send an error message.
@@ -110,6 +111,7 @@ void PrintViewManager::DidPrintPage(
owner_.Stop();
return;
}
+#endif
base::SharedMemory shared_buf(params.metafile_data_handle, true);
if (!shared_buf.Map(params.data_size)) {
diff --git a/chrome/browser/printing/printer_query.cc b/chrome/browser/printing/printer_query.cc
index 3bcee7a..4fdadbe 100644
--- a/chrome/browser/printing/printer_query.cc
+++ b/chrome/browser/printing/printer_query.cc
@@ -17,8 +17,8 @@ PrinterQuery::PrinterQuery()
: ui_message_loop_(MessageLoop::current()),
worker_(new PrintJobWorker(this)),
is_print_dialog_box_shown_(false),
- last_status_(PrintingContext::FAILED),
- cookie_(PrintSettings::NewCookie()) {
+ cookie_(PrintSettings::NewCookie()),
+ last_status_(PrintingContext::FAILED) {
}
PrinterQuery::~PrinterQuery() {
@@ -62,7 +62,7 @@ PrintJobWorker* PrinterQuery::DetachWorker(PrintJobWorkerOwner* new_owner) {
}
void PrinterQuery::GetSettings(GetSettingsAskParam ask_user_for_settings,
- HWND parent_window,
+ gfx::NativeWindow parent_window,
int expected_page_count,
bool has_selection,
CancelableTask* callback) {
diff --git a/chrome/browser/printing/printer_query.h b/chrome/browser/printing/printer_query.h
index b0502c8..b4826ec 100644
--- a/chrome/browser/printing/printer_query.h
+++ b/chrome/browser/printing/printer_query.h
@@ -5,6 +5,7 @@
#ifndef CHROME_BROWSER_PRINTING_PRINTER_QUERY_H_
#define CHROME_BROWSER_PRINTING_PRINTER_QUERY_H_
+#include "app/gfx/native_widget_types.h"
#include "base/scoped_ptr.h"
#include "chrome/browser/printing/print_job_worker_owner.h"
@@ -47,7 +48,7 @@ class PrinterQuery : public PrintJobWorkerOwner {
// owner of the print setting dialog box. It is unused when
// |ask_for_user_settings| is DEFAULTS.
void GetSettings(GetSettingsAskParam ask_user_for_settings,
- HWND parent_window,
+ gfx::NativeWindow parent_window,
int expected_page_count,
bool has_selection,
CancelableTask* callback);