Commit e86ec5b6 authored by Alan Screen's avatar Alan Screen Committed by Commit Bot

Introduce print backend mojom with Paper struct

Adding support for PrintBackend queries to happen out of the browser
process requires related data structures to be made available via a Mojo
interface.  These are moved into their own mojom file separate from the
common definition in printing/mojom since they are specific to a new
process being introduced and do not need to be encumbered by the
dependencies which exist for print.mojom.

Starting with the historically most prolific cause of browser crashes
from printing (GetPrinterSemanticCapsAndDefaults), work towards having
support definitions to enable that query to be moved out-of-process.

Start with a mojo definition for the
printing::PrinterSemanticCapsAndDefaults::Paper structure, which is
required for the larger query.

Bug: 809738
Change-Id: Id7d52f131f8587b9edc50c8e1c4f8b6718998965
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2387409Reviewed-by: default avatarRobert Sesek <rsesek@chromium.org>
Reviewed-by: default avatarKen Rockot <rockot@google.com>
Reviewed-by: default avatarDaniel Hosseinian <dhoss@chromium.org>
Reviewed-by: default avatarLei Zhang <thestig@chromium.org>
Commit-Queue: Alan Screen <awscreen@chromium.org>
Cr-Commit-Position: refs/heads/master@{#812424}
parent 928785ea
...@@ -325,6 +325,7 @@ static_library("test_support") { ...@@ -325,6 +325,7 @@ static_library("test_support") {
test("printing_unittests") { test("printing_unittests") {
sources = [ sources = [
"backend/mojom/print_backend_mojom_traits_unittest.cc",
"metafile_skia_unittest.cc", "metafile_skia_unittest.cc",
"nup_parameters_unittest.cc", "nup_parameters_unittest.cc",
"page_number_unittest.cc", "page_number_unittest.cc",
...@@ -340,8 +341,10 @@ test("printing_unittests") { ...@@ -340,8 +341,10 @@ test("printing_unittests") {
configs += [ "//build/config/compiler:noshadowing" ] configs += [ "//build/config/compiler:noshadowing" ]
deps = [ deps = [
":printing", ":printing",
"//base/test:run_all_unittests",
"//base/test:test_support", "//base/test:test_support",
"//mojo/core/test:run_all_unittests",
"//mojo/public/cpp/test_support:test_utils",
"//printing/backend/mojom",
"//printing/common", "//printing/common",
"//printing/mojom", "//printing/mojom",
"//testing/gmock", "//testing/gmock",
......
include_rules = [ include_rules = [
"+cc/paint", "+cc/paint",
"+mojo/public",
"+printing/printing_jni_headers", "+printing/printing_jni_headers",
"+skia/ext", "+skia/ext",
"+third_party/icu/source/common/unicode", "+third_party/icu/source/common/unicode",
......
# Copyright 2020 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import("//mojo/public/tools/bindings/mojom.gni")
mojom("mojom") {
sources = [ "print_backend.mojom" ]
deps = [ "//ui/gfx/geometry/mojom" ]
cpp_typemaps = [
{
types = [
{
mojom = "printing.mojom.Paper"
cpp = "::printing::PrinterSemanticCapsAndDefaults::Paper"
},
]
traits_sources = [ "print_backend_mojom_traits.cc" ]
traits_headers = [ "print_backend_mojom_traits.h" ]
},
]
}
per-file *.mojom=set noparent
per-file *.mojom=file://ipc/SECURITY_OWNERS
per-file *_mojom_traits*.*=set noparent
per-file *_mojom_traits*.*=file://ipc/SECURITY_OWNERS
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
module printing.mojom;
import "ui/gfx/geometry/mojom/geometry.mojom";
// Paper used by printer semantic capabilities and defaults.
struct Paper {
string display_name;
string vendor_id;
gfx.mojom.Size size_um;
};
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "printing/backend/mojom/print_backend_mojom_traits.h"
#include "ui/gfx/geometry/mojom/geometry.mojom-shared.h"
#include "ui/gfx/geometry/mojom/geometry_mojom_traits.h"
namespace mojo {
// static
bool StructTraits<printing::mojom::PaperDataView,
printing::PrinterSemanticCapsAndDefaults::Paper>::
Read(printing::mojom::PaperDataView data,
printing::PrinterSemanticCapsAndDefaults::Paper* out) {
return data.ReadDisplayName(&out->display_name) &&
data.ReadVendorId(&out->vendor_id) && data.ReadSizeUm(&out->size_um);
}
} // namespace mojo
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef PRINTING_BACKEND_MOJOM_PRINT_BACKEND_MOJOM_TRAITS_H_
#define PRINTING_BACKEND_MOJOM_PRINT_BACKEND_MOJOM_TRAITS_H_
#include <string>
#include "printing/backend/mojom/print_backend.mojom-shared.h"
#include "printing/backend/print_backend.h"
#include "ui/gfx/geometry/size.h"
namespace mojo {
template <>
struct StructTraits<printing::mojom::PaperDataView,
printing::PrinterSemanticCapsAndDefaults::Paper> {
static const std::string& display_name(
const printing::PrinterSemanticCapsAndDefaults::Paper& p) {
return p.display_name;
}
static const std::string& vendor_id(
const printing::PrinterSemanticCapsAndDefaults::Paper& p) {
return p.vendor_id;
}
static const gfx::Size& size_um(
const printing::PrinterSemanticCapsAndDefaults::Paper& p) {
return p.size_um;
}
static bool Read(printing::mojom::PaperDataView data,
printing::PrinterSemanticCapsAndDefaults::Paper* out);
};
} // namespace mojo
#endif // PRINTING_BACKEND_MOJOM_PRINT_BACKEND_MOJOM_TRAITS_H_
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "mojo/public/cpp/test_support/test_utils.h"
#include "printing/backend/mojom/print_backend.mojom.h"
#include "printing/backend/print_backend.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/gfx/geometry/size.h"
namespace printing {
namespace {
const printing::PrinterSemanticCapsAndDefaults::Paper kPaperA3{
/*display_name=*/"A3", /*vendor_id=*/"67",
/*size_um=*/gfx::Size(7016, 9921)};
const printing::PrinterSemanticCapsAndDefaults::Paper kPaperA4{
/*display_name=*/"A4", /*vendor_id=*/"12",
/*size_um=*/gfx::Size(4961, 7016)};
const printing::PrinterSemanticCapsAndDefaults::Paper kPaperLetter{
/*display_name=*/"Letter", /*vendor_id=*/"45",
/*size_um=*/gfx::Size(5100, 6600)};
const printing::PrinterSemanticCapsAndDefaults::Paper kPaperLedger{
/*display_name=*/"Ledger", /*vendor_id=*/"89",
/*size_um=*/gfx::Size(6600, 10200)};
} // namespace
TEST(PrintBackendMojomTraitsTest, TestSerializeAndDeserializePaper) {
const printing::PrinterSemanticCapsAndDefaults::Papers kPapers{
kPaperA3, kPaperA4, kPaperLetter, kPaperLedger};
for (const auto& paper : kPapers) {
printing::PrinterSemanticCapsAndDefaults::Paper input = paper;
printing::PrinterSemanticCapsAndDefaults::Paper output;
EXPECT_TRUE(mojo::test::SerializeAndDeserialize<printing::mojom::Paper>(
&input, &output));
EXPECT_EQ(paper, output);
}
}
} // namespace printing
...@@ -37,6 +37,12 @@ AdvancedCapability::~AdvancedCapability() = default; ...@@ -37,6 +37,12 @@ AdvancedCapability::~AdvancedCapability() = default;
#endif // defined(OS_CHROMEOS) #endif // defined(OS_CHROMEOS)
bool PrinterSemanticCapsAndDefaults::Paper::operator==(
const PrinterSemanticCapsAndDefaults::Paper& other) const {
return display_name == other.display_name && vendor_id == other.vendor_id &&
size_um == other.size_um;
}
PrinterSemanticCapsAndDefaults::PrinterSemanticCapsAndDefaults() = default; PrinterSemanticCapsAndDefaults::PrinterSemanticCapsAndDefaults() = default;
PrinterSemanticCapsAndDefaults::PrinterSemanticCapsAndDefaults( PrinterSemanticCapsAndDefaults::PrinterSemanticCapsAndDefaults(
......
...@@ -105,10 +105,12 @@ struct PRINTING_EXPORT PrinterSemanticCapsAndDefaults { ...@@ -105,10 +105,12 @@ struct PRINTING_EXPORT PrinterSemanticCapsAndDefaults {
mojom::ColorModel color_model = mojom::ColorModel::kUnknownColorModel; mojom::ColorModel color_model = mojom::ColorModel::kUnknownColorModel;
mojom::ColorModel bw_model = mojom::ColorModel::kUnknownColorModel; mojom::ColorModel bw_model = mojom::ColorModel::kUnknownColorModel;
struct Paper { struct PRINTING_EXPORT Paper {
std::string display_name; std::string display_name;
std::string vendor_id; std::string vendor_id;
gfx::Size size_um; gfx::Size size_um;
bool operator==(const Paper& other) const;
}; };
using Papers = std::vector<Paper>; using Papers = std::vector<Paper>;
Papers papers; Papers papers;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment