Add some debugging info for PlatformAppBrowserTest.WindowsApiBounds test
[chromium-blink-merge.git] / printing / printing_context_no_system_dialog.cc
blob3cc991c8d5c73d97b659e942bc343bc50c5dc632
1 // Copyright (c) 2011 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_no_system_dialog.h"
7 #include <unicode/ulocdata.h>
9 #include "base/logging.h"
10 #include "base/values.h"
11 #include "printing/metafile.h"
12 #include "printing/print_job_constants.h"
13 #include "printing/units.h"
15 namespace printing {
17 // static
18 PrintingContext* PrintingContext::Create(const std::string& app_locale) {
19 return static_cast<PrintingContext*>(
20 new PrintingContextNoSystemDialog(app_locale));
23 PrintingContextNoSystemDialog::PrintingContextNoSystemDialog(
24 const std::string& app_locale) : PrintingContext(app_locale) {
27 PrintingContextNoSystemDialog::~PrintingContextNoSystemDialog() {
28 ReleaseContext();
31 void PrintingContextNoSystemDialog::AskUserForSettings(
32 gfx::NativeView parent_view,
33 int max_pages,
34 bool has_selection,
35 const PrintSettingsCallback& callback) {
36 // We don't want to bring up a dialog here. Ever. Just signal the callback.
37 callback.Run(OK);
40 PrintingContext::Result PrintingContextNoSystemDialog::UseDefaultSettings() {
41 DCHECK(!in_print_job_);
43 ResetSettings();
44 // TODO(abodenha): Fetch these settings from the OS where possible. See
45 // bug 102583.
46 // TODO(sanjeevr): We need a better feedback loop between the cloud print
47 // dialog and this code.
48 int dpi = 300;
49 gfx::Size physical_size_device_units;
50 gfx::Rect printable_area_device_units;
51 int32_t width = 0;
52 int32_t height = 0;
53 UErrorCode error = U_ZERO_ERROR;
54 ulocdata_getPaperSize(app_locale_.c_str(), &height, &width, &error);
55 if (error > U_ZERO_ERROR) {
56 // If the call failed, assume a paper size of 8.5 x 11 inches.
57 LOG(WARNING) << "ulocdata_getPaperSize failed, using 8.5 x 11, error: "
58 << error;
59 width = static_cast<int>(8.5 * dpi);
60 height = static_cast<int>(11 * dpi);
61 } else {
62 // ulocdata_getPaperSize returns the width and height in mm.
63 // Convert this to pixels based on the dpi.
64 width = static_cast<int>(ConvertUnitDouble(width, 25.4, 1.0) * dpi);
65 height = static_cast<int>(ConvertUnitDouble(height, 25.4, 1.0) * dpi);
68 physical_size_device_units.SetSize(width, height);
70 // Assume full page is printable for now.
71 printable_area_device_units.SetRect(0, 0, width, height);
73 settings_.set_dpi(dpi);
74 settings_.SetPrinterPrintableArea(physical_size_device_units,
75 printable_area_device_units,
76 dpi);
78 return OK;
81 PrintingContext::Result PrintingContextNoSystemDialog::UpdatePrinterSettings(
82 const DictionaryValue& job_settings, const PageRanges& ranges) {
83 bool landscape = false;
85 if (!job_settings.GetBoolean(kSettingLandscape, &landscape))
86 return OnError();
88 if (settings_.dpi() == 0)
89 UseDefaultSettings();
91 settings_.SetOrientation(landscape);
92 settings_.ranges = ranges;
94 return OK;
97 PrintingContext::Result PrintingContextNoSystemDialog::InitWithSettings(
98 const PrintSettings& settings) {
99 DCHECK(!in_print_job_);
101 settings_ = settings;
103 return OK;
106 PrintingContext::Result PrintingContextNoSystemDialog::NewDocument(
107 const string16& document_name) {
108 DCHECK(!in_print_job_);
109 in_print_job_ = true;
111 return OK;
114 PrintingContext::Result PrintingContextNoSystemDialog::NewPage() {
115 if (abort_printing_)
116 return CANCEL;
117 DCHECK(in_print_job_);
119 // Intentional No-op.
121 return OK;
124 PrintingContext::Result PrintingContextNoSystemDialog::PageDone() {
125 if (abort_printing_)
126 return CANCEL;
127 DCHECK(in_print_job_);
129 // Intentional No-op.
131 return OK;
134 PrintingContext::Result PrintingContextNoSystemDialog::DocumentDone() {
135 if (abort_printing_)
136 return CANCEL;
137 DCHECK(in_print_job_);
139 ResetSettings();
140 return OK;
143 void PrintingContextNoSystemDialog::Cancel() {
144 abort_printing_ = true;
145 in_print_job_ = false;
148 void PrintingContextNoSystemDialog::ReleaseContext() {
149 // Intentional No-op.
152 gfx::NativeDrawingContext PrintingContextNoSystemDialog::context() const {
153 // Intentional No-op.
154 return NULL;
157 } // namespace printing