Chromium Code Reviews| 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/grit/generated_resources.h" | 16 #include "chrome/grit/generated_resources.h" |
| 17 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
| 18 #include "content/public/browser/notification_service.h" | 18 #include "content/public/browser/notification_service.h" |
| 19 #include "content/public/browser/render_view_host.h" | 19 #include "content/public/browser/render_view_host.h" |
| 20 #include "content/public/browser/web_contents.h" | 20 #include "content/public/browser/web_contents.h" |
| 21 #include "printing/print_job_constants.h" | 21 #include "printing/print_job_constants.h" |
| 22 #include "printing/printed_document.h" | 22 #include "printing/printed_document.h" |
| 23 #include "printing/printed_page.h" | 23 #include "printing/printed_page.h" |
| 24 #include "printing/printing_utils.h" | 24 #include "printing/printing_utils.h" |
| 25 #include "ui/base/l10n/l10n_util.h" | 25 #include "ui/base/l10n/l10n_util.h" |
| 26 | 26 |
| 27 #if defined(OS_ANDROID) | |
| 28 #include "chrome/browser/android/tab_android.h" | |
| 29 #endif | |
| 30 | |
| 27 using content::BrowserThread; | 31 using content::BrowserThread; |
| 28 | 32 |
| 29 namespace printing { | 33 namespace printing { |
| 30 | 34 |
| 31 namespace { | 35 namespace { |
| 32 | 36 |
| 33 // Helper function to ensure |owner| is valid until at least |callback| returns. | 37 // Helper function to ensure |owner| is valid until at least |callback| returns. |
| 34 void HoldRefCallback(const scoped_refptr<printing::PrintJobWorkerOwner>& owner, | 38 void HoldRefCallback(const scoped_refptr<printing::PrintJobWorkerOwner>& owner, |
| 35 const base::Closure& callback) { | 39 const base::Closure& callback) { |
| 36 callback.Run(); | 40 callback.Run(); |
| (...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 110 DCHECK(owner_->RunsTasksOnCurrentThread()); | 114 DCHECK(owner_->RunsTasksOnCurrentThread()); |
| 111 Stop(); | 115 Stop(); |
| 112 } | 116 } |
| 113 | 117 |
| 114 void PrintJobWorker::SetNewOwner(PrintJobWorkerOwner* new_owner) { | 118 void PrintJobWorker::SetNewOwner(PrintJobWorkerOwner* new_owner) { |
| 115 DCHECK(page_number_ == PageNumber::npos()); | 119 DCHECK(page_number_ == PageNumber::npos()); |
| 116 owner_ = new_owner; | 120 owner_ = new_owner; |
| 117 } | 121 } |
| 118 | 122 |
| 119 void PrintJobWorker::GetSettings( | 123 void PrintJobWorker::GetSettings( |
| 120 bool ask_user_for_settings, | 124 PrinterQuery::GetSettingsAskParam ask_settings_type, |
| 121 int document_page_count, | 125 int document_page_count, |
| 122 bool has_selection, | 126 bool has_selection, |
| 123 MarginType margin_type) { | 127 MarginType margin_type) { |
| 124 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 128 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 125 DCHECK_EQ(page_number_, PageNumber::npos()); | 129 DCHECK_EQ(page_number_, PageNumber::npos()); |
| 126 | 130 |
| 127 // Recursive task processing is needed for the dialog in case it needs to be | 131 // Recursive task processing is needed for the dialog in case it needs to be |
| 128 // destroyed by a task. | 132 // destroyed by a task. |
| 129 // TODO(thestig): This code is wrong. SetNestableTasksAllowed(true) is needed | 133 // TODO(thestig): This code is wrong. SetNestableTasksAllowed(true) is needed |
| 130 // on the thread where the PrintDlgEx is called, and definitely both calls | 134 // on the thread where the PrintDlgEx is called, and definitely both calls |
| 131 // should happen on the same thread. See http://crbug.com/73466 | 135 // should happen on the same thread. See http://crbug.com/73466 |
| 132 // MessageLoop::current()->SetNestableTasksAllowed(true); | 136 // MessageLoop::current()->SetNestableTasksAllowed(true); |
| 133 printing_context_->set_margin_type(margin_type); | 137 printing_context_->set_margin_type(margin_type); |
| 134 | 138 |
| 135 // When we delegate to a destination, we don't ask the user for settings. | 139 // When we delegate to a destination, we don't ask the user for settings. |
| 136 // TODO(mad): Ask the destination for settings. | 140 // TODO(mad): Ask the destination for settings. |
| 137 if (ask_user_for_settings) { | 141 if (ask_settings_type == PrinterQuery::GetSettingsAskParam::ASK_USER) { |
| 138 BrowserThread::PostTask( | 142 BrowserThread::PostTask( |
| 139 BrowserThread::UI, FROM_HERE, | 143 BrowserThread::UI, FROM_HERE, |
| 140 base::Bind(&HoldRefCallback, make_scoped_refptr(owner_), | 144 base::Bind(&HoldRefCallback, make_scoped_refptr(owner_), |
| 141 base::Bind(&PrintJobWorker::GetSettingsWithUI, | 145 base::Bind(&PrintJobWorker::GetSettingsWithUI, |
|
Vitaly Buka (NO REVIEWS)
2014/12/12 08:37:16
ASK_USER vs SYSTEM_SPECIFIC is meaningless for oth
| |
| 142 base::Unretained(this), | 146 base::Unretained(this), |
| 143 document_page_count, | 147 document_page_count, |
| 144 has_selection))); | 148 has_selection))); |
| 149 } else if (ask_settings_type == | |
| 150 PrinterQuery::GetSettingsAskParam::SYSTEM_SPECIFIC) { | |
| 151 BrowserThread::PostTask( | |
| 152 BrowserThread::UI, FROM_HERE, | |
| 153 base::Bind(&HoldRefCallback, make_scoped_refptr(owner_), | |
| 154 base::Bind(&PrintJobWorker::ShowSystemDialog, | |
| 155 base::Unretained(this)))); | |
| 145 } else { | 156 } else { |
| 146 BrowserThread::PostTask( | 157 BrowserThread::PostTask( |
| 147 BrowserThread::UI, FROM_HERE, | 158 BrowserThread::UI, FROM_HERE, |
| 148 base::Bind(&HoldRefCallback, make_scoped_refptr(owner_), | 159 base::Bind(&HoldRefCallback, make_scoped_refptr(owner_), |
| 149 base::Bind(&PrintJobWorker::UseDefaultSettings, | 160 base::Bind(&PrintJobWorker::UseDefaultSettings, |
| 150 base::Unretained(this)))); | 161 base::Unretained(this)))); |
| 151 } | 162 } |
| 152 } | 163 } |
| 153 | 164 |
| 165 void PrintJobWorker::ShowSystemDialog() { | |
| 166 DCHECK_CURRENTLY_ON(BrowserThread::UI); | |
| 167 | |
| 168 #if defined(OS_ANDROID) | |
| 169 PrintingContextDelegate* pcd = | |
| 170 static_cast<PrintingContextDelegate*>(printing_context_delegate_.get()); | |
| 171 content::WebContents* wc = pcd->GetWebContents(); | |
|
Vitaly Buka (NO REVIEWS)
2014/12/12 08:37:16
please merge ShowSystemDialog and GetSettingsWithU
| |
| 172 TabAndroid* tab = TabAndroid::FromWebContents(wc); | |
| 173 if (tab) { | |
| 174 // If fails or is not called, attempting to start a pending print does | |
| 175 // nothing and will notify that printing is finished. | |
| 176 tab->SetPendingPrint(); | |
| 177 } | |
| 178 #endif | |
| 179 | |
| 180 printing_context_->RequestSystemDialog( | |
| 181 base::Bind(&PrintJobWorker::GetSettingsDone, | |
| 182 base::Unretained(this))); | |
| 183 } | |
| 184 | |
| 154 void PrintJobWorker::SetSettings( | 185 void PrintJobWorker::SetSettings( |
| 155 scoped_ptr<base::DictionaryValue> new_settings) { | 186 scoped_ptr<base::DictionaryValue> new_settings) { |
| 156 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 187 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
| 157 | 188 |
| 158 BrowserThread::PostTask( | 189 BrowserThread::PostTask( |
| 159 BrowserThread::UI, | 190 BrowserThread::UI, |
| 160 FROM_HERE, | 191 FROM_HERE, |
| 161 base::Bind(&HoldRefCallback, | 192 base::Bind(&HoldRefCallback, |
| 162 make_scoped_refptr(owner_), | 193 make_scoped_refptr(owner_), |
| 163 base::Bind(&PrintJobWorker::UpdatePrintSettings, | 194 base::Bind(&PrintJobWorker::UpdatePrintSettings, |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 408 document_, | 439 document_, |
| 409 scoped_refptr<PrintedPage>())); | 440 scoped_refptr<PrintedPage>())); |
| 410 Cancel(); | 441 Cancel(); |
| 411 | 442 |
| 412 // Makes sure the variables are reinitialized. | 443 // Makes sure the variables are reinitialized. |
| 413 document_ = NULL; | 444 document_ = NULL; |
| 414 page_number_ = PageNumber::npos(); | 445 page_number_ = PageNumber::npos(); |
| 415 } | 446 } |
| 416 | 447 |
| 417 } // namespace printing | 448 } // namespace printing |
| OLD | NEW |