Commit e1abed93 authored by Julie Jeongeun Kim's avatar Julie Jeongeun Kim Committed by Commit Bot

[printing] Move printing::SkiaDocumentType to //printing/mojom/print.mojom

This CL moves printing::SkiaDocumentType to print.mojom to pass it
to Mojo interfaces. This is a precursor CL to mojofy
PrintHostMsg_GetDefaultPrintSettings.

Bug: 1008939
Change-Id: Id4622825e97443dd7d96c65ac9d28a8c8fb9c552
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2231922Reviewed-by: default avatarSam McNally <sammc@chromium.org>
Reviewed-by: default avatarDave Tapuska <dtapuska@chromium.org>
Reviewed-by: default avatarLei Zhang <thestig@chromium.org>
Reviewed-by: default avatarKinuko Yasuda <kinuko@chromium.org>
Commit-Queue: Julie Kim <jkim@igalia.com>
Cr-Commit-Position: refs/heads/master@{#777309}
parent 096c2f90
......@@ -41,6 +41,7 @@
#include "mojo/public/cpp/bindings/associated_remote.h"
#include "net/dns/mock_host_resolver.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
#include "printing/mojom/print.mojom.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h"
#include "third_party/blink/public/common/scheduler/web_scheduler_tracked_feature.h"
......@@ -133,8 +134,8 @@ class NupPrintingTestDelegate : public PrintingMessageFilter::TestDelegate {
params.dpi = gfx::Size(72, 72);
params.document_cookie = kDefaultDocumentCookie;
params.pages_per_sheet = 4;
params.printed_doc_type =
IsOopifEnabled() ? SkiaDocumentType::MSKP : SkiaDocumentType::PDF;
params.printed_doc_type = IsOopifEnabled() ? mojom::SkiaDocumentType::kMSKP
: mojom::SkiaDocumentType::kPDF;
return params;
}
......
......@@ -20,6 +20,7 @@
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/render_process_host.h"
#include "content/public/browser/service_process_host.h"
#include "printing/common/metafile_utils.h"
#include "printing/printing_utils.h"
#include "third_party/blink/public/common/associated_interfaces/associated_interface_provider.h"
......
......@@ -7,6 +7,7 @@
#include "components/printing/browser/print_composite_client.h"
#include "components/printing/common/print_messages.h"
#include "content/public/browser/site_isolation_policy.h"
#include "printing/mojom/print.mojom.h"
#include "printing/print_settings.h"
namespace printing {
......@@ -68,8 +69,8 @@ void RenderParamsFromPrintSettings(const PrintSettings& settings,
params->title = settings.title();
params->url = settings.url();
params->printed_doc_type = IsOopifEnabled() && settings.is_modifiable()
? SkiaDocumentType::MSKP
: SkiaDocumentType::PDF;
? mojom::SkiaDocumentType::kMSKP
: mojom::SkiaDocumentType::kPDF;
params->pages_per_sheet = settings.pages_per_sheet();
}
......
......@@ -79,7 +79,7 @@ PrintMsg_Print_Params::PrintMsg_Print_Params()
print_to_pdf(false),
display_header_footer(false),
should_print_backgrounds(false),
printed_doc_type(printing::SkiaDocumentType::PDF),
printed_doc_type(printing::mojom::SkiaDocumentType::kPDF),
prefer_css_page_size(false),
pages_per_sheet(1) {}
......@@ -112,7 +112,7 @@ void PrintMsg_Print_Params::Reset() {
header_template = base::string16();
footer_template = base::string16();
should_print_backgrounds = false;
printed_doc_type = printing::SkiaDocumentType::PDF;
printed_doc_type = printing::mojom::SkiaDocumentType::kPDF;
prefer_css_page_size = false;
pages_per_sheet = 1;
}
......
......@@ -18,7 +18,6 @@
#include "components/printing/common/printing_param_traits_macros.h"
#include "ipc/ipc_message_macros.h"
#include "printing/buildflags/buildflags.h"
#include "printing/common/metafile_utils.h"
#include "printing/mojom/print.mojom.h"
#include "printing/page_range.h"
#include "printing/print_job_constants.h"
......@@ -62,7 +61,7 @@ struct PrintMsg_Print_Params {
base::string16 header_template;
base::string16 footer_template;
bool should_print_backgrounds;
printing::SkiaDocumentType printed_doc_type;
printing::mojom::SkiaDocumentType printed_doc_type;
bool prefer_css_page_size;
int pages_per_sheet;
};
......@@ -106,8 +105,8 @@ struct PrintHostMsg_PreviewIds {
IPC_ENUM_TRAITS_MAX_VALUE(printing::mojom::PrintScalingOption,
printing::mojom::PrintScalingOption::kMaxValue)
IPC_ENUM_TRAITS_MAX_VALUE(printing::SkiaDocumentType,
printing::SkiaDocumentType::MAX)
IPC_ENUM_TRAITS_MAX_VALUE(printing::mojom::SkiaDocumentType,
printing::mojom::SkiaDocumentType::kMaxValue)
// Parameters for a render request.
IPC_STRUCT_TRAITS_BEGIN(PrintMsg_Print_Params)
......
......@@ -1344,7 +1344,8 @@ void PrintRenderFrameHelper::PrintFrameContent(
if (!weak_this)
return;
MetafileSkia metafile(SkiaDocumentType::MSKP, params->document_cookie);
MetafileSkia metafile(mojom::SkiaDocumentType::kMSKP,
params->document_cookie);
gfx::Size area_size = params->printable_area.size();
// Since GetVectorCanvasForNewPage() starts a new recording, it will return
// a valid canvas.
......@@ -1492,7 +1493,7 @@ PrintRenderFrameHelper::CreatePreviewDocument() {
bool require_document_metafile =
print_renderer_ ||
print_params.printed_doc_type != SkiaDocumentType::MSKP;
print_params.printed_doc_type != mojom::SkiaDocumentType::kMSKP;
if (!print_preview_context_.CreatePreviewDocument(
std::move(prep_frame_view_), pages, print_params.printed_doc_type,
print_params.document_cookie, require_document_metafile)) {
......@@ -1549,7 +1550,8 @@ PrintRenderFrameHelper::CreatePreviewDocument() {
return CREATE_IN_PROGRESS;
}
if (print_pages_params_->params.printed_doc_type == SkiaDocumentType::MSKP) {
if (print_pages_params_->params.printed_doc_type ==
mojom::SkiaDocumentType::kMSKP) {
// Want modifiable content of MSKP type to be collected into a document
// during individual page preview generation (to avoid separate document
// version for composition), notify to prepare to do this collection.
......@@ -2522,7 +2524,7 @@ void PrintRenderFrameHelper::PrintPreviewContext::OnPrintPreview() {
bool PrintRenderFrameHelper::PrintPreviewContext::CreatePreviewDocument(
std::unique_ptr<PrepareFrameAndViewForPrint> prepared_frame,
const std::vector<int>& pages,
SkiaDocumentType doc_type,
mojom::SkiaDocumentType doc_type,
int document_cookie,
bool require_document_metafile) {
DCHECK_EQ(INITIALIZED, state_);
......
......@@ -480,7 +480,7 @@ class PrintRenderFrameHelper
bool CreatePreviewDocument(
std::unique_ptr<PrepareFrameAndViewForPrint> prepared_frame,
const std::vector<int>& pages,
SkiaDocumentType doc_type,
mojom::SkiaDocumentType doc_type,
int document_cookie,
bool require_document_metafile);
......
......@@ -177,6 +177,7 @@ static_library("web_test_renderer") {
"//gpu/command_buffer/client:gles2_interface",
"//media/capture",
"//printing",
"//printing/mojom",
"//services/device/public/mojom",
"//skia",
"//skia:test_fonts",
......
......@@ -20,6 +20,7 @@
#include "content/shell/renderer/web_test/web_test_runtime_flags.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "printing/metafile_skia.h"
#include "printing/mojom/print.mojom.h"
#include "printing/print_settings.h"
#include "services/service_manager/public/cpp/interface_provider.h"
#include "skia/ext/platform_canvas.h"
......@@ -64,7 +65,7 @@ void CapturePixelsForPrinting(
return;
}
printing::MetafileSkia metafile(printing::SkiaDocumentType::MSKP,
printing::MetafileSkia metafile(printing::mojom::SkiaDocumentType::kMSKP,
printing::PrintSettings::NewCookie());
cc::SkiaPaintCanvas canvas(bitmap);
canvas.SetPrintingMetafile(&metafile);
......
......@@ -19,13 +19,6 @@ namespace printing {
using ContentToProxyIdMap = base::flat_map<uint32_t, int>;
enum class SkiaDocumentType {
PDF,
// MSKP is an experimental, fragile, and diagnostic-only document type.
MSKP,
MAX = MSKP
};
// Stores the mapping between a content's unique id and its actual content.
using DeserializationContext = base::flat_map<uint32_t, sk_sp<SkPicture>>;
......
......@@ -83,7 +83,7 @@ struct MetafileSkiaData {
// meaningful for a vector canvas as for a raster canvas.
float scale_factor;
SkSize size;
SkiaDocumentType type;
mojom::SkiaDocumentType type;
#if defined(OS_MACOSX)
PdfMetafileCg pdf_cg;
......@@ -91,10 +91,10 @@ struct MetafileSkiaData {
};
MetafileSkia::MetafileSkia() : data_(std::make_unique<MetafileSkiaData>()) {
data_->type = SkiaDocumentType::PDF;
data_->type = mojom::SkiaDocumentType::kPDF;
}
MetafileSkia::MetafileSkia(SkiaDocumentType type, int document_cookie)
MetafileSkia::MetafileSkia(mojom::SkiaDocumentType type, int document_cookie)
: data_(std::make_unique<MetafileSkiaData>()) {
data_->type = type;
data_->document_cookie = document_cookie;
......@@ -196,10 +196,10 @@ bool MetafileSkia::FinishDocument() {
sk_sp<SkDocument> doc;
cc::PlaybackParams::CustomDataRasterCallback custom_callback;
switch (data_->type) {
case SkiaDocumentType::PDF:
case mojom::SkiaDocumentType::kPDF:
doc = MakePdfDocument(printing::GetAgent(), accessibility_tree_, &stream);
break;
case SkiaDocumentType::MSKP:
case mojom::SkiaDocumentType::kMSKP:
SkSerialProcs procs = SerializationProcs(&data_->subframe_content_info);
doc = SkMakeMultiPictureDocument(&stream, &procs);
// It is safe to use base::Unretained(this) because the callback
......@@ -227,7 +227,7 @@ void MetafileSkia::FinishFrameContent() {
// content.
DCHECK_EQ(data_->pages.size(), 1u);
// Also make sure it is in skia multi-picture document format.
DCHECK_EQ(data_->type, SkiaDocumentType::MSKP);
DCHECK_EQ(data_->type, mojom::SkiaDocumentType::kMSKP);
DCHECK(!data_->data_stream);
cc::PlaybackParams::CustomDataRasterCallback custom_callback =
......@@ -360,7 +360,7 @@ bool MetafileSkia::SaveTo(base::File* file) const {
#endif // defined(OS_ANDROID)
std::unique_ptr<MetafileSkia> MetafileSkia::GetMetafileForCurrentPage(
SkiaDocumentType type) {
mojom::SkiaDocumentType type) {
// If we only ever need the metafile for the last page, should we
// only keep a handle on one PaintRecord?
auto metafile = std::make_unique<MetafileSkia>(type, data_->document_cookie);
......
......@@ -15,6 +15,7 @@
#include "cc/paint/paint_canvas.h"
#include "printing/common/metafile_utils.h"
#include "printing/metafile.h"
#include "printing/mojom/print.mojom-forward.h"
#include "skia/ext/platform_canvas.h"
#include "ui/accessibility/ax_tree_update.h"
......@@ -29,11 +30,11 @@ struct MetafileSkiaData;
// This class uses Skia graphics library to generate a PDF or MSKP document.
class PRINTING_EXPORT MetafileSkia : public Metafile {
public:
// Default constructor, for SkiaDocumentType::PDF type only.
// Default constructor, for mojom::SkiaDocumentType::kPDF type only.
// TODO(weili): we should split up this use case into a different class, see
// comments before InitFromData()'s implementation.
MetafileSkia();
MetafileSkia(SkiaDocumentType type, int document_cookie);
MetafileSkia(mojom::SkiaDocumentType type, int document_cookie);
~MetafileSkia() override;
// Metafile methods.
......@@ -80,7 +81,7 @@ class PRINTING_EXPORT MetafileSkia : public Metafile {
// Return a new metafile containing just the current page in draft mode.
std::unique_ptr<MetafileSkia> GetMetafileForCurrentPage(
SkiaDocumentType type);
mojom::SkiaDocumentType type);
// This method calls StartPage and then returns an appropriate
// PlatformCanvas implementation bound to the context created by
......
......@@ -6,6 +6,7 @@
#include "cc/paint/paint_record.h"
#include "printing/common/metafile_utils.h"
#include "printing/mojom/print.mojom.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/skia/include/core/SkPictureRecorder.h"
......@@ -31,7 +32,7 @@ TEST(MetafileSkiaTest, TestFrameContent) {
SkSize page_size = SkSize::Make(kPageSideLen, kPageSideLen);
// Finish creating the entire metafile.
MetafileSkia metafile(SkiaDocumentType::MSKP, 1);
MetafileSkia metafile(mojom::SkiaDocumentType::kMSKP, 1);
metafile.AppendPage(page_size, std::move(record));
metafile.AppendSubframeInfo(content_id, 2, std::move(pic_holder));
metafile.FinishFrameContent();
......
......@@ -41,3 +41,12 @@ enum PrintScalingOption {
// Reduces or enlarges each page to fit the selected printer paper size.
kFitToPaper,
};
// Document type that Skia graphics library generates.
enum SkiaDocumentType {
// PDF document type.
kPDF,
// MultiPictureDocument type. kMSKP is an experimental, fragile, and
// diagnostic-only document type.
kMSKP,
};
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