0

Migrate Cloud Print utility messages to Mojo

These are the last remaining legacy IPC messages sent to or from any
utility process.

Bug: 993189
Change-Id: If231f7eaa9986deced8149a9095b31007945ab50
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2953763
Reviewed-by: Avi Drissman <avi@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
Commit-Queue: Ken Rockot <rockot@google.com>
Cr-Commit-Position: refs/heads/master@{#891777}
This commit is contained in:
Ken Rockot
2021-06-11 20:28:11 +00:00
committed by Chromium LUCI CQ
parent 5f58fb11f8
commit adf0045afd
21 changed files with 200 additions and 264 deletions

@ -395,7 +395,7 @@ static_library("common") {
}
if (is_win) {
sources += [
"chrome_utility_printing_messages.h",
"chrome_utility_printing_param_traits_macros.h",
"service_process_util_win.cc",
]
@ -793,3 +793,25 @@ mojom("offline_page_auto_fetcher_mojom") {
sources = [ "offline_page_auto_fetcher.mojom" ]
public_deps = [ "//url/mojom:url_mojom_gurl" ]
}
if (enable_basic_printing && is_win) {
mojom("cloud_print_utility_mojom") {
sources = [ "cloud_print_utility.mojom" ]
cpp_typemaps = [
{
types = [
{
mojom = "chrome.mojom.PrinterCapsAndDefaults"
cpp = "::printing::PrinterCapsAndDefaults"
},
{
mojom = "chrome.mojom.PrinterSemanticCapsAndDefaults"
cpp = "::printing::PrinterSemanticCapsAndDefaults"
},
]
traits_headers = [ "chrome_utility_printing_param_traits_macros.h" ]
traits_public_deps = [ ":common" ]
},
]
}
}

@ -1,105 +0,0 @@
// Copyright 2014 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 CHROME_COMMON_CHROME_UTILITY_PRINTING_MESSAGES_H_
#define CHROME_COMMON_CHROME_UTILITY_PRINTING_MESSAGES_H_
#include <string>
#include "build/build_config.h"
#include "ipc/ipc_message_macros.h"
#include "ipc/ipc_message_start.h"
#include "ipc/ipc_param_traits.h"
#include "printing/backend/print_backend.h"
#include "printing/buildflags/buildflags.h"
#include "printing/mojom/print.mojom.h"
#define IPC_MESSAGE_START ChromeUtilityPrintingMsgStart
#if defined(OS_WIN) && BUILDFLAG(ENABLE_PRINT_PREVIEW)
// Preview and Cloud Print messages.
IPC_STRUCT_TRAITS_BEGIN(printing::PrinterCapsAndDefaults)
IPC_STRUCT_TRAITS_MEMBER(printer_capabilities)
IPC_STRUCT_TRAITS_MEMBER(caps_mime_type)
IPC_STRUCT_TRAITS_MEMBER(printer_defaults)
IPC_STRUCT_TRAITS_MEMBER(defaults_mime_type)
IPC_STRUCT_TRAITS_END()
IPC_ENUM_TRAITS_MAX_VALUE(printing::mojom::ColorModel,
printing::mojom::ColorModel::kColorModelLast)
IPC_STRUCT_TRAITS_BEGIN(printing::PrinterSemanticCapsAndDefaults::Paper)
IPC_STRUCT_TRAITS_MEMBER(display_name)
IPC_STRUCT_TRAITS_MEMBER(vendor_id)
IPC_STRUCT_TRAITS_MEMBER(size_um)
IPC_STRUCT_TRAITS_END()
IPC_ENUM_TRAITS_MIN_MAX_VALUE(printing::mojom::DuplexMode,
printing::mojom::DuplexMode::kUnknownDuplexMode,
printing::mojom::DuplexMode::kShortEdge)
IPC_STRUCT_TRAITS_BEGIN(printing::PrinterSemanticCapsAndDefaults)
IPC_STRUCT_TRAITS_MEMBER(collate_capable)
IPC_STRUCT_TRAITS_MEMBER(collate_default)
IPC_STRUCT_TRAITS_MEMBER(copies_max)
IPC_STRUCT_TRAITS_MEMBER(duplex_modes)
IPC_STRUCT_TRAITS_MEMBER(duplex_default)
IPC_STRUCT_TRAITS_MEMBER(color_changeable)
IPC_STRUCT_TRAITS_MEMBER(color_default)
IPC_STRUCT_TRAITS_MEMBER(color_model)
IPC_STRUCT_TRAITS_MEMBER(bw_model)
IPC_STRUCT_TRAITS_MEMBER(papers)
IPC_STRUCT_TRAITS_MEMBER(default_paper)
IPC_STRUCT_TRAITS_MEMBER(dpis)
IPC_STRUCT_TRAITS_MEMBER(default_dpi)
IPC_STRUCT_TRAITS_END()
//------------------------------------------------------------------------------
// Utility process messages:
// These are messages from the browser to the utility process.
// Tells the utility process to get capabilities and defaults for the specified
// printer. Used on Windows to isolate the service process from printer driver
// crashes by executing this in a separate process. This does not run in a
// sandbox.
IPC_MESSAGE_CONTROL1(ChromeUtilityMsg_GetPrinterCapsAndDefaults,
std::string /* printer name */)
// Tells the utility process to get capabilities and defaults for the specified
// printer. Used on Windows to isolate the service process from printer driver
// crashes by executing this in a separate process. This does not run in a
// sandbox. Returns result as printing::PrinterSemanticCapsAndDefaults.
IPC_MESSAGE_CONTROL1(ChromeUtilityMsg_GetPrinterSemanticCapsAndDefaults,
std::string /* printer name */)
//------------------------------------------------------------------------------
// Utility process host messages:
// These are messages from the utility process to the browser.
// Reply when the utility process has succeeded in obtaining the printer
// capabilities and defaults.
IPC_MESSAGE_CONTROL2(ChromeUtilityHostMsg_GetPrinterCapsAndDefaults_Succeeded,
std::string /* printer name */,
printing::PrinterCapsAndDefaults)
// Reply when the utility process has succeeded in obtaining the printer
// semantic capabilities and defaults.
IPC_MESSAGE_CONTROL2(
ChromeUtilityHostMsg_GetPrinterSemanticCapsAndDefaults_Succeeded,
std::string /* printer name */,
printing::PrinterSemanticCapsAndDefaults)
// Reply when the utility process has failed to obtain the printer
// capabilities and defaults.
IPC_MESSAGE_CONTROL1(ChromeUtilityHostMsg_GetPrinterCapsAndDefaults_Failed,
std::string /* printer name */)
// Reply when the utility process has failed to obtain the printer
// semantic capabilities and defaults.
IPC_MESSAGE_CONTROL1(
ChromeUtilityHostMsg_GetPrinterSemanticCapsAndDefaults_Failed,
std::string /* printer name */)
#endif // defined(OS_WIN) && BUILDFLAG(ENABLE_PRINT_PREVIEW)
#endif // CHROME_COMMON_CHROME_UTILITY_PRINTING_MESSAGES_H_

@ -0,0 +1,56 @@
// Copyright 2014 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 CHROME_COMMON_CHROME_UTILITY_PRINTING_PARAM_TRAITS_MACROS_H_
#define CHROME_COMMON_CHROME_UTILITY_PRINTING_PARAM_TRAITS_MACROS_H_
#include "build/build_config.h"
#include "ipc/ipc_message_macros.h"
#include "ipc/ipc_message_start.h"
#include "ipc/ipc_param_traits.h"
#include "printing/backend/print_backend.h"
#include "printing/buildflags/buildflags.h"
#include "printing/mojom/print.mojom.h"
#if defined(OS_WIN) && BUILDFLAG(ENABLE_PRINT_PREVIEW)
// Preview and Cloud Print messages.
IPC_STRUCT_TRAITS_BEGIN(printing::PrinterCapsAndDefaults)
IPC_STRUCT_TRAITS_MEMBER(printer_capabilities)
IPC_STRUCT_TRAITS_MEMBER(caps_mime_type)
IPC_STRUCT_TRAITS_MEMBER(printer_defaults)
IPC_STRUCT_TRAITS_MEMBER(defaults_mime_type)
IPC_STRUCT_TRAITS_END()
IPC_ENUM_TRAITS_MAX_VALUE(printing::mojom::ColorModel,
printing::mojom::ColorModel::kColorModelLast)
IPC_STRUCT_TRAITS_BEGIN(printing::PrinterSemanticCapsAndDefaults::Paper)
IPC_STRUCT_TRAITS_MEMBER(display_name)
IPC_STRUCT_TRAITS_MEMBER(vendor_id)
IPC_STRUCT_TRAITS_MEMBER(size_um)
IPC_STRUCT_TRAITS_END()
IPC_ENUM_TRAITS_MIN_MAX_VALUE(printing::mojom::DuplexMode,
printing::mojom::DuplexMode::kUnknownDuplexMode,
printing::mojom::DuplexMode::kShortEdge)
IPC_STRUCT_TRAITS_BEGIN(printing::PrinterSemanticCapsAndDefaults)
IPC_STRUCT_TRAITS_MEMBER(collate_capable)
IPC_STRUCT_TRAITS_MEMBER(collate_default)
IPC_STRUCT_TRAITS_MEMBER(copies_max)
IPC_STRUCT_TRAITS_MEMBER(duplex_modes)
IPC_STRUCT_TRAITS_MEMBER(duplex_default)
IPC_STRUCT_TRAITS_MEMBER(color_changeable)
IPC_STRUCT_TRAITS_MEMBER(color_default)
IPC_STRUCT_TRAITS_MEMBER(color_model)
IPC_STRUCT_TRAITS_MEMBER(bw_model)
IPC_STRUCT_TRAITS_MEMBER(papers)
IPC_STRUCT_TRAITS_MEMBER(default_paper)
IPC_STRUCT_TRAITS_MEMBER(dpis)
IPC_STRUCT_TRAITS_MEMBER(default_dpi)
IPC_STRUCT_TRAITS_END()
#endif // defined(OS_WIN) && BUILDFLAG(ENABLE_PRINT_PREVIEW)
#endif // CHROME_COMMON_CHROME_UTILITY_PRINTING_PARAM_TRAITS_MACROS_H_

@ -0,0 +1,29 @@
// Copyright 2021 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.
module chrome.mojom;
// Interface implemented by the unsandboxed Cloud Print utility process (see
// src/chrome/utility/printing_handler.cc) and called by the Cloud Print service
// process, which is a special Windows service process run by the deprecated
// Cloud Print Connector tool. The purpose of the utility process is to isolate
// printer driver crashes from the service process.
interface CloudPrintUtility {
// Retrieves capabilities and defaults for the specified printer. Returns null
// on failure.
GetPrinterCapsAndDefaults(string printer_name)
=> (PrinterCapsAndDefaults? caps_and_defaults);
// Retrieves capabilities and defaults for the specified printer. Returns null
// on failure.
GetPrinterSemanticCapsAndDefaults(string printer_name)
=> (PrinterSemanticCapsAndDefaults? caps_and_defaults);
};
[Native]
struct PrinterCapsAndDefaults;
[Native]
struct PrinterSemanticCapsAndDefaults;

@ -14,11 +14,11 @@
#include "printing/buildflags/buildflags.h"
#if BUILDFLAG(ENABLE_PRINTING)
#undef CHROME_COMMON_CHROME_UTILITY_PRINTING_MESSAGES_H_
#include "chrome/common/chrome_utility_printing_messages.h"
#ifndef CHROME_COMMON_CHROME_UTILITY_PRINTING_MESSAGES_H_
#undef CHROME_COMMON_CHROME_UTILITY_PRINTING_PARAM_TRAITS_MACROS_H_
#include "chrome/common/chrome_utility_printing_param_traits_macros.h"
#ifndef CHROME_COMMON_CHROME_UTILITY_PRINTING_PARAM_TRAITS_MACROS_H_
#error \
"Failed to include header chrome/common/chrome_utility_printing_messages.h"
"Failed to include header chrome/common/chrome_utility_printing_param_traits_macros.h"
#endif
#endif

@ -95,6 +95,9 @@ static_library("service") {
"service_utility_process_host.h",
"service_utility_process_host_receiver_bindings.cc",
]
deps += [ "//sandbox/win:sandbox" ]
deps += [
"//chrome/common:cloud_print_utility_mojom",
"//sandbox/win:sandbox",
]
}
}

@ -28,7 +28,7 @@
#include "base/win/win_util.h"
#include "build/build_config.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/common/chrome_utility_printing_messages.h"
#include "chrome/common/cloud_print_utility.mojom.h"
#include "chrome/services/printing/public/mojom/pdf_to_emf_converter.mojom.h"
#include "content/public/common/child_process_host.h"
#include "content/public/common/content_switches.h"
@ -221,6 +221,8 @@ ServiceUtilityProcessHost::ServiceUtilityProcessHost(
waiting_for_reply_(false) {
child_process_host_ =
ChildProcessHost::Create(this, ChildProcessHost::IpcMode::kNormal);
child_process_host_->BindReceiver(
cloud_print_utility_remote_.BindNewPipeAndPassReceiver());
}
ServiceUtilityProcessHost::~ServiceUtilityProcessHost() {
@ -267,7 +269,11 @@ bool ServiceUtilityProcessHost::StartGetPrinterCapsAndDefaults(
return false;
DCHECK(!waiting_for_reply_);
waiting_for_reply_ = true;
return Send(new ChromeUtilityMsg_GetPrinterCapsAndDefaults(printer_name));
cloud_print_utility_remote_->GetPrinterCapsAndDefaults(
printer_name,
base::BindOnce(&ServiceUtilityProcessHost::OnGetPrinterCapsAndDefaults,
base::Unretained(this), printer_name));
return true;
}
bool ServiceUtilityProcessHost::StartGetPrinterSemanticCapsAndDefaults(
@ -276,8 +282,12 @@ bool ServiceUtilityProcessHost::StartGetPrinterSemanticCapsAndDefaults(
return false;
DCHECK(!waiting_for_reply_);
waiting_for_reply_ = true;
return Send(
new ChromeUtilityMsg_GetPrinterSemanticCapsAndDefaults(printer_name));
cloud_print_utility_remote_->GetPrinterSemanticCapsAndDefaults(
printer_name,
base::BindOnce(
&ServiceUtilityProcessHost::OnGetPrinterSemanticCapsAndDefaults,
base::Unretained(this), printer_name));
return true;
}
bool ServiceUtilityProcessHost::StartProcess(bool sandbox) {
@ -287,10 +297,6 @@ bool ServiceUtilityProcessHost::StartProcess(bool sandbox) {
return false;
}
// NOTE: This call to |CreateChannelMojo()| requires a working
// ServiceManagerConnection to have already been established.
child_process_host_->CreateChannelMojo();
base::CommandLine cmd_line(exe_path);
cmd_line.AppendSwitchASCII(switches::kProcessType, switches::kUtilityProcess);
cmd_line.AppendSwitch(switches::kLang);
@ -357,13 +363,6 @@ bool ServiceUtilityProcessHost::Launch(base::CommandLine* cmd_line,
return true;
}
bool ServiceUtilityProcessHost::Send(IPC::Message* msg) {
if (child_process_host_)
return child_process_host_->Send(msg);
delete msg;
return false;
}
base::FilePath ServiceUtilityProcessHost::GetUtilityProcessCmd() {
return ChildProcessHost::GetChildPath(ChildProcessHost::CHILD_NORMAL);
}
@ -381,22 +380,7 @@ void ServiceUtilityProcessHost::OnChildDisconnected() {
}
bool ServiceUtilityProcessHost::OnMessageReceived(const IPC::Message& message) {
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(ServiceUtilityProcessHost, message)
IPC_MESSAGE_HANDLER(
ChromeUtilityHostMsg_GetPrinterCapsAndDefaults_Succeeded,
OnGetPrinterCapsAndDefaultsSucceeded)
IPC_MESSAGE_HANDLER(ChromeUtilityHostMsg_GetPrinterCapsAndDefaults_Failed,
OnGetPrinterCapsAndDefaultsFailed)
IPC_MESSAGE_HANDLER(
ChromeUtilityHostMsg_GetPrinterSemanticCapsAndDefaults_Succeeded,
OnGetPrinterSemanticCapsAndDefaultsSucceeded)
IPC_MESSAGE_HANDLER(
ChromeUtilityHostMsg_GetPrinterSemanticCapsAndDefaults_Failed,
OnGetPrinterSemanticCapsAndDefaultsFailed)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
return handled;
return false;
}
const base::Process& ServiceUtilityProcessHost::GetProcess() {
@ -448,52 +432,33 @@ void ServiceUtilityProcessHost::OnPDFToEmfFinished(bool success) {
delete this;
}
void ServiceUtilityProcessHost::OnGetPrinterCapsAndDefaultsSucceeded(
void ServiceUtilityProcessHost::OnGetPrinterCapsAndDefaults(
const std::string& printer_name,
const printing::PrinterCapsAndDefaults& caps_and_defaults) {
const absl::optional<printing::PrinterCapsAndDefaults>& caps_and_defaults) {
DCHECK(waiting_for_reply_);
waiting_for_reply_ = false;
client_task_runner_->PostTask(
FROM_HERE,
base::BindOnce(&Client::OnGetPrinterCapsAndDefaults, client_.get(), true,
printer_name, caps_and_defaults));
base::BindOnce(
&Client::OnGetPrinterCapsAndDefaults, client_.get(),
caps_and_defaults.has_value(), printer_name,
caps_and_defaults.value_or(printing::PrinterCapsAndDefaults())));
// The child process disconnects itself and this host deletes itself via
// OnChildDisconnected().
}
void ServiceUtilityProcessHost::OnGetPrinterSemanticCapsAndDefaultsSucceeded(
void ServiceUtilityProcessHost::OnGetPrinterSemanticCapsAndDefaults(
const std::string& printer_name,
const printing::PrinterSemanticCapsAndDefaults& caps_and_defaults) {
const absl::optional<printing::PrinterSemanticCapsAndDefaults>&
caps_and_defaults) {
DCHECK(waiting_for_reply_);
waiting_for_reply_ = false;
client_task_runner_->PostTask(
FROM_HERE,
base::BindOnce(&Client::OnGetPrinterSemanticCapsAndDefaults,
client_.get(), true, printer_name, caps_and_defaults));
// The child process disconnects itself and this host deletes itself via
// OnChildDisconnected().
}
void ServiceUtilityProcessHost::OnGetPrinterCapsAndDefaultsFailed(
const std::string& printer_name) {
DCHECK(waiting_for_reply_);
waiting_for_reply_ = false;
client_task_runner_->PostTask(
FROM_HERE,
base::BindOnce(&Client::OnGetPrinterCapsAndDefaults, client_.get(), false,
printer_name, printing::PrinterCapsAndDefaults()));
// The child process disconnects itself and this host deletes itself via
// OnChildDisconnected().
}
void ServiceUtilityProcessHost::OnGetPrinterSemanticCapsAndDefaultsFailed(
const std::string& printer_name) {
DCHECK(waiting_for_reply_);
waiting_for_reply_ = false;
client_task_runner_->PostTask(
FROM_HERE, base::BindOnce(&Client::OnGetPrinterSemanticCapsAndDefaults,
client_.get(), false, printer_name,
printing::PrinterSemanticCapsAndDefaults()));
client_.get(), caps_and_defaults.has_value(), printer_name,
caps_and_defaults.value_or(
printing::PrinterSemanticCapsAndDefaults())));
// The child process disconnects itself and this host deletes itself via
// OnChildDisconnected().
}

@ -11,10 +11,12 @@
#include "base/macros.h"
#include "base/memory/ref_counted.h"
#include "base/memory/weak_ptr.h"
#include "chrome/common/cloud_print_utility.mojom.h"
#include "chrome/services/printing/public/mojom/pdf_to_emf_converter.mojom.h"
#include "content/public/common/child_process_host_delegate.h"
#include "ipc/ipc_platform_file.h"
#include "mojo/public/cpp/bindings/pending_remote.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
namespace base {
class CommandLine;
@ -112,8 +114,6 @@ class ServiceUtilityProcessHost : public content::ChildProcessHostDelegate {
bool StartGetPrinterSemanticCapsAndDefaults(const std::string& printer_name);
protected:
bool Send(IPC::Message* msg);
// Allows this method to be overridden for tests.
virtual base::FilePath GetUtilityProcessCmd();
@ -143,19 +143,19 @@ class ServiceUtilityProcessHost : public content::ChildProcessHostDelegate {
base::ReadOnlySharedMemoryRegion emf_region,
float scale_factor);
// IPC Messages handlers:
void OnGetPrinterCapsAndDefaultsSucceeded(
// IPC response handlers:
void OnGetPrinterCapsAndDefaults(
const std::string& printer_name,
const printing::PrinterCapsAndDefaults& caps_and_defaults);
void OnGetPrinterCapsAndDefaultsFailed(const std::string& printer_name);
void OnGetPrinterSemanticCapsAndDefaultsSucceeded(
const absl::optional<printing::PrinterCapsAndDefaults>&
caps_and_defaults);
void OnGetPrinterSemanticCapsAndDefaults(
const std::string& printer_name,
const printing::PrinterSemanticCapsAndDefaults& caps_and_defaults);
void OnGetPrinterSemanticCapsAndDefaultsFailed(
const std::string& printer_name);
const absl::optional<printing::PrinterSemanticCapsAndDefaults>&
caps_and_defaults);
std::unique_ptr<content::ChildProcessHost> child_process_host_;
base::Process process_;
mojo::Remote<chrome::mojom::CloudPrintUtility> cloud_print_utility_remote_;
// A pointer to our client interface, who will be informed of progress.
scoped_refptr<Client> client_;
scoped_refptr<base::SingleThreadTaskRunner> client_task_runner_;

@ -221,6 +221,7 @@ static_library("utility") {
"printing_handler.cc",
"printing_handler.h",
]
public_deps += [ "//chrome/common:cloud_print_utility_mojom" ]
}
}

@ -13,6 +13,25 @@
#include "chrome/services/printing/pdf_to_emf_converter_factory.h"
#endif
#if BUILDFLAG(ENABLE_PRINT_PREVIEW) && defined(OS_WIN)
#include "chrome/common/cloud_print_utility.mojom.h"
#include "chrome/utility/printing_handler.h"
#include "mojo/public/cpp/bindings/pending_receiver.h"
#include "mojo/public/cpp/bindings/self_owned_receiver.h"
#endif
#if BUILDFLAG(ENABLE_PRINT_PREVIEW) && defined(OS_WIN)
namespace {
void BindCloudPrintUtility(
mojo::PendingReceiver<chrome::mojom::CloudPrintUtility> receiver) {
mojo::MakeSelfOwnedReceiver(std::make_unique<printing::PrintingHandler>(),
std::move(receiver));
}
} // namespace
#endif
void ExposeElevatedChromeUtilityInterfacesToBrowser(mojo::BinderMap* binders) {
#if BUILDFLAG(ENABLE_PRINTING) && defined(OS_WIN)
// TODO(crbug.com/798782): remove when the Cloud print chrome/service is
@ -20,4 +39,7 @@ void ExposeElevatedChromeUtilityInterfacesToBrowser(mojo::BinderMap* binders) {
binders->Add(base::BindRepeating(printing::PdfToEmfConverterFactory::Create),
base::ThreadTaskRunnerHandle::Get());
#endif
#if BUILDFLAG(ENABLE_PRINT_PREVIEW) && defined(OS_WIN)
binders->Add(base::BindRepeating(&BindCloudPrintUtility));
#endif
}

@ -34,9 +34,6 @@ base::LazyInstance<ChromeContentUtilityClient::NetworkBinderCreationCallback>::
ChromeContentUtilityClient::ChromeContentUtilityClient()
: utility_process_running_elevated_(false) {
#if BUILDFLAG(ENABLE_PRINT_PREVIEW) && defined(OS_WIN)
printing_handler_ = std::make_unique<printing::PrintingHandler>();
#endif
}
ChromeContentUtilityClient::~ChromeContentUtilityClient() = default;
@ -59,18 +56,6 @@ void ChromeContentUtilityClient::ExposeInterfacesToBrowser(
ExposeElevatedChromeUtilityInterfacesToBrowser(binders);
}
bool ChromeContentUtilityClient::OnMessageReceived(
const IPC::Message& message) {
if (utility_process_running_elevated_)
return false;
#if BUILDFLAG(ENABLE_PRINT_PREVIEW) && defined(OS_WIN)
if (printing_handler_->OnMessageReceived(message))
return true;
#endif
return false;
}
void ChromeContentUtilityClient::RegisterNetworkBinders(
service_manager::BinderRegistry* registry) {
if (g_network_binder_creation_callback.Get())

@ -27,7 +27,6 @@ class ChromeContentUtilityClient : public content::ContentUtilityClient {
// content::ContentUtilityClient:
void ExposeInterfacesToBrowser(mojo::BinderMap* binders) override;
bool OnMessageReceived(const IPC::Message& message) override;
void PostIOThreadCreated(
base::SingleThreadTaskRunner* io_thread_task_runner) override;
void RegisterNetworkBinders(

@ -5,22 +5,17 @@
#include "chrome/utility/printing_handler.h"
#include "build/build_config.h"
#include "chrome/common/chrome_utility_printing_messages.h"
#include "components/crash/core/common/crash_keys.h"
#include "content/public/utility/utility_thread.h"
#include "ipc/ipc_message.h"
#include "printing/backend/print_backend.h"
#include "printing/buildflags/buildflags.h"
#include "printing/mojom/print.mojom.h"
#include "third_party/abseil-cpp/absl/types/optional.h"
namespace printing {
namespace {
bool Send(IPC::Message* message) {
return content::UtilityThread::Get()->Send(message);
}
void ReleaseProcess() {
content::UtilityThread::Get()->ReleaseProcess();
}
@ -31,20 +26,9 @@ PrintingHandler::PrintingHandler() = default;
PrintingHandler::~PrintingHandler() = default;
bool PrintingHandler::OnMessageReceived(const IPC::Message& message) {
bool handled = true;
IPC_BEGIN_MESSAGE_MAP(PrintingHandler, message)
IPC_MESSAGE_HANDLER(ChromeUtilityMsg_GetPrinterCapsAndDefaults,
OnGetPrinterCapsAndDefaults)
IPC_MESSAGE_HANDLER(ChromeUtilityMsg_GetPrinterSemanticCapsAndDefaults,
OnGetPrinterSemanticCapsAndDefaults)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
return handled;
}
void PrintingHandler::OnGetPrinterCapsAndDefaults(
const std::string& printer_name) {
void PrintingHandler::GetPrinterCapsAndDefaults(
const std::string& printer_name,
GetPrinterCapsAndDefaultsCallback callback) {
scoped_refptr<PrintBackend> print_backend =
PrintBackend::CreateInstance(/*locale=*/std::string());
PrinterCapsAndDefaults printer_info;
@ -54,17 +38,16 @@ void PrintingHandler::OnGetPrinterCapsAndDefaults(
if (print_backend->GetPrinterCapsAndDefaults(printer_name, &printer_info) ==
mojom::ResultCode::kSuccess) {
Send(new ChromeUtilityHostMsg_GetPrinterCapsAndDefaults_Succeeded(
printer_name, printer_info));
std::move(callback).Run(printer_info);
} else {
Send(new ChromeUtilityHostMsg_GetPrinterCapsAndDefaults_Failed(
printer_name));
std::move(callback).Run(absl::nullopt);
}
ReleaseProcess();
}
void PrintingHandler::OnGetPrinterSemanticCapsAndDefaults(
const std::string& printer_name) {
void PrintingHandler::GetPrinterSemanticCapsAndDefaults(
const std::string& printer_name,
GetPrinterSemanticCapsAndDefaultsCallback callback) {
scoped_refptr<PrintBackend> print_backend =
PrintBackend::CreateInstance(/*locale=*/std::string());
PrinterSemanticCapsAndDefaults printer_info;
@ -74,11 +57,9 @@ void PrintingHandler::OnGetPrinterSemanticCapsAndDefaults(
if (print_backend->GetPrinterSemanticCapsAndDefaults(
printer_name, &printer_info) == mojom::ResultCode::kSuccess) {
Send(new ChromeUtilityHostMsg_GetPrinterSemanticCapsAndDefaults_Succeeded(
printer_name, printer_info));
std::move(callback).Run(printer_info);
} else {
Send(new ChromeUtilityHostMsg_GetPrinterSemanticCapsAndDefaults_Failed(
printer_name));
std::move(callback).Run(absl::nullopt);
}
ReleaseProcess();
}

@ -9,32 +9,31 @@
#include "base/macros.h"
#include "build/build_config.h"
#include "chrome/common/cloud_print_utility.mojom.h"
#include "printing/buildflags/buildflags.h"
#if !defined(OS_WIN) || !BUILDFLAG(ENABLE_PRINT_PREVIEW)
#error "Windows printing and print preview must be enabled"
#endif
namespace IPC {
class Message;
}
namespace printing {
// Dispatches IPCs for printing.
class PrintingHandler {
class PrintingHandler : public chrome::mojom::CloudPrintUtility {
public:
PrintingHandler();
~PrintingHandler();
bool OnMessageReceived(const IPC::Message& message);
PrintingHandler(const PrintingHandler&) = delete;
PrintingHandler& operator=(const PrintingHandler&) = delete;
~PrintingHandler() override;
private:
// IPC message handlers.
void OnGetPrinterCapsAndDefaults(const std::string& printer_name);
void OnGetPrinterSemanticCapsAndDefaults(const std::string& printer_name);
DISALLOW_COPY_AND_ASSIGN(PrintingHandler);
// chrome::mojom::CloudPrintUtility:
void GetPrinterCapsAndDefaults(
const std::string& printer_name,
GetPrinterCapsAndDefaultsCallback callback) override;
void GetPrinterSemanticCapsAndDefaults(
const std::string& printer_name,
GetPrinterSemanticCapsAndDefaultsCallback callback) override;
};
} // namespace printing

@ -6,10 +6,6 @@
namespace content {
bool ContentUtilityClient::OnMessageReceived(const IPC::Message& message) {
return false;
}
bool ContentUtilityClient::HandleServiceRequestDeprecated(
const std::string& service_name,
mojo::ScopedMessagePipeHandle service_pipe) {

@ -13,10 +13,6 @@
#include "mojo/public/cpp/bindings/generic_pending_receiver.h"
#include "services/service_manager/public/cpp/binder_registry.h"
namespace IPC {
class Message;
}
namespace mojo {
class BinderMap;
class ServiceFactory;
@ -32,9 +28,6 @@ class CONTENT_EXPORT ContentUtilityClient {
// Notifies us that the UtilityThread has been created.
virtual void UtilityThreadStarted() {}
// Allows the embedder to filter messages.
virtual bool OnMessageReceived(const IPC::Message& message);
// Allows the embedder to register interface binders to handle interface
// requests coming in from the browser process. These are requests that the
// browser issues through the ChildProcessHost's BindReceiver() API on the

@ -252,10 +252,6 @@ void UtilityThreadImpl::Init() {
service_factory_ = std::make_unique<UtilityServiceFactory>();
}
bool UtilityThreadImpl::OnControlMessageReceived(const IPC::Message& msg) {
return GetContentClient()->utility()->OnMessageReceived(msg);
}
void UtilityThreadImpl::RunServiceDeprecated(
const std::string& service_name,
mojo::ScopedMessagePipeHandle service_pipe) {

@ -56,7 +56,6 @@ class UtilityThreadImpl : public UtilityThread,
void Init();
// ChildThreadImpl:
bool OnControlMessageReceived(const IPC::Message& msg) override;
void RunServiceDeprecated(
const std::string& service_name,
mojo::ScopedMessagePipeHandle service_pipe) override;

@ -23,7 +23,6 @@ enum IPCMessageStart {
NaClHostMsgStart,
EncryptedMediaMsgStart,
GinJavaBridgeMsgStart,
ChromeUtilityPrintingMsgStart,
ExtensionsGuestViewMsgStart,
GuestViewMsgStart,
MediaPlayerDelegateMsgStart,

@ -53,9 +53,6 @@ void WriteIpcMessageIdAsProtozero(uint32_t message_id,
case GinJavaBridgeMsgStart:
message_class = ChromeLegacyIpc::CLASS_GIN_JAVA_BRIDGE;
break;
case ChromeUtilityPrintingMsgStart:
message_class = ChromeLegacyIpc::CLASS_CHROME_UTILITY_PRINTING;
break;
case ExtensionsGuestViewMsgStart:
message_class = ChromeLegacyIpc::CLASS_EXTENSIONS_GUEST_VIEW;
break;

@ -48,7 +48,6 @@ static bool check_msgtable() {
// include message files used inside the actual chrome browser in this list.
exemptions.push_back(TestMsgStart);
exemptions.push_back(WorkerMsgStart); // Now only used by tests.
exemptions.push_back(ChromeUtilityPrintingMsgStart); // BUILDFLAGS, sigh.
#if !BUILDFLAG(ENABLE_NACL)
exemptions.push_back(NaClMsgStart);