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 <memory> | 7 #include <memory> |
8 #include <string> | 8 #include <string> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 18 matching lines...) Expand all Loading... |
29 #include "printing/print_job_constants.h" | 29 #include "printing/print_job_constants.h" |
30 #include "printing/printed_document.h" | 30 #include "printing/printed_document.h" |
31 #include "printing/printed_page.h" | 31 #include "printing/printed_page.h" |
32 #include "printing/printing_utils.h" | 32 #include "printing/printing_utils.h" |
33 #include "ui/base/l10n/l10n_util.h" | 33 #include "ui/base/l10n/l10n_util.h" |
34 | 34 |
35 #if defined(OS_ANDROID) | 35 #if defined(OS_ANDROID) |
36 #include "chrome/browser/android/tab_android.h" | 36 #include "chrome/browser/android/tab_android.h" |
37 #endif | 37 #endif |
38 | 38 |
| 39 #if defined(OS_WIN) |
| 40 #include "chrome/common/chrome_features.h" |
| 41 #endif |
| 42 |
39 using content::BrowserThread; | 43 using content::BrowserThread; |
40 | 44 |
41 namespace printing { | 45 namespace printing { |
42 | 46 |
43 namespace { | 47 namespace { |
44 | 48 |
45 // Helper function to ensure |owner| is valid until at least |callback| returns. | 49 // Helper function to ensure |owner| is valid until at least |callback| returns. |
46 void HoldRefCallback(const scoped_refptr<PrintJobWorkerOwner>& owner, | 50 void HoldRefCallback(const scoped_refptr<PrintJobWorkerOwner>& owner, |
47 const base::Closure& callback) { | 51 const base::Closure& callback) { |
48 callback.Run(); | 52 callback.Run(); |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 base::Bind(&HoldRefCallback, | 188 base::Bind(&HoldRefCallback, |
185 make_scoped_refptr(owner_), | 189 make_scoped_refptr(owner_), |
186 base::Bind(&PrintJobWorker::UpdatePrintSettings, | 190 base::Bind(&PrintJobWorker::UpdatePrintSettings, |
187 base::Unretained(this), | 191 base::Unretained(this), |
188 base::Passed(&new_settings)))); | 192 base::Passed(&new_settings)))); |
189 } | 193 } |
190 | 194 |
191 void PrintJobWorker::UpdatePrintSettings( | 195 void PrintJobWorker::UpdatePrintSettings( |
192 std::unique_ptr<base::DictionaryValue> new_settings) { | 196 std::unique_ptr<base::DictionaryValue> new_settings) { |
193 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 197 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 198 #if defined(OS_WIN) |
| 199 printing_context_->SetPostScriptEnabled( |
| 200 base::FeatureList::IsEnabled(features::kPostScriptPrinting)); |
| 201 #endif |
194 PrintingContext::Result result = | 202 PrintingContext::Result result = |
195 printing_context_->UpdatePrintSettings(*new_settings); | 203 printing_context_->UpdatePrintSettings(*new_settings); |
196 GetSettingsDone(result); | 204 GetSettingsDone(result); |
197 } | 205 } |
198 | 206 |
199 void PrintJobWorker::GetSettingsDone(PrintingContext::Result result) { | 207 void PrintJobWorker::GetSettingsDone(PrintingContext::Result result) { |
200 // Most PrintingContext functions may start a message loop and process | 208 // Most PrintingContext functions may start a message loop and process |
201 // message recursively, so disable recursive task processing. | 209 // message recursively, so disable recursive task processing. |
202 // TODO(thestig): See above comment. SetNestableTasksAllowed(false) needs to | 210 // TODO(thestig): See above comment. SetNestableTasksAllowed(false) needs to |
203 // be called on the same thread as the previous call. See | 211 // be called on the same thread as the previous call. See |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 | 247 |
240 // weak_factory_ creates pointers valid only on owner_ thread. | 248 // weak_factory_ creates pointers valid only on owner_ thread. |
241 printing_context_->AskUserForSettings( | 249 printing_context_->AskUserForSettings( |
242 document_page_count, has_selection, is_scripted, | 250 document_page_count, has_selection, is_scripted, |
243 base::Bind(&PostOnOwnerThread, make_scoped_refptr(owner_), | 251 base::Bind(&PostOnOwnerThread, make_scoped_refptr(owner_), |
244 base::Bind(&PrintJobWorker::GetSettingsDone, | 252 base::Bind(&PrintJobWorker::GetSettingsDone, |
245 weak_factory_.GetWeakPtr()))); | 253 weak_factory_.GetWeakPtr()))); |
246 } | 254 } |
247 | 255 |
248 void PrintJobWorker::UseDefaultSettings() { | 256 void PrintJobWorker::UseDefaultSettings() { |
| 257 #if defined(OS_WIN) |
| 258 printing_context_->SetPostScriptEnabled( |
| 259 base::FeatureList::IsEnabled(features::kPostScriptPrinting)); |
| 260 #endif |
249 PrintingContext::Result result = printing_context_->UseDefaultSettings(); | 261 PrintingContext::Result result = printing_context_->UseDefaultSettings(); |
250 GetSettingsDone(result); | 262 GetSettingsDone(result); |
251 } | 263 } |
252 | 264 |
253 void PrintJobWorker::StartPrinting(PrintedDocument* new_document) { | 265 void PrintJobWorker::StartPrinting(PrintedDocument* new_document) { |
254 DCHECK(task_runner_->RunsTasksOnCurrentThread()); | 266 DCHECK(task_runner_->RunsTasksOnCurrentThread()); |
255 DCHECK_EQ(page_number_, PageNumber::npos()); | 267 DCHECK_EQ(page_number_, PageNumber::npos()); |
256 DCHECK_EQ(document_.get(), new_document); | 268 DCHECK_EQ(document_.get(), new_document); |
257 DCHECK(document_.get()); | 269 DCHECK(document_.get()); |
258 | 270 |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
436 JobEventDetails::FAILED, 0, | 448 JobEventDetails::FAILED, 0, |
437 base::RetainedRef(document_), nullptr)); | 449 base::RetainedRef(document_), nullptr)); |
438 Cancel(); | 450 Cancel(); |
439 | 451 |
440 // Makes sure the variables are reinitialized. | 452 // Makes sure the variables are reinitialized. |
441 document_ = NULL; | 453 document_ = NULL; |
442 page_number_ = PageNumber::npos(); | 454 page_number_ = PageNumber::npos(); |
443 } | 455 } |
444 | 456 |
445 } // namespace printing | 457 } // namespace printing |
OLD | NEW |