diff options
Diffstat (limited to 'chromium/components/services/pdf_compositor/public/cpp')
6 files changed, 180 insertions, 0 deletions
diff --git a/chromium/components/services/pdf_compositor/public/cpp/BUILD.gn b/chromium/components/services/pdf_compositor/public/cpp/BUILD.gn new file mode 100644 index 00000000000..414da314966 --- /dev/null +++ b/chromium/components/services/pdf_compositor/public/cpp/BUILD.gn @@ -0,0 +1,34 @@ +# Copyright 2017 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") + +source_set("factory") { + sources = [ + "pdf_compositor_service_factory.cc", + "pdf_compositor_service_factory.h", + ] + + deps = [ + "//components/services/pdf_compositor/", + "//content/public/common", + "//content/public/utility", + ] + + public_deps = [ + "//components/services/pdf_compositor/public/interfaces", + "//services/service_manager/public/cpp", + ] +} + +source_set("utils") { + sources = [ + "pdf_service_mojo_utils.cc", + "pdf_service_mojo_utils.h", + ] + + public_deps = [ + "//mojo/public/cpp/system:system", + ] +} diff --git a/chromium/components/services/pdf_compositor/public/cpp/pdf_compositor_service_factory.cc b/chromium/components/services/pdf_compositor/public/cpp/pdf_compositor_service_factory.cc new file mode 100644 index 00000000000..0af223b62b1 --- /dev/null +++ b/chromium/components/services/pdf_compositor/public/cpp/pdf_compositor_service_factory.cc @@ -0,0 +1,28 @@ +// Copyright 2017 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 "components/services/pdf_compositor/public/cpp/pdf_compositor_service_factory.h" + +#include "build/build_config.h" +#include "components/services/pdf_compositor/pdf_compositor_service.h" +#include "content/public/utility/utility_thread.h" +#include "third_party/blink/public/platform/web_image_generator.h" +#include "third_party/skia/include/core/SkGraphics.h" + +namespace printing { + +std::unique_ptr<service_manager::Service> CreatePdfCompositorService( + const std::string& creator) { +#if defined(OS_POSIX) && !defined(OS_ANDROID) && !defined(OS_FUCHSIA) + content::UtilityThread::Get()->EnsureBlinkInitializedWithSandboxSupport(); +#else + content::UtilityThread::Get()->EnsureBlinkInitialized(); +#endif + // Hook up blink's codecs so skia can call them. + SkGraphics::SetImageGeneratorFromEncodedDataFactory( + blink::WebImageGenerator::CreateAsSkImageGenerator); + return printing::PdfCompositorService::Create(creator); +} + +} // namespace printing diff --git a/chromium/components/services/pdf_compositor/public/cpp/pdf_compositor_service_factory.h b/chromium/components/services/pdf_compositor/public/cpp/pdf_compositor_service_factory.h new file mode 100644 index 00000000000..371f47294a0 --- /dev/null +++ b/chromium/components/services/pdf_compositor/public/cpp/pdf_compositor_service_factory.h @@ -0,0 +1,20 @@ +// Copyright 2017 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 COMPONENTS_SERVICES_PDF_COMPOSITOR_PUBLIC_CPP_PDF_COMPOSITOR_SERVICE_FACTORY_H_ +#define COMPONENTS_SERVICES_PDF_COMPOSITOR_PUBLIC_CPP_PDF_COMPOSITOR_SERVICE_FACTORY_H_ + +#include <memory> +#include <string> + +#include "services/service_manager/public/cpp/service.h" + +namespace printing { + +std::unique_ptr<service_manager::Service> CreatePdfCompositorService( + const std::string& creator); + +} // namespace printing + +#endif // COMPONENTS_SERVICES_PDF_COMPOSITOR_PUBLIC_CPP_PDF_COMPOSITOR_SERVICE_FACTORY_H_ diff --git a/chromium/components/services/pdf_compositor/public/cpp/pdf_service_mojo_types.h b/chromium/components/services/pdf_compositor/public/cpp/pdf_service_mojo_types.h new file mode 100644 index 00000000000..dfc3b5f8e15 --- /dev/null +++ b/chromium/components/services/pdf_compositor/public/cpp/pdf_service_mojo_types.h @@ -0,0 +1,17 @@ +// Copyright 2018 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 COMPONENTS_SERVICES_PDF_COMPOSITOR_PUBLIC_CPP_PDF_SERVICE_MOJO_TYPES_H_ +#define COMPONENTS_SERVICES_PDF_COMPOSITOR_PUBLIC_CPP_PDF_SERVICE_MOJO_TYPES_H_ + +#include "base/containers/flat_map.h" + +namespace printing { + +// Create an alias for map<uint32, uint64> type. +using ContentToFrameMap = base::flat_map<uint32_t, uint64_t>; + +} // namespace printing + +#endif // COMPONENTS_SERVICES_PDF_COMPOSITOR_PUBLIC_CPP_PDF_SERVICE_MOJO_TYPES_H_ diff --git a/chromium/components/services/pdf_compositor/public/cpp/pdf_service_mojo_utils.cc b/chromium/components/services/pdf_compositor/public/cpp/pdf_service_mojo_utils.cc new file mode 100644 index 00000000000..b814cf60dfe --- /dev/null +++ b/chromium/components/services/pdf_compositor/public/cpp/pdf_service_mojo_utils.cc @@ -0,0 +1,53 @@ +// Copyright 2017 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 "components/services/pdf_compositor/public/cpp/pdf_service_mojo_utils.h" + +#include <utility> + +#include "base/memory/shared_memory.h" +#include "base/memory/writable_shared_memory_region.h" +#include "mojo/public/cpp/system/platform_handle.h" + +namespace printing { + +base::MappedReadOnlyRegion CreateReadOnlySharedMemoryRegion(size_t size) { + mojo::ScopedSharedBufferHandle handle = + mojo::SharedBufferHandle::Create(size); + base::WritableSharedMemoryRegion writable_region = + UnwrapWritableSharedMemoryRegion(std::move(handle)); + base::WritableSharedMemoryMapping mapping = writable_region.Map(); + if (!mapping.IsValid()) + return {}; + + base::ReadOnlySharedMemoryRegion readonly_region = + base::WritableSharedMemoryRegion::ConvertToReadOnly( + std::move(writable_region)); + return {std::move(readonly_region), std::move(mapping)}; +} + +std::unique_ptr<base::SharedMemory> GetShmFromMojoHandle( + mojo::ScopedSharedBufferHandle handle) { + base::SharedMemoryHandle memory_handle; + size_t memory_size = 0; + mojo::UnwrappedSharedMemoryHandleProtection protection; + + const MojoResult result = mojo::UnwrapSharedMemoryHandle( + std::move(handle), &memory_handle, &memory_size, &protection); + if (result != MOJO_RESULT_OK) + return nullptr; + + DCHECK_GT(memory_size, 0u); + const bool read_only = + protection == mojo::UnwrappedSharedMemoryHandleProtection::kReadOnly; + std::unique_ptr<base::SharedMemory> shm = + std::make_unique<base::SharedMemory>(memory_handle, read_only); + if (!shm->Map(memory_size)) { + DLOG(ERROR) << "Map shared memory failed."; + return nullptr; + } + return shm; +} + +} // namespace printing diff --git a/chromium/components/services/pdf_compositor/public/cpp/pdf_service_mojo_utils.h b/chromium/components/services/pdf_compositor/public/cpp/pdf_service_mojo_utils.h new file mode 100644 index 00000000000..1e0bd92fe1e --- /dev/null +++ b/chromium/components/services/pdf_compositor/public/cpp/pdf_service_mojo_utils.h @@ -0,0 +1,28 @@ +// Copyright 2017 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 COMPONENTS_SERVICES_PDF_COMPOSITOR_PUBLIC_CPP_PDF_SERVICE_MOJO_UTILS_H_ +#define COMPONENTS_SERVICES_PDF_COMPOSITOR_PUBLIC_CPP_PDF_SERVICE_MOJO_UTILS_H_ + +#include <memory> + +#include "base/memory/read_only_shared_memory_region.h" +#include "mojo/public/cpp/system/buffer.h" + +namespace base { +class SharedMemory; +} // namespace base + +namespace printing { + +// Similar to base::ReadOnlySharedMemoryRegion::Create(), except it works inside +// sandboxed environments. +base::MappedReadOnlyRegion CreateReadOnlySharedMemoryRegion(size_t size); + +std::unique_ptr<base::SharedMemory> GetShmFromMojoHandle( + mojo::ScopedSharedBufferHandle handle); + +} // namespace printing + +#endif // COMPONENTS_SERVICES_PDF_COMPOSITOR_PUBLIC_CPP_PDF_SERVICE_MOJO_UTILS_H_ |