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.
|
|
|
|
|
2020-02-04 20:19:40 +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 21:38:23 +00:00
|
|
|
#include "base/threading/sequenced_task_runner_handle.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"
|
2020-07-14 01:13:34 +00:00
|
|
|
#include "sandbox/policy/switches.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"
|
2020-07-14 01:13:34 +00:00
|
|
|
|
|
|
|
#if defined(OS_WIN)
|
|
|
|
#include "chrome/services/util_win/public/mojom/util_read_icon.mojom.h"
|
|
|
|
#include "chrome/services/util_win/util_read_icon.h"
|
|
|
|
#endif // defined(OS_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
|
|
|
|
2020-07-14 01:13:34 +00:00
|
|
|
#if BUILDFLAG(ENABLE_PRINTING) && defined(OS_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) && defined(OS_WIN)
|
2018-10-13 01:57:04 +00:00
|
|
|
#include "chrome/utility/printing_handler.h"
|
2020-07-14 01:13:34 +00:00
|
|
|
#endif
|
2018-10-13 01:57:04 +00:00
|
|
|
|
2020-07-14 01:13:34 +00:00
|
|
|
#if BUILDFLAG(ENABLE_PRINT_PREVIEW) || \
|
|
|
|
(BUILDFLAG(ENABLE_PRINTING) && defined(OS_WIN))
|
|
|
|
#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
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
namespace electron {
|
2015-04-30 03:31:17 +00:00
|
|
|
|
2019-01-21 21:38:23 +00:00
|
|
|
namespace {
|
|
|
|
|
2020-07-14 01:13:34 +00:00
|
|
|
#if BUILDFLAG(ENABLE_PRINT_PREVIEW) || \
|
|
|
|
(BUILDFLAG(ENABLE_PRINTING) && defined(OS_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
|
|
|
|
|
2020-07-14 01:13:34 +00:00
|
|
|
#if defined(OS_WIN)
|
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
2019-01-21 21:38:23 +00:00
|
|
|
} // namespace
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
ElectronContentUtilityClient::ElectronContentUtilityClient()
|
2019-12-11 00:22:35 +00:00
|
|
|
: utility_process_running_elevated_(false) {
|
2020-07-14 01:13:34 +00:00
|
|
|
#if BUILDFLAG(ENABLE_PRINT_PREVIEW) && defined(OS_WIN)
|
2018-10-13 01:57:04 +00:00
|
|
|
printing_handler_ = std::make_unique<printing::PrintingHandler>();
|
2015-05-04 12:58:48 +00:00
|
|
|
#endif
|
2015-04-30 03:31:17 +00:00
|
|
|
}
|
|
|
|
|
2020-02-04 20:19:40 +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
|
2020-02-04 20:19:40 +00:00
|
|
|
void ElectronContentUtilityClient::ExposeInterfacesToBrowser(
|
2019-12-11 00:22:35 +00:00
|
|
|
mojo::BinderMap* binders) {
|
2017-04-05 03:40:43 +00:00
|
|
|
#if defined(OS_WIN)
|
2018-10-13 01:57:04 +00:00
|
|
|
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
|
2019-12-11 00:22:35 +00:00
|
|
|
utility_process_running_elevated_ = command_line->HasSwitch(
|
2020-07-14 01:13:34 +00:00
|
|
|
sandbox::policy::switches::kNoSandboxAndElevatedPrivileges);
|
|
|
|
#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_) {
|
2020-07-14 01:13:34 +00:00
|
|
|
#if BUILDFLAG(ENABLE_PRINTING) && defined(OS_WIN)
|
2019-12-11 00:22:35 +00:00
|
|
|
binders->Add(
|
2018-10-13 01:57:04 +00:00
|
|
|
base::BindRepeating(printing::PdfToEmfConverterFactory::Create),
|
|
|
|
base::ThreadTaskRunnerHandle::Get());
|
|
|
|
#endif
|
2017-04-05 03:40:43 +00:00
|
|
|
}
|
2018-10-13 01:57:04 +00:00
|
|
|
}
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
bool ElectronContentUtilityClient::OnMessageReceived(
|
|
|
|
const IPC::Message& message) {
|
2019-12-11 00:22:35 +00:00
|
|
|
if (utility_process_running_elevated_)
|
2018-10-13 01:57:04 +00:00
|
|
|
return false;
|
|
|
|
|
2020-07-14 01:13:34 +00:00
|
|
|
#if BUILDFLAG(ENABLE_PRINT_PREVIEW) && defined(OS_WIN)
|
2018-10-13 01:57:04 +00:00
|
|
|
if (printing_handler_->OnMessageReceived(message))
|
|
|
|
return true;
|
2017-04-05 03:40:43 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
mojo::ServiceFactory*
|
|
|
|
ElectronContentUtilityClient::GetMainThreadServiceFactory() {
|
2019-08-15 20:50:58 +00:00
|
|
|
static base::NoDestructor<mojo::ServiceFactory> factory {
|
2019-08-24 01:14:23 +00:00
|
|
|
#if defined(OS_WIN)
|
2020-07-14 01:13:34 +00:00
|
|
|
RunWindowsIconReader,
|
2019-08-24 01:14:23 +00:00
|
|
|
#endif
|
2020-07-14 01:13:34 +00:00
|
|
|
|
|
|
|
#if BUILDFLAG(ENABLE_PRINTING)
|
|
|
|
RunPrintCompositor,
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if BUILDFLAG(ENABLE_PRINT_PREVIEW) || \
|
|
|
|
(BUILDFLAG(ENABLE_PRINTING) && defined(OS_WIN))
|
|
|
|
RunPrintingService,
|
2019-08-15 20:50:58 +00:00
|
|
|
#endif
|
|
|
|
};
|
|
|
|
return factory.get();
|
|
|
|
}
|
|
|
|
|
2020-02-04 20:19:40 +00:00
|
|
|
mojo::ServiceFactory*
|
|
|
|
ElectronContentUtilityClient::GetIOThreadServiceFactory() {
|
2019-08-02 23:56:46 +00:00
|
|
|
static base::NoDestructor<mojo::ServiceFactory> factory{RunProxyResolver};
|
|
|
|
return factory.get();
|
2019-07-24 22:58:51 +00:00
|
|
|
}
|
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
} // namespace electron
|