chromium/components/services/print_compositor/print_compositor_impl.cc

// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "components/services/print_compositor/print_compositor_impl.h"

#include <tuple>
#include <utility>

#include "base/containers/contains.h"
#include "base/logging.h"
#include "base/memory/discardable_memory.h"
#include "base/ranges/algorithm.h"
#include "base/task/single_thread_task_runner.h"
#include "base/trace_event/trace_event.h"
#include "build/build_config.h"
#include "components/crash/core/common/crash_key.h"
#include "components/discardable_memory/client/client_discardable_shared_memory_manager.h"
#include "components/enterprise/buildflags/buildflags.h"
#include "components/services/print_compositor/public/cpp/print_service_mojo_types.h"
#include "content/public/utility/utility_thread.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/system/platform_handle.h"
#include "printing/common/metafile_utils.h"
#include "printing/mojom/print.mojom.h"
#include "skia/ext/font_utils.h"
#include "third_party/blink/public/platform/web_image_generator.h"
#include "third_party/skia/include/core/SkCanvas.h"
#include "third_party/skia/include/core/SkDocument.h"
#include "third_party/skia/include/core/SkGraphics.h"
#include "third_party/skia/include/core/SkSerialProcs.h"
#include "third_party/skia/include/docs/SkMultiPictureDocument.h"
#include "ui/accessibility/ax_tree_update.h"

#if BUILDFLAG(IS_WIN)
#include "content/public/child/dwrite_font_proxy_init_win.h"
#include "printing/backend/win_helper.h"  // nogncheck
#elif BUILDFLAG(IS_APPLE)
#include "third_party/blink/public/platform/platform.h"
#include "third_party/skia/include/core/SkFontMgr.h"
#elif BUILDFLAG(IS_POSIX) && !BUILDFLAG(IS_ANDROID)
#include "third_party/blink/public/platform/platform.h"
#endif

#if BUILDFLAG(ENTERPRISE_WATERMARK)
#include "components/enterprise/watermarking/features.h"  // nogncheck
#include "components/enterprise/watermarking/watermark.h"  // nogncheck
#endif

MojoDiscardableSharedMemoryManager;

namespace printing {

namespace {

#if BUILDFLAG(ENTERPRISE_WATERMARK)
// Print UX requirement for watermarking. Values are in pixels.
constexpr int kWatermarkBlockWidth =;
constexpr float kTextSize =;
#endif

sk_sp<SkDocument> MakeDocument(
    const std::string& creator,
    const std::string& title,
    ui::AXTreeUpdate* accessibility_tree,
    mojom::GenerateDocumentOutline generate_document_outline,
    mojom::PrintCompositor::DocumentType document_type,
    SkWStream& stream) {}

#if BUILDFLAG(ENTERPRISE_WATERMARK)
void DrawEnterpriseWatermark(SkCanvas* canvas, SkSize size) {}
#endif

void DrawPage(SkDocument* doc, const SkDocumentPage& page) {}

}  // namespace

PrintCompositorImpl::PrintCompositorImpl(
    mojo::PendingReceiver<mojom::PrintCompositor> receiver,
    bool initialize_environment,
    scoped_refptr<base::SingleThreadTaskRunner> io_task_runner)
    :{}

PrintCompositorImpl::~PrintCompositorImpl() {}

void PrintCompositorImpl::NotifyUnavailableSubframe(uint64_t frame_guid) {}

void PrintCompositorImpl::AddSubframeContent(
    uint64_t frame_guid,
    base::ReadOnlySharedMemoryRegion serialized_content,
    const ContentToFrameMap& subframe_content_map) {}

void PrintCompositorImpl::SetAccessibilityTree(
    const ui::AXTreeUpdate& accessibility_tree) {}

void PrintCompositorImpl::CompositePage(
    uint64_t frame_guid,
    base::ReadOnlySharedMemoryRegion serialized_content,
    const ContentToFrameMap& subframe_content_map,
    mojom::PrintCompositor::CompositePageCallback callback) {}

void PrintCompositorImpl::CompositeDocument(
    uint64_t frame_guid,
    base::ReadOnlySharedMemoryRegion serialized_content,
    const ContentToFrameMap& subframe_content_map,
    mojom::PrintCompositor::DocumentType document_type,
    mojom::PrintCompositor::CompositeDocumentCallback callback) {}

void PrintCompositorImpl::PrepareToCompositeDocument(
    mojom::PrintCompositor::DocumentType document_type,
    mojom::PrintCompositor::PrepareToCompositeDocumentCallback callback) {}

void PrintCompositorImpl::FinishDocumentComposition(
    uint32_t page_count,
    mojom::PrintCompositor::FinishDocumentCompositionCallback callback) {}

void PrintCompositorImpl::SetWebContentsURL(const GURL& url) {}

void PrintCompositorImpl::SetUserAgent(const std::string& user_agent) {}

void PrintCompositorImpl::UpdateRequestsWithSubframeInfo(
    uint64_t frame_guid,
    const std::vector<uint64_t>& pending_subframes) {}

bool PrintCompositorImpl::IsReadyToComposite(
    uint64_t frame_guid,
    const ContentToFrameMap& subframe_content_map,
    base::flat_set<uint64_t>* pending_subframes) const {}

void PrintCompositorImpl::CheckFramesForReadiness(
    const ContentToFrameMap& subframe_content_map,
    base::flat_set<uint64_t>* pending_subframes,
    base::flat_set<uint64_t>* visited) const {}

void PrintCompositorImpl::HandleCompositionRequest(
    uint64_t frame_guid,
    base::ReadOnlySharedMemoryRegion serialized_content,
    const ContentToFrameMap& subframe_content_map,
    mojom::PrintCompositor::DocumentType document_type,
    CompositePagesCallback callback) {}

void PrintCompositorImpl::HandleDocumentCompletionRequest() {}

mojom::PrintCompositor::Status PrintCompositorImpl::CompositePages(
    base::span<const uint8_t> serialized_content,
    const ContentToFrameMap& subframe_content_map,
    base::ReadOnlySharedMemoryRegion* region,
    mojom::PrintCompositor::DocumentType document_type) {}

void PrintCompositorImpl::CompositeSubframe(FrameInfo* frame_info) {}

PrintCompositorImpl::PictureDeserializationContext
PrintCompositorImpl::GetPictureDeserializationContext(
    const ContentToFrameMap& subframe_content_map) {}

void PrintCompositorImpl::FulfillRequest(
    base::span<const uint8_t> serialized_content,
    const ContentToFrameMap& subframe_content_map,
    mojom::PrintCompositor::DocumentType document_type,
    CompositePagesCallback callback) {}

void PrintCompositorImpl::FinishDocumentRequest(
    FinishDocumentCompositionCallback callback) {}

PrintCompositorImpl::FrameContentInfo::FrameContentInfo(
    base::span<const uint8_t> content,
    const ContentToFrameMap& map)
    :{}

PrintCompositorImpl::FrameContentInfo::FrameContentInfo() = default;

PrintCompositorImpl::FrameContentInfo::~FrameContentInfo() = default;

// TODO(crbug.com/40100562) Make use of `document_type` parameter once
// `MakeXpsDocument()` is available.
PrintCompositorImpl::DocumentInfo::DocumentInfo(
    mojom::PrintCompositor::DocumentType document_type)
    :{}

PrintCompositorImpl::DocumentInfo::~DocumentInfo() = default;

PrintCompositorImpl::RequestInfo::RequestInfo(
    base::span<const uint8_t> content,
    const ContentToFrameMap& content_info,
    const base::flat_set<uint64_t>& pending_subframes,
    mojom::PrintCompositor::DocumentType document_type,
    mojom::PrintCompositor::CompositePageCallback callback)
    :{}

PrintCompositorImpl::RequestInfo::~RequestInfo() = default;

void PrintCompositorImpl::SetGenerateDocumentOutline(
    mojom::GenerateDocumentOutline generate_document_outline) {}

void PrintCompositorImpl::SetTitle(const std::string& title) {}

}  // namespace printing