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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 bool ask_user_for_settings, |
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, |
128 bool is_scripted) { | |
124 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 129 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
125 DCHECK_EQ(page_number_, PageNumber::npos()); | 130 DCHECK_EQ(page_number_, PageNumber::npos()); |
126 | 131 |
127 // Recursive task processing is needed for the dialog in case it needs to be | 132 // Recursive task processing is needed for the dialog in case it needs to be |
128 // destroyed by a task. | 133 // destroyed by a task. |
129 // TODO(thestig): This code is wrong. SetNestableTasksAllowed(true) is needed | 134 // TODO(thestig): This code is wrong. SetNestableTasksAllowed(true) is needed |
130 // on the thread where the PrintDlgEx is called, and definitely both calls | 135 // on the thread where the PrintDlgEx is called, and definitely both calls |
131 // should happen on the same thread. See http://crbug.com/73466 | 136 // should happen on the same thread. See http://crbug.com/73466 |
132 // MessageLoop::current()->SetNestableTasksAllowed(true); | 137 // MessageLoop::current()->SetNestableTasksAllowed(true); |
133 printing_context_->set_margin_type(margin_type); | 138 printing_context_->set_margin_type(margin_type); |
134 | 139 |
135 // When we delegate to a destination, we don't ask the user for settings. | 140 // When we delegate to a destination, we don't ask the user for settings. |
136 // TODO(mad): Ask the destination for settings. | 141 // TODO(mad): Ask the destination for settings. |
137 if (ask_user_for_settings) { | 142 if (ask_user_for_settings) { |
138 BrowserThread::PostTask( | 143 BrowserThread::PostTask( |
139 BrowserThread::UI, FROM_HERE, | 144 BrowserThread::UI, FROM_HERE, |
140 base::Bind(&HoldRefCallback, make_scoped_refptr(owner_), | 145 base::Bind(&HoldRefCallback, make_scoped_refptr(owner_), |
141 base::Bind(&PrintJobWorker::GetSettingsWithUI, | 146 base::Bind(&PrintJobWorker::GetSettingsWithUI, |
142 base::Unretained(this), | 147 base::Unretained(this), |
143 document_page_count, | 148 document_page_count, |
144 has_selection))); | 149 has_selection, |
150 is_scripted))); | |
145 } else { | 151 } else { |
146 BrowserThread::PostTask( | 152 BrowserThread::PostTask( |
147 BrowserThread::UI, FROM_HERE, | 153 BrowserThread::UI, FROM_HERE, |
148 base::Bind(&HoldRefCallback, make_scoped_refptr(owner_), | 154 base::Bind(&HoldRefCallback, make_scoped_refptr(owner_), |
149 base::Bind(&PrintJobWorker::UseDefaultSettings, | 155 base::Bind(&PrintJobWorker::UseDefaultSettings, |
150 base::Unretained(this)))); | 156 base::Unretained(this)))); |
151 } | 157 } |
152 } | 158 } |
153 | 159 |
154 void PrintJobWorker::SetSettings( | 160 void PrintJobWorker::SetSettings( |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
186 // PrintJob will create the new PrintedDocument. | 192 // PrintJob will create the new PrintedDocument. |
187 owner_->PostTask(FROM_HERE, | 193 owner_->PostTask(FROM_HERE, |
188 base::Bind(&PrintJobWorkerOwner::GetSettingsDone, | 194 base::Bind(&PrintJobWorkerOwner::GetSettingsDone, |
189 make_scoped_refptr(owner_), | 195 make_scoped_refptr(owner_), |
190 printing_context_->settings(), | 196 printing_context_->settings(), |
191 result)); | 197 result)); |
192 } | 198 } |
193 | 199 |
194 void PrintJobWorker::GetSettingsWithUI( | 200 void PrintJobWorker::GetSettingsWithUI( |
195 int document_page_count, | 201 int document_page_count, |
196 bool has_selection) { | 202 bool has_selection, |
203 bool is_scripted) { | |
197 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 204 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
205 | |
206 #if defined(OS_ANDROID) | |
207 if (is_scripted) { | |
208 PrintingContextDelegate* printing_context_delegate = | |
209 static_cast<PrintingContextDelegate*>(printing_context_delegate_.get()); | |
210 content::WebContents* web_contents = | |
211 printing_context_delegate->GetWebContents(); | |
212 TabAndroid* tab = TabAndroid::FromWebContents(web_contents); | |
213 if (tab) { | |
214 // If the following method fails (print not supported by policy, print | |
215 // in progress...) or is not called, attempting to start a pending print | |
216 // does nothing and will notify that printing is finished. | |
Bernhard Bauer
2014/12/15 10:44:59
I'm not particularly familiar with this code, but
dgn
2014/12/15 13:16:24
Initially, the comment was there to clarify what h
| |
217 tab->SetPendingPrint(); | |
218 } | |
219 } | |
220 #endif | |
221 | |
198 printing_context_->AskUserForSettings( | 222 printing_context_->AskUserForSettings( |
199 document_page_count, | 223 document_page_count, |
200 has_selection, | 224 has_selection, |
225 is_scripted, | |
201 base::Bind(&PrintJobWorker::GetSettingsWithUIDone, | 226 base::Bind(&PrintJobWorker::GetSettingsWithUIDone, |
202 base::Unretained(this))); | 227 base::Unretained(this))); |
203 } | 228 } |
204 | 229 |
205 void PrintJobWorker::GetSettingsWithUIDone(PrintingContext::Result result) { | 230 void PrintJobWorker::GetSettingsWithUIDone(PrintingContext::Result result) { |
206 PostTask(FROM_HERE, | 231 PostTask(FROM_HERE, |
207 base::Bind(&HoldRefCallback, | 232 base::Bind(&HoldRefCallback, |
208 make_scoped_refptr(owner_), | 233 make_scoped_refptr(owner_), |
209 base::Bind(&PrintJobWorker::GetSettingsDone, | 234 base::Bind(&PrintJobWorker::GetSettingsDone, |
210 base::Unretained(this), | 235 base::Unretained(this), |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
408 document_, | 433 document_, |
409 scoped_refptr<PrintedPage>())); | 434 scoped_refptr<PrintedPage>())); |
410 Cancel(); | 435 Cancel(); |
411 | 436 |
412 // Makes sure the variables are reinitialized. | 437 // Makes sure the variables are reinitialized. |
413 document_ = NULL; | 438 document_ = NULL; |
414 page_number_ = PageNumber::npos(); | 439 page_number_ = PageNumber::npos(); |
415 } | 440 } |
416 | 441 |
417 } // namespace printing | 442 } // namespace printing |
OLD | NEW |