| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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_view_manager_base.h" | 5 #include "chrome/browser/printing/print_view_manager_base.h" |
| 6 | 6 |
| 7 #include "base/auto_reset.h" |
| 7 #include "base/bind.h" | 8 #include "base/bind.h" |
| 8 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/prefs/pref_service.h" | 10 #include "base/prefs/pref_service.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 11 #include "base/timer/timer.h" | 12 #include "base/timer/timer.h" |
| 12 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
| 13 #include "chrome/browser/chrome_notification_types.h" | 14 #include "chrome/browser/chrome_notification_types.h" |
| 14 #include "chrome/browser/printing/print_job.h" | 15 #include "chrome/browser/printing/print_job.h" |
| 15 #include "chrome/browser/printing/print_job_manager.h" | 16 #include "chrome/browser/printing/print_job_manager.h" |
| 16 #include "chrome/browser/printing/printer_query.h" | 17 #include "chrome/browser/printing/printer_query.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 33 #include "chrome/browser/printing/print_error_dialog.h" | 34 #include "chrome/browser/printing/print_error_dialog.h" |
| 34 #endif | 35 #endif |
| 35 | 36 |
| 36 using base::TimeDelta; | 37 using base::TimeDelta; |
| 37 using content::BrowserThread; | 38 using content::BrowserThread; |
| 38 | 39 |
| 39 namespace printing { | 40 namespace printing { |
| 40 | 41 |
| 41 namespace { | 42 namespace { |
| 42 | 43 |
| 44 void ShowWarningMessageBox(const base::string16& message) { |
| 45 // Runs always on the UI thread. |
| 46 static bool is_dialog_shown = false; |
| 47 if (is_dialog_shown) |
| 48 return; |
| 49 // Block opening dialog from nested task. |
| 50 base::AutoReset<bool> auto_reset(&is_dialog_shown, true); |
| 51 |
| 52 chrome::ShowMessageBox(nullptr, base::string16(), message, |
| 53 chrome::MESSAGE_BOX_TYPE_WARNING); |
| 54 } |
| 55 |
| 43 } // namespace | 56 } // namespace |
| 44 | 57 |
| 45 PrintViewManagerBase::PrintViewManagerBase(content::WebContents* web_contents) | 58 PrintViewManagerBase::PrintViewManagerBase(content::WebContents* web_contents) |
| 46 : content::WebContentsObserver(web_contents), | 59 : content::WebContentsObserver(web_contents), |
| 47 number_pages_(0), | 60 number_pages_(0), |
| 48 printing_succeeded_(false), | 61 printing_succeeded_(false), |
| 49 inside_inner_message_loop_(false), | 62 inside_inner_message_loop_(false), |
| 50 cookie_(0), | 63 cookie_(0), |
| 51 queue_(g_browser_process->print_job_manager()->queue()) { | 64 queue_(g_browser_process->print_job_manager()->queue()) { |
| 52 DCHECK(queue_.get()); | 65 DCHECK(queue_.get()); |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 | 201 |
| 189 ReleasePrinterQuery(); | 202 ReleasePrinterQuery(); |
| 190 | 203 |
| 191 content::NotificationService::current()->Notify( | 204 content::NotificationService::current()->Notify( |
| 192 chrome::NOTIFICATION_PRINT_JOB_RELEASED, | 205 chrome::NOTIFICATION_PRINT_JOB_RELEASED, |
| 193 content::Source<content::WebContents>(web_contents()), | 206 content::Source<content::WebContents>(web_contents()), |
| 194 content::NotificationService::NoDetails()); | 207 content::NotificationService::NoDetails()); |
| 195 } | 208 } |
| 196 | 209 |
| 197 void PrintViewManagerBase::OnShowInvalidPrinterSettingsError() { | 210 void PrintViewManagerBase::OnShowInvalidPrinterSettingsError() { |
| 198 chrome::ShowMessageBox(NULL, | 211 base::MessageLoop::current()->PostTask( |
| 199 base::string16(), | 212 FROM_HERE, base::Bind(&ShowWarningMessageBox, |
| 200 l10n_util::GetStringUTF16( | 213 l10n_util::GetStringUTF16( |
| 201 IDS_PRINT_INVALID_PRINTER_SETTINGS), | 214 IDS_PRINT_INVALID_PRINTER_SETTINGS))); |
| 202 chrome::MESSAGE_BOX_TYPE_WARNING); | |
| 203 } | 215 } |
| 204 | 216 |
| 205 void PrintViewManagerBase::DidStartLoading() { | 217 void PrintViewManagerBase::DidStartLoading() { |
| 206 UpdateScriptedPrintingBlocked(); | 218 UpdateScriptedPrintingBlocked(); |
| 207 } | 219 } |
| 208 | 220 |
| 209 bool PrintViewManagerBase::OnMessageReceived(const IPC::Message& message) { | 221 bool PrintViewManagerBase::OnMessageReceived(const IPC::Message& message) { |
| 210 bool handled = true; | 222 bool handled = true; |
| 211 IPC_BEGIN_MESSAGE_MAP(PrintViewManagerBase, message) | 223 IPC_BEGIN_MESSAGE_MAP(PrintViewManagerBase, message) |
| 212 IPC_MESSAGE_HANDLER(PrintHostMsg_DidGetPrintedPagesCount, | 224 IPC_MESSAGE_HANDLER(PrintHostMsg_DidGetPrintedPagesCount, |
| (...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 514 scoped_refptr<printing::PrinterQuery> printer_query; | 526 scoped_refptr<printing::PrinterQuery> printer_query; |
| 515 printer_query = queue_->PopPrinterQuery(cookie); | 527 printer_query = queue_->PopPrinterQuery(cookie); |
| 516 if (!printer_query.get()) | 528 if (!printer_query.get()) |
| 517 return; | 529 return; |
| 518 BrowserThread::PostTask( | 530 BrowserThread::PostTask( |
| 519 BrowserThread::IO, FROM_HERE, | 531 BrowserThread::IO, FROM_HERE, |
| 520 base::Bind(&PrinterQuery::StopWorker, printer_query.get())); | 532 base::Bind(&PrinterQuery::StopWorker, printer_query.get())); |
| 521 } | 533 } |
| 522 | 534 |
| 523 } // namespace printing | 535 } // namespace printing |
| OLD | NEW |