Skip to content

Commit

Permalink
build: fix buildflags in shell/utility/electron_content_utility_clien…
Browse files Browse the repository at this point in the history
…t.cc (#25520)

Co-authored-by: Milan Burda <miburda@microsoft.com>
  • Loading branch information
miniak and Milan Burda committed Sep 21, 2020
1 parent 24691a4 commit 63688e8
Showing 1 changed file with 32 additions and 16 deletions.
48 changes: 32 additions & 16 deletions shell/utility/electron_content_utility_client.cc
Expand Up @@ -16,33 +16,43 @@
#include "services/service_manager/public/cpp/service.h"
#include "services/service_manager/sandbox/switches.h"

#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)

#if BUILDFLAG(ENABLE_PRINTING)
#include "components/services/print_compositor/print_compositor_impl.h"
#include "components/services/print_compositor/public/mojom/print_compositor.mojom.h" // nogncheck
#endif // BUILDFLAG(ENABLE_PRINTING)

#if defined(OS_WIN)
#if BUILDFLAG(ENABLE_PRINTING) && defined(OS_WIN)
#include "chrome/services/printing/pdf_to_emf_converter_factory.h"
#include "chrome/services/printing/printing_service.h"
#include "chrome/services/printing/public/mojom/printing_service.mojom.h"
#include "chrome/services/util_win/public/mojom/util_read_icon.mojom.h"
#include "chrome/services/util_win/util_read_icon.h"
#endif

#if BUILDFLAG(ENABLE_PRINT_PREVIEW) && defined(OS_WIN)
#include "chrome/utility/printing_handler.h"
#endif // defined(OS_WIN)
#endif

#endif // BUILDFLAG(ENABLE_PRINTING)
#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

namespace electron {

namespace {

#if defined(OS_WIN)
#if BUILDFLAG(ENABLE_PRINTING)
#if BUILDFLAG(ENABLE_PRINT_PREVIEW) || \
(BUILDFLAG(ENABLE_PRINTING) && defined(OS_WIN))
auto RunPrintingService(
mojo::PendingReceiver<printing::mojom::PrintingService> receiver) {
return std::make_unique<printing::PrintingService>(std::move(receiver));
}
#endif

#if defined(OS_WIN)
auto RunWindowsIconReader(
mojo::PendingReceiver<chrome::mojom::UtilReadIcon> receiver) {
return std::make_unique<UtilReadIcon>(std::move(receiver));
Expand All @@ -69,7 +79,7 @@ auto RunProxyResolver(

ElectronContentUtilityClient::ElectronContentUtilityClient()
: utility_process_running_elevated_(false) {
#if BUILDFLAG(ENABLE_PRINTING) && defined(OS_WIN)
#if BUILDFLAG(ENABLE_PRINT_PREVIEW) && defined(OS_WIN)
printing_handler_ = std::make_unique<printing::PrintingHandler>();
#endif
}
Expand All @@ -85,25 +95,25 @@ void ElectronContentUtilityClient::ExposeInterfacesToBrowser(
base::CommandLine* command_line = base::CommandLine::ForCurrentProcess();
utility_process_running_elevated_ = command_line->HasSwitch(
service_manager::switches::kNoSandboxAndElevatedPrivileges);
#endif

// If our process runs with elevated privileges, only add elevated Mojo
// interfaces to the BinderMap.
if (!utility_process_running_elevated_) {
#if BUILDFLAG(ENABLE_PRINTING)
#if BUILDFLAG(ENABLE_PRINTING) && defined(OS_WIN)
binders->Add(
base::BindRepeating(printing::PdfToEmfConverterFactory::Create),
base::ThreadTaskRunnerHandle::Get());
#endif
}
#endif
}

bool ElectronContentUtilityClient::OnMessageReceived(
const IPC::Message& message) {
if (utility_process_running_elevated_)
return false;

#if BUILDFLAG(ENABLE_PRINTING) && defined(OS_WIN)
#if BUILDFLAG(ENABLE_PRINT_PREVIEW) && defined(OS_WIN)
if (printing_handler_->OnMessageReceived(message))
return true;
#endif
Expand All @@ -114,11 +124,17 @@ bool ElectronContentUtilityClient::OnMessageReceived(
mojo::ServiceFactory*
ElectronContentUtilityClient::GetMainThreadServiceFactory() {
static base::NoDestructor<mojo::ServiceFactory> factory {
#if BUILDFLAG(ENABLE_PRINTING)
RunPrintCompositor,
#if defined(OS_WIN)
RunPrintingService, RunWindowsIconReader
RunWindowsIconReader,
#endif

#if BUILDFLAG(ENABLE_PRINTING)
RunPrintCompositor,
#endif

#if BUILDFLAG(ENABLE_PRINT_PREVIEW) || \
(BUILDFLAG(ENABLE_PRINTING) && defined(OS_WIN))
RunPrintingService,
#endif
};
return factory.get();
Expand Down

0 comments on commit 63688e8

Please sign in to comment.