2015-04-30 03:31:17 +00:00
|
|
|
// Copyright (c) 2015 GitHub, Inc.
|
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/utility/electron_content_utility_client.h"
|
2015-04-30 03:31:17 +00:00
|
|
|
|
2018-10-13 01:57:04 +00:00
|
|
|
#include <utility>
|
|
|
|
|
|
|
|
#include "base/command_line.h"
|
2019-07-24 22:58:51 +00:00
|
|
|
#include "base/no_destructor.h"
|
2019-01-21 18:20:22 +00:00
|
|
|
#include "content/public/utility/utility_thread.h"
|
2019-08-02 23:56:46 +00:00
|
|
|
#include "mojo/public/cpp/bindings/service_factory.h"
|
2021-11-24 08:45:59 +00:00
|
|
|
#include "sandbox/policy/mojom/sandbox.mojom.h"
|
|
|
|
#include "sandbox/policy/sandbox_type.h"
|
2019-07-24 22:58:51 +00:00
|
|
|
#include "services/proxy_resolver/proxy_resolver_factory_impl.h"
|
2018-10-04 18:08:56 +00:00
|
|
|
#include "services/proxy_resolver/public/mojom/proxy_resolver.mojom.h"
|
2019-01-21 21:38:23 +00:00
|
|
|
#include "services/service_manager/public/cpp/service.h"
|
2022-10-20 05:49:49 +00:00
|
|
|
#include "shell/services/node/node_service.h"
|
|
|
|
#include "shell/services/node/public/mojom/node_service.mojom.h"
|
2020-07-14 01:13:34 +00:00
|
|
|
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2020-07-14 01:13:34 +00:00
|
|
|
#include "chrome/services/util_win/public/mojom/util_read_icon.mojom.h"
|
|
|
|
#include "chrome/services/util_win/util_read_icon.h"
|
2022-02-10 02:58:52 +00:00
|
|
|
#endif // BUILDFLAG(IS_WIN)
|
2018-10-13 01:57:04 +00:00
|
|
|
|
|
|
|
#if BUILDFLAG(ENABLE_PRINTING)
|
2020-01-17 18:41:52 +00:00
|
|
|
#include "components/services/print_compositor/print_compositor_impl.h"
|
2020-04-29 06:16:10 +00:00
|
|
|
#include "components/services/print_compositor/public/mojom/print_compositor.mojom.h" // nogncheck
|
2020-07-14 01:13:34 +00:00
|
|
|
#endif // BUILDFLAG(ENABLE_PRINTING)
|
2018-10-04 18:08:56 +00:00
|
|
|
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(ENABLE_PRINTING) && BUILDFLAG(IS_WIN)
|
2018-10-13 01:57:04 +00:00
|
|
|
#include "chrome/services/printing/pdf_to_emf_converter_factory.h"
|
2020-07-14 01:13:34 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if BUILDFLAG(ENABLE_PRINT_PREVIEW) || \
|
2022-02-10 02:58:52 +00:00
|
|
|
(BUILDFLAG(ENABLE_PRINTING) && BUILDFLAG(IS_WIN))
|
2020-07-14 01:13:34 +00:00
|
|
|
#include "chrome/services/printing/printing_service.h"
|
|
|
|
#include "chrome/services/printing/public/mojom/printing_service.mojom.h"
|
|
|
|
#endif
|
2015-04-30 03:31:17 +00:00
|
|
|
|
|
|
|
namespace electron {
|
|
|
|
|
2019-01-21 21:38:23 +00:00
|
|
|
namespace {
|
|
|
|
|
2020-07-14 01:13:34 +00:00
|
|
|
#if BUILDFLAG(ENABLE_PRINT_PREVIEW) || \
|
2022-02-10 02:58:52 +00:00
|
|
|
(BUILDFLAG(ENABLE_PRINTING) && BUILDFLAG(IS_WIN))
|
2019-08-15 20:50:58 +00:00
|
|
|
auto RunPrintingService(
|
|
|
|
mojo::PendingReceiver<printing::mojom::PrintingService> receiver) {
|
|
|
|
return std::make_unique<printing::PrintingService>(std::move(receiver));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2020-07-14 01:13:34 +00:00
|
|
|
auto RunWindowsIconReader(
|
|
|
|
mojo::PendingReceiver<chrome::mojom::UtilReadIcon> receiver) {
|
|
|
|
return std::make_unique<UtilReadIcon>(std::move(receiver));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-08-24 01:14:23 +00:00
|
|
|
#if BUILDFLAG(ENABLE_PRINTING)
|
2020-01-17 18:41:52 +00:00
|
|
|
auto RunPrintCompositor(
|
|
|
|
mojo::PendingReceiver<printing::mojom::PrintCompositor> receiver) {
|
|
|
|
return std::make_unique<printing::PrintCompositorImpl>(
|
2019-08-24 01:14:23 +00:00
|
|
|
std::move(receiver), true /* initialize_environment */,
|
|
|
|
content::UtilityThread::Get()->GetIOTaskRunner());
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-08-02 23:56:46 +00:00
|
|
|
auto RunProxyResolver(
|
|
|
|
mojo::PendingReceiver<proxy_resolver::mojom::ProxyResolverFactory>
|
|
|
|
receiver) {
|
|
|
|
return std::make_unique<proxy_resolver::ProxyResolverFactoryImpl>(
|
|
|
|
std::move(receiver));
|
|
|
|
}
|
|
|
|
|
2022-10-20 05:49:49 +00:00
|
|
|
auto RunNodeService(mojo::PendingReceiver<node::mojom::NodeService> receiver) {
|
|
|
|
return std::make_unique<electron::NodeService>(std::move(receiver));
|
|
|
|
}
|
|
|
|
|
2019-01-21 21:38:23 +00:00
|
|
|
} // namespace
|
|
|
|
|
2022-02-10 02:58:52 +00:00
|
|
|
ElectronContentUtilityClient::ElectronContentUtilityClient() = default;
|
2015-04-30 03:31:17 +00:00
|
|
|
|
2019-09-16 22:12:00 +00:00
|
|
|
ElectronContentUtilityClient::~ElectronContentUtilityClient() = default;
|
2015-04-30 03:31:17 +00:00
|
|
|
|
2018-10-13 01:57:04 +00:00
|
|
|
// The guts of this came from the chromium implementation
|
|
|
|
// https://cs.chromium.org/chromium/src/chrome/utility/
|
|
|
|
// chrome_content_utility_client.cc?sq=package:chromium&dr=CSs&g=0&l=142
|
2019-12-11 00:22:35 +00:00
|
|
|
void ElectronContentUtilityClient::ExposeInterfacesToBrowser(
|
|
|
|
mojo::BinderMap* binders) {
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2021-11-24 08:45:59 +00:00
|
|
|
auto& cmd_line = *base::CommandLine::ForCurrentProcess();
|
|
|
|
auto sandbox_type = sandbox::policy::SandboxTypeFromCommandLine(cmd_line);
|
|
|
|
utility_process_running_elevated_ =
|
|
|
|
sandbox_type == sandbox::mojom::Sandbox::kNoSandboxAndElevatedPrivileges;
|
2020-07-14 01:13:34 +00:00
|
|
|
#endif
|
2018-10-13 01:57:04 +00:00
|
|
|
|
|
|
|
// If our process runs with elevated privileges, only add elevated Mojo
|
2019-12-11 00:22:35 +00:00
|
|
|
// interfaces to the BinderMap.
|
|
|
|
if (!utility_process_running_elevated_) {
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(ENABLE_PRINTING) && BUILDFLAG(IS_WIN)
|
2022-08-17 18:35:53 +00:00
|
|
|
binders->Add<printing::mojom::PdfToEmfConverterFactory>(
|
2018-10-13 01:57:04 +00:00
|
|
|
base::BindRepeating(printing::PdfToEmfConverterFactory::Create),
|
2023-02-03 11:43:42 +00:00
|
|
|
base::SingleThreadTaskRunner::GetCurrentDefault());
|
2018-10-13 01:57:04 +00:00
|
|
|
#endif
|
2017-04-05 03:40:43 +00:00
|
|
|
}
|
2018-10-13 01:57:04 +00:00
|
|
|
}
|
|
|
|
|
2020-11-14 00:16:56 +00:00
|
|
|
void ElectronContentUtilityClient::RegisterMainThreadServices(
|
|
|
|
mojo::ServiceFactory& services) {
|
2022-02-10 02:58:52 +00:00
|
|
|
#if BUILDFLAG(IS_WIN)
|
2020-11-14 00:16:56 +00:00
|
|
|
services.Add(RunWindowsIconReader);
|
2019-08-24 01:14:23 +00:00
|
|
|
#endif
|
2020-07-14 01:13:34 +00:00
|
|
|
|
|
|
|
#if BUILDFLAG(ENABLE_PRINTING)
|
2020-11-14 00:16:56 +00:00
|
|
|
services.Add(RunPrintCompositor);
|
2020-07-14 01:13:34 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if BUILDFLAG(ENABLE_PRINT_PREVIEW) || \
|
2022-02-10 02:58:52 +00:00
|
|
|
(BUILDFLAG(ENABLE_PRINTING) && BUILDFLAG(IS_WIN))
|
2020-11-14 00:16:56 +00:00
|
|
|
services.Add(RunPrintingService);
|
2019-08-15 20:50:58 +00:00
|
|
|
#endif
|
2022-10-20 05:49:49 +00:00
|
|
|
|
|
|
|
services.Add(RunNodeService);
|
2019-08-15 20:50:58 +00:00
|
|
|
}
|
|
|
|
|
2020-11-14 00:16:56 +00:00
|
|
|
void ElectronContentUtilityClient::RegisterIOThreadServices(
|
|
|
|
mojo::ServiceFactory& services) {
|
|
|
|
services.Add(RunProxyResolver);
|
2019-07-24 22:58:51 +00:00
|
|
|
}
|
|
|
|
|
2015-04-30 03:31:17 +00:00
|
|
|
} // namespace electron
|