| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_job_worker.h" | 5 #include "chrome/browser/printing/print_job_worker.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/callback.h" | 9 #include "base/callback.h" |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 11 #include "base/message_loop/message_loop.h" | 11 #include "base/message_loop/message_loop.h" |
| 12 #include "base/values.h" | 12 #include "base/values.h" |
| 13 #include "chrome/browser/browser_process.h" | 13 #include "chrome/browser/browser_process.h" |
| 14 #include "chrome/browser/chrome_notification_types.h" | 14 #include "chrome/browser/chrome_notification_types.h" |
| 15 #include "chrome/browser/printing/print_job.h" | 15 #include "chrome/browser/printing/print_job.h" |
| 16 #include "chrome/browser/printing/printing_ui_web_contents_observer.h" |
| 16 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
| 17 #include "content/public/browser/notification_service.h" | 18 #include "content/public/browser/notification_service.h" |
| 18 #include "grit/generated_resources.h" | 19 #include "grit/generated_resources.h" |
| 19 #include "printing/backend/print_backend.h" | 20 #include "printing/backend/print_backend.h" |
| 20 #include "printing/print_job_constants.h" | 21 #include "printing/print_job_constants.h" |
| 21 #include "printing/printed_document.h" | 22 #include "printing/printed_document.h" |
| 22 #include "printing/printed_page.h" | 23 #include "printing/printed_page.h" |
| 23 #include "ui/base/l10n/l10n_util.h" | 24 #include "ui/base/l10n/l10n_util.h" |
| 24 | 25 |
| 25 using content::BrowserThread; | 26 using content::BrowserThread; |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 void PrintJobWorker::SetNewOwner(PrintJobWorkerOwner* new_owner) { | 71 void PrintJobWorker::SetNewOwner(PrintJobWorkerOwner* new_owner) { |
| 71 DCHECK(page_number_ == PageNumber::npos()); | 72 DCHECK(page_number_ == PageNumber::npos()); |
| 72 owner_ = new_owner; | 73 owner_ = new_owner; |
| 73 } | 74 } |
| 74 | 75 |
| 75 void PrintJobWorker::SetPrintDestination( | 76 void PrintJobWorker::SetPrintDestination( |
| 76 PrintDestinationInterface* destination) { | 77 PrintDestinationInterface* destination) { |
| 77 destination_ = destination; | 78 destination_ = destination; |
| 78 } | 79 } |
| 79 | 80 |
| 80 void PrintJobWorker::GetSettings(bool ask_user_for_settings, | 81 void PrintJobWorker::GetSettings( |
| 81 gfx::NativeView parent_view, | 82 bool ask_user_for_settings, |
| 82 int document_page_count, | 83 scoped_ptr<PrintingUIWebContentsObserver> web_contents_observer, |
| 83 bool has_selection, | 84 int document_page_count, |
| 84 MarginType margin_type) { | 85 bool has_selection, |
| 86 MarginType margin_type) { |
| 85 DCHECK_EQ(message_loop(), base::MessageLoop::current()); | 87 DCHECK_EQ(message_loop(), base::MessageLoop::current()); |
| 86 DCHECK_EQ(page_number_, PageNumber::npos()); | 88 DCHECK_EQ(page_number_, PageNumber::npos()); |
| 87 | 89 |
| 88 // Recursive task processing is needed for the dialog in case it needs to be | 90 // Recursive task processing is needed for the dialog in case it needs to be |
| 89 // destroyed by a task. | 91 // destroyed by a task. |
| 90 // TODO(thestig): This code is wrong. SetNestableTasksAllowed(true) is needed | 92 // TODO(thestig): This code is wrong. SetNestableTasksAllowed(true) is needed |
| 91 // on the thread where the PrintDlgEx is called, and definitely both calls | 93 // on the thread where the PrintDlgEx is called, and definitely both calls |
| 92 // should happen on the same thread. See http://crbug.com/73466 | 94 // should happen on the same thread. See http://crbug.com/73466 |
| 93 // MessageLoop::current()->SetNestableTasksAllowed(true); | 95 // MessageLoop::current()->SetNestableTasksAllowed(true); |
| 94 printing_context_->set_margin_type(margin_type); | 96 printing_context_->set_margin_type(margin_type); |
| 95 | 97 |
| 96 // When we delegate to a destination, we don't ask the user for settings. | 98 // When we delegate to a destination, we don't ask the user for settings. |
| 97 // TODO(mad): Ask the destination for settings. | 99 // TODO(mad): Ask the destination for settings. |
| 98 if (ask_user_for_settings && destination_.get() == NULL) { | 100 if (ask_user_for_settings && destination_.get() == NULL) { |
| 99 BrowserThread::PostTask( | 101 BrowserThread::PostTask( |
| 100 BrowserThread::UI, FROM_HERE, | 102 BrowserThread::UI, FROM_HERE, |
| 101 base::Bind(&HoldRefCallback, make_scoped_refptr(owner_), | 103 base::Bind(&HoldRefCallback, make_scoped_refptr(owner_), |
| 102 base::Bind(&PrintJobWorker::GetSettingsWithUI, | 104 base::Bind(&PrintJobWorker::GetSettingsWithUI, |
| 103 base::Unretained(this), parent_view, | 105 base::Unretained(this), |
| 104 document_page_count, has_selection))); | 106 base::Passed(&web_contents_observer), |
| 107 document_page_count, |
| 108 has_selection))); |
| 105 } else { | 109 } else { |
| 106 BrowserThread::PostTask( | 110 BrowserThread::PostTask( |
| 107 BrowserThread::UI, FROM_HERE, | 111 BrowserThread::UI, FROM_HERE, |
| 108 base::Bind(&HoldRefCallback, make_scoped_refptr(owner_), | 112 base::Bind(&HoldRefCallback, make_scoped_refptr(owner_), |
| 109 base::Bind(&PrintJobWorker::UseDefaultSettings, | 113 base::Bind(&PrintJobWorker::UseDefaultSettings, |
| 110 base::Unretained(this)))); | 114 base::Unretained(this)))); |
| 111 } | 115 } |
| 112 } | 116 } |
| 113 | 117 |
| 114 void PrintJobWorker::SetSettings(const DictionaryValue* const new_settings) { | 118 void PrintJobWorker::SetSettings(const DictionaryValue* const new_settings) { |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 // We can't use OnFailure() here since owner_ may not support notifications. | 166 // We can't use OnFailure() here since owner_ may not support notifications. |
| 163 | 167 |
| 164 // PrintJob will create the new PrintedDocument. | 168 // PrintJob will create the new PrintedDocument. |
| 165 owner_->message_loop()->PostTask( | 169 owner_->message_loop()->PostTask( |
| 166 FROM_HERE, | 170 FROM_HERE, |
| 167 base::Bind(&PrintJobWorkerOwner::GetSettingsDone, | 171 base::Bind(&PrintJobWorkerOwner::GetSettingsDone, |
| 168 make_scoped_refptr(owner_), printing_context_->settings(), | 172 make_scoped_refptr(owner_), printing_context_->settings(), |
| 169 result)); | 173 result)); |
| 170 } | 174 } |
| 171 | 175 |
| 172 void PrintJobWorker::GetSettingsWithUI(gfx::NativeView parent_view, | 176 void PrintJobWorker::GetSettingsWithUI( |
| 173 int document_page_count, | 177 scoped_ptr<PrintingUIWebContentsObserver> web_contents_observer, |
| 174 bool has_selection) { | 178 int document_page_count, |
| 179 bool has_selection) { |
| 175 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 180 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); |
| 176 | 181 |
| 182 gfx::NativeView parent_view; |
| 183 if (!web_contents_observer->GetParentView(&parent_view)) { |
| 184 GetSettingsWithUIDone(printing::PrintingContext::FAILED); |
| 185 return; |
| 186 } |
| 177 printing_context_->AskUserForSettings( | 187 printing_context_->AskUserForSettings( |
| 178 parent_view, document_page_count, has_selection, | 188 parent_view, document_page_count, has_selection, |
| 179 base::Bind(&PrintJobWorker::GetSettingsWithUIDone, | 189 base::Bind(&PrintJobWorker::GetSettingsWithUIDone, |
| 180 base::Unretained(this))); | 190 base::Unretained(this))); |
| 181 } | 191 } |
| 182 | 192 |
| 183 void PrintJobWorker::GetSettingsWithUIDone(PrintingContext::Result result) { | 193 void PrintJobWorker::GetSettingsWithUIDone(PrintingContext::Result result) { |
| 184 message_loop()->PostTask( | 194 message_loop()->PostTask( |
| 185 FROM_HERE, | 195 FROM_HERE, |
| 186 base::Bind(&HoldRefCallback, make_scoped_refptr(owner_), | 196 base::Bind(&HoldRefCallback, make_scoped_refptr(owner_), |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 JobEventDetails::FAILED, document_, | 380 JobEventDetails::FAILED, document_, |
| 371 scoped_refptr<PrintedPage>())); | 381 scoped_refptr<PrintedPage>())); |
| 372 Cancel(); | 382 Cancel(); |
| 373 | 383 |
| 374 // Makes sure the variables are reinitialized. | 384 // Makes sure the variables are reinitialized. |
| 375 document_ = NULL; | 385 document_ = NULL; |
| 376 page_number_ = PageNumber::npos(); | 386 page_number_ = PageNumber::npos(); |
| 377 } | 387 } |
| 378 | 388 |
| 379 } // namespace printing | 389 } // namespace printing |
| OLD | NEW |