Improves audio support for case when process lacks MODIFY_AUDIO_SETTINGS and/or RECOR...
[chromium-blink-merge.git] / printing / printing_context_linux.cc
blob3b6d2ee9f1faca5339aa168d2c6110e8972c1517
1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "printing/printing_context_linux.h"
7 #include "base/logging.h"
8 #include "base/values.h"
9 #include "printing/metafile.h"
10 #include "printing/print_dialog_gtk_interface.h"
11 #include "printing/print_job_constants.h"
12 #include "printing/units.h"
14 namespace {
16 // Function pointer for creating print dialogs. |callback| is only used when
17 // |show_dialog| is true.
18 printing::PrintDialogGtkInterface* (*create_dialog_func_)(
19 printing::PrintingContextLinux* context) = NULL;
21 // Function pointer for determining paper size.
22 gfx::Size (*get_pdf_paper_size_)(
23 printing::PrintingContextLinux* context) = NULL;
25 } // namespace
27 namespace printing {
29 // static
30 PrintingContext* PrintingContext::Create(const std::string& app_locale) {
31 return static_cast<PrintingContext*>(new PrintingContextLinux(app_locale));
34 PrintingContextLinux::PrintingContextLinux(const std::string& app_locale)
35 : PrintingContext(app_locale),
36 print_dialog_(NULL) {
39 PrintingContextLinux::~PrintingContextLinux() {
40 ReleaseContext();
42 if (print_dialog_)
43 print_dialog_->ReleaseDialog();
46 // static
47 void PrintingContextLinux::SetCreatePrintDialogFunction(
48 PrintDialogGtkInterface* (*create_dialog_func)(
49 PrintingContextLinux* context)) {
50 DCHECK(create_dialog_func);
51 DCHECK(!create_dialog_func_);
52 create_dialog_func_ = create_dialog_func;
55 // static
56 void PrintingContextLinux::SetPdfPaperSizeFunction(
57 gfx::Size (*get_pdf_paper_size)(PrintingContextLinux* context)) {
58 DCHECK(get_pdf_paper_size);
59 DCHECK(!get_pdf_paper_size_);
60 get_pdf_paper_size_ = get_pdf_paper_size;
63 void PrintingContextLinux::PrintDocument(const Metafile* metafile) {
64 DCHECK(print_dialog_);
65 DCHECK(metafile);
66 print_dialog_->PrintDocument(metafile, document_name_);
69 void PrintingContextLinux::AskUserForSettings(
70 gfx::NativeView parent_view,
71 int max_pages,
72 bool has_selection,
73 const PrintSettingsCallback& callback) {
74 if (!print_dialog_) {
75 // Can only get here if the renderer is sending bad messages.
76 // http://crbug.com/341777
77 NOTREACHED();
78 callback.Run(FAILED);
79 return;
82 print_dialog_->ShowDialog(parent_view, has_selection, callback);
85 PrintingContext::Result PrintingContextLinux::UseDefaultSettings() {
86 DCHECK(!in_print_job_);
88 ResetSettings();
90 if (!create_dialog_func_)
91 return OK;
93 if (!print_dialog_) {
94 print_dialog_ = create_dialog_func_(this);
95 print_dialog_->AddRefToDialog();
97 print_dialog_->UseDefaultSettings();
99 return OK;
102 gfx::Size PrintingContextLinux::GetPdfPaperSizeDeviceUnits() {
103 if (get_pdf_paper_size_)
104 return get_pdf_paper_size_(this);
106 return gfx::Size();
109 PrintingContext::Result PrintingContextLinux::UpdatePrinterSettings(
110 bool external_preview) {
111 DCHECK(!in_print_job_);
112 DCHECK(!external_preview) << "Not implemented";
114 if (!create_dialog_func_)
115 return OK;
117 if (!print_dialog_) {
118 print_dialog_ = create_dialog_func_(this);
119 print_dialog_->AddRefToDialog();
122 if (!print_dialog_->UpdateSettings(&settings_))
123 return OnError();
125 return OK;
128 PrintingContext::Result PrintingContextLinux::InitWithSettings(
129 const PrintSettings& settings) {
130 DCHECK(!in_print_job_);
132 settings_ = settings;
134 return OK;
137 PrintingContext::Result PrintingContextLinux::NewDocument(
138 const base::string16& document_name) {
139 DCHECK(!in_print_job_);
140 in_print_job_ = true;
142 document_name_ = document_name;
144 return OK;
147 PrintingContext::Result PrintingContextLinux::NewPage() {
148 if (abort_printing_)
149 return CANCEL;
150 DCHECK(in_print_job_);
152 // Intentional No-op.
154 return OK;
157 PrintingContext::Result PrintingContextLinux::PageDone() {
158 if (abort_printing_)
159 return CANCEL;
160 DCHECK(in_print_job_);
162 // Intentional No-op.
164 return OK;
167 PrintingContext::Result PrintingContextLinux::DocumentDone() {
168 if (abort_printing_)
169 return CANCEL;
170 DCHECK(in_print_job_);
172 ResetSettings();
173 return OK;
176 void PrintingContextLinux::Cancel() {
177 abort_printing_ = true;
178 in_print_job_ = false;
181 void PrintingContextLinux::ReleaseContext() {
182 // Intentional No-op.
185 gfx::NativeDrawingContext PrintingContextLinux::context() const {
186 // Intentional No-op.
187 return NULL;
190 } // namespace printing