blob: af6f53bff28c1c4287c409b56e7eef4598370709 [file] [log] [blame]
Alan Screenf2fbeb7a2021-08-28 05:27:381// Copyright 2021 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.
4
5#include "printing/test_printing_context.h"
6
7#include <memory>
8#include <utility>
9
10#include "base/check.h"
11#include "base/containers/flat_map.h"
12#include "base/notreached.h"
13#include "base/strings/utf_string_conversions.h"
Alan Screen597675382021-09-11 05:14:5314#include "build/build_config.h"
Alan Screen202e49a2021-09-21 06:34:2815#include "printing/mojom/print.mojom.h"
Alan Screenf2fbeb7a2021-08-28 05:27:3816#include "printing/print_settings.h"
17#include "printing/printing_context.h"
18#include "ui/gfx/geometry/size.h"
19
20namespace printing {
21
22TestPrintingContextDelegate::TestPrintingContextDelegate() = default;
23
24TestPrintingContextDelegate::~TestPrintingContextDelegate() = default;
25
26gfx::NativeView TestPrintingContextDelegate::GetParentView() {
27 return nullptr;
28}
29
30std::string TestPrintingContextDelegate::GetAppLocale() {
31 return std::string();
32}
33
34TestPrintingContext::TestPrintingContext(Delegate* delegate)
35 : PrintingContext(delegate) {}
36
37TestPrintingContext::~TestPrintingContext() = default;
38
39void TestPrintingContext::SetDeviceSettings(
40 const std::string& device_name,
41 std::unique_ptr<PrintSettings> settings) {
42 device_settings_.emplace(device_name, std::move(settings));
43}
44
45void TestPrintingContext::AskUserForSettings(int max_pages,
46 bool has_selection,
47 bool is_scripted,
48 PrintSettingsCallback callback) {
49 NOTIMPLEMENTED();
50}
51
Alan Screen202e49a2021-09-21 06:34:2852mojom::ResultCode TestPrintingContext::UseDefaultSettings() {
Alan Screenf2fbeb7a2021-08-28 05:27:3853 NOTIMPLEMENTED();
Alan Screen202e49a2021-09-21 06:34:2854 return mojom::ResultCode::kFailed;
Alan Screenf2fbeb7a2021-08-28 05:27:3855}
56
57gfx::Size TestPrintingContext::GetPdfPaperSizeDeviceUnits() {
58 NOTIMPLEMENTED();
59 return gfx::Size();
60}
61
Alan Screen202e49a2021-09-21 06:34:2862mojom::ResultCode TestPrintingContext::UpdatePrinterSettings(
Lei Zhanga3fdad442021-11-15 23:55:3363 const PrinterSettings& printer_settings) {
Alan Screenf2fbeb7a2021-08-28 05:27:3864 DCHECK(!in_print_job_);
Lei Zhanga3fdad442021-11-15 23:55:3365#if defined(OS_MAC)
66 DCHECK(!printer_settings.external_preview) << "Not implemented";
67#endif
68 DCHECK(!printer_settings.show_system_dialog) << "Not implemented";
Alan Screenf2fbeb7a2021-08-28 05:27:3869
70 // The printer name is to be embedded in the printing context's existing
71 // settings.
72 const std::string& device_name = base::UTF16ToUTF8(settings_->device_name());
73 auto found = device_settings_.find(device_name);
74 if (found == device_settings_.end()) {
75 DLOG(ERROR) << "No such device found in test printing context: `"
76 << device_name << "`";
Alan Screen202e49a2021-09-21 06:34:2877 return mojom::ResultCode::kFailed;
Alan Screenf2fbeb7a2021-08-28 05:27:3878 }
79
Alan Screen597675382021-09-11 05:14:5380 // Perform some initialization, akin to various platform-specific actions in
81 // `InitPrintSettings()`.
Alan Screenf2fbeb7a2021-08-28 05:27:3882 DVLOG(1) << "Updating context settings for device `" << device_name << "`";
Alan Screen597675382021-09-11 05:14:5383 std::unique_ptr<PrintSettings> existing_settings = std::move(settings_);
84 settings_ = std::make_unique<PrintSettings>(*found->second);
85 settings_->set_dpi(existing_settings->dpi());
86#if defined(OS_LINUX) || defined(OS_CHROMEOS)
87 for (const auto& item : existing_settings->advanced_settings())
88 settings_->advanced_settings().emplace(item.first, item.second.Clone());
89#endif
90
Alan Screen202e49a2021-09-21 06:34:2891 return mojom::ResultCode::kSuccess;
Alan Screenf2fbeb7a2021-08-28 05:27:3892}
93
Alan Screen202e49a2021-09-21 06:34:2894mojom::ResultCode TestPrintingContext::NewDocument(
Alan Screenf2fbeb7a2021-08-28 05:27:3895 const std::u16string& document_name) {
Alan Screen2166ab12021-09-01 23:09:2596 // No-op.
Alan Screen202e49a2021-09-21 06:34:2897 return mojom::ResultCode::kSuccess;
Alan Screenf2fbeb7a2021-08-28 05:27:3898}
99
Alan Screen202e49a2021-09-21 06:34:28100mojom::ResultCode TestPrintingContext::NewPage() {
Alan Screenf2fbeb7a2021-08-28 05:27:38101 NOTIMPLEMENTED();
Alan Screen202e49a2021-09-21 06:34:28102 return mojom::ResultCode::kFailed;
Alan Screenf2fbeb7a2021-08-28 05:27:38103}
104
Alan Screen202e49a2021-09-21 06:34:28105mojom::ResultCode TestPrintingContext::PageDone() {
Alan Screenf2fbeb7a2021-08-28 05:27:38106 NOTIMPLEMENTED();
Alan Screen202e49a2021-09-21 06:34:28107 return mojom::ResultCode::kFailed;
Alan Screenf2fbeb7a2021-08-28 05:27:38108}
109
Alan Screen202e49a2021-09-21 06:34:28110mojom::ResultCode TestPrintingContext::DocumentDone() {
Alan Screenf2fbeb7a2021-08-28 05:27:38111 NOTIMPLEMENTED();
Alan Screen202e49a2021-09-21 06:34:28112 return mojom::ResultCode::kFailed;
Alan Screenf2fbeb7a2021-08-28 05:27:38113}
114
115void TestPrintingContext::Cancel() {
116 NOTIMPLEMENTED();
117}
118void TestPrintingContext::ReleaseContext() {}
119
120printing::NativeDrawingContext TestPrintingContext::context() const {
121 NOTIMPLEMENTED();
122 return nullptr;
123}
124
125#if defined(OS_WIN)
Alan Screen202e49a2021-09-21 06:34:28126mojom::ResultCode TestPrintingContext::InitWithSettingsForTest(
Alan Screenf2fbeb7a2021-08-28 05:27:38127 std::unique_ptr<PrintSettings> settings) {
128 NOTIMPLEMENTED();
Alan Screen202e49a2021-09-21 06:34:28129 return mojom::ResultCode::kFailed;
Alan Screenf2fbeb7a2021-08-28 05:27:38130}
131#endif // defined(OS_WIN)
132
133} // namespace printing