Commit a8804a50 authored by Daniel Hosseinian's avatar Daniel Hosseinian Committed by Commit Bot

Support CUPS IPP printing backend on macOS

Build Chromium on macOS with CUPS IPP. Use a runtime switch to allow
for dynamic switching between the original CUPS backend, which uses PPD
attributes, and the new backend. The original backend will remain the
default one until the new one is verfied through experiments and/or
automated testing.

Bug: 226176
Change-Id: I88147e12ec8bb75a2c17add32fbccf7496d2f669
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2067548Reviewed-by: default avatarLei Zhang <thestig@chromium.org>
Reviewed-by: default avatarSean Kau <skau@chromium.org>
Commit-Queue: Daniel Hosseinian <dhoss@chromium.org>
Cr-Commit-Position: refs/heads/master@{#754744}
parent 1618c310
...@@ -8,8 +8,10 @@ if (is_chromeos) { ...@@ -8,8 +8,10 @@ if (is_chromeos) {
} }
declare_args() { declare_args() {
# For now, we only enable print media localization on Chrome OS. # Enable print media localization only on the platforms that support CUPS IPP
enable_print_media_l10n = is_chromeos # (ChromeOS and macOS for now). The localization expects media vendor IDs
# uniquely generated by CUPS IPP.
enable_print_media_l10n = is_chromeos || is_mac
} }
buildflag_header("printing_buildflags") { buildflag_header("printing_buildflags") {
......
...@@ -29,7 +29,7 @@ ...@@ -29,7 +29,7 @@
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "components/strings/grit/components_strings.h" #include "components/strings/grit/components_strings.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#endif #endif // defined(OS_WIN)
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
#include "base/feature_list.h" #include "base/feature_list.h"
...@@ -41,7 +41,10 @@ ...@@ -41,7 +41,10 @@
#if BUILDFLAG(PRINT_MEDIA_L10N_ENABLED) #if BUILDFLAG(PRINT_MEDIA_L10N_ENABLED)
#include "components/printing/browser/print_media_l10n.h" #include "components/printing/browser/print_media_l10n.h"
#endif #if defined(OS_MACOSX)
#include "printing/printing_features.h"
#endif // defined(OS_MACOSX)
#endif // BUILDFLAG(PRINT_MEDIA_L10N_ENABLED)
namespace printing { namespace printing {
...@@ -111,10 +114,21 @@ base::Value GetPrinterCapabilitiesOnBlockingTaskRunner( ...@@ -111,10 +114,21 @@ base::Value GetPrinterCapabilitiesOnBlockingTaskRunner(
} }
#if BUILDFLAG(PRINT_MEDIA_L10N_ENABLED) #if BUILDFLAG(PRINT_MEDIA_L10N_ENABLED)
PopulateAllPaperDisplayNames(&info); bool populate_paper_display_names = true;
#if defined(OS_MACOSX)
// Paper display name localization requires standardized vendor ID names
// populated by CUPS IPP. If the CUPS IPP backend is not enabled, localization
// will not properly occur.
populate_paper_display_names =
base::FeatureList::IsEnabled(features::kCupsIppPrintingBackend);
#endif #endif
if (populate_paper_display_names)
PopulateAllPaperDisplayNames(&info);
#endif // BUILDFLAG(PRINT_MEDIA_L10N_ENABLED)
info.papers.insert(info.papers.end(), additional_papers.begin(), info.papers.insert(info.papers.end(), additional_papers.begin(),
additional_papers.end()); additional_papers.end());
#if defined(OS_CHROMEOS) #if defined(OS_CHROMEOS)
if (!has_secure_protocol) if (!has_secure_protocol)
info.pin_supported = false; info.pin_supported = false;
......
...@@ -163,12 +163,10 @@ component("printing") { ...@@ -163,12 +163,10 @@ component("printing") {
configs += [ ":cups" ] configs += [ ":cups" ]
if (is_linux) { if (is_linux) {
cflags += [ # CUPS 1.6 deprecated the PPD APIs, but we will stay with this API
# CUPS 1.6 deprecated the PPD APIs, but we will stay with this # for now as the suitability of the replacement is unclear.
# API for now as the suitability of the replacement is unclear.
# More info: crbug.com/226176 # More info: crbug.com/226176
"-Wno-deprecated-declarations", cflags += [ "-Wno-deprecated-declarations" ]
]
} }
if (is_mac) { if (is_mac) {
...@@ -181,9 +179,7 @@ component("printing") { ...@@ -181,9 +179,7 @@ component("printing") {
# of the print backend and enables a custom implementation instead. # of the print backend and enables a custom implementation instead.
defines += [ "PRINT_BACKEND_AVAILABLE" ] defines += [ "PRINT_BACKEND_AVAILABLE" ]
if (is_chromeos) { if (is_chromeos || is_mac) {
deps += [ ":ipp_handlers_generate" ]
sources += [ sources += [
"backend/cups_connection.cc", "backend/cups_connection.cc",
"backend/cups_connection.h", "backend/cups_connection.h",
...@@ -199,16 +195,25 @@ component("printing") { ...@@ -199,16 +195,25 @@ component("printing") {
"backend/cups_jobs.h", "backend/cups_jobs.h",
"backend/cups_printer.cc", "backend/cups_printer.cc",
"backend/cups_printer.h", "backend/cups_printer.h",
"backend/print_backend_cups_ipp.cc",
"backend/print_backend_cups_ipp.h",
]
}
if (is_chromeos) {
deps += [ ":ipp_handlers_generate" ]
sources += [
"backend/ipp_handler_map.h", "backend/ipp_handler_map.h",
"backend/ipp_handlers.cc", "backend/ipp_handlers.cc",
"backend/ipp_handlers.h", "backend/ipp_handlers.h",
"backend/print_backend_cups_ipp.cc",
"backend/print_backend_cups_ipp.h",
"printing_context_chromeos.cc", "printing_context_chromeos.cc",
"printing_context_chromeos.h", "printing_context_chromeos.h",
ipp_handler_map_path, ipp_handler_map_path,
] ]
} else { } else {
# TODO(crbug.com/1062136): Remove the original CUPS backend for macOS
# when Cloud Print support is terminated. Follow up after Jan 1, 2021.
sources += [ sources += [
"backend/cups_helper.cc", "backend/cups_helper.cc",
"backend/cups_helper.h", "backend/cups_helper.h",
...@@ -236,9 +241,6 @@ component("printing") { ...@@ -236,9 +241,6 @@ component("printing") {
"backend/printing_restrictions.cc", "backend/printing_restrictions.cc",
"backend/printing_restrictions.h", "backend/printing_restrictions.h",
"printed_document_chromeos.cc", "printed_document_chromeos.cc",
"printer_query_result.h",
"printer_status.cc",
"printer_status.h",
"printing_context_no_system_dialog.cc", "printing_context_no_system_dialog.cc",
"printing_context_no_system_dialog.h", "printing_context_no_system_dialog.h",
] ]
...@@ -257,6 +259,14 @@ component("printing") { ...@@ -257,6 +259,14 @@ component("printing") {
"printing_context_linux.h", "printing_context_linux.h",
] ]
} }
if (is_chromeos || is_mac) {
sources += [
"printer_query_result.h",
"printer_status.cc",
"printer_status.h",
]
}
} }
static_library("test_support") { static_library("test_support") {
...@@ -333,9 +343,11 @@ test("printing_unittests") { ...@@ -333,9 +343,11 @@ test("printing_unittests") {
if (use_cups) { if (use_cups) {
configs += [ ":cups" ] configs += [ ":cups" ]
if (is_chromeos) { if (is_chromeos || is_mac) {
sources += [ "backend/cups_ipp_helper_unittest.cc" ] sources += [ "backend/cups_ipp_helper_unittest.cc" ]
} else { }
if (!is_chromeos) {
sources += [ sources += [
"backend/cups_helper_unittest.cc", "backend/cups_helper_unittest.cc",
"backend/print_backend_cups_unittest.cc", "backend/print_backend_cups_unittest.cc",
......
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "base/logging.h" #include "base/logging.h"
#include "base/test/metrics/histogram_tester.h" #include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h" #include "base/test/scoped_feature_list.h"
#include "build/build_config.h"
#include "printing/backend/cups_printer.h" #include "printing/backend/cups_printer.h"
#include "printing/printing_features.h" #include "printing/printing_features.h"
#include "testing/gmock/include/gmock/gmock.h" #include "testing/gmock/include/gmock/gmock.h"
...@@ -275,6 +276,7 @@ TEST_F(PrintBackendCupsIppHelperTest, OmitPapersWithSpecialVendorIds) { ...@@ -275,6 +276,7 @@ TEST_F(PrintBackendCupsIppHelperTest, OmitPapersWithSpecialVendorIds) {
"iso b0"))); "iso b0")));
} }
#if defined(OS_CHROMEOS)
TEST_F(PrintBackendCupsIppHelperTest, PinSupported) { TEST_F(PrintBackendCupsIppHelperTest, PinSupported) {
printer_->SetSupportedOptions("job-password", MakeInteger(ipp_, 4)); printer_->SetSupportedOptions("job-password", MakeInteger(ipp_, 4));
printer_->SetSupportedOptions("job-password-encryption", printer_->SetSupportedOptions("job-password-encryption",
...@@ -349,5 +351,6 @@ TEST_F(PrintBackendCupsIppHelperTest, AdvancedCaps) { ...@@ -349,5 +351,6 @@ TEST_F(PrintBackendCupsIppHelperTest, AdvancedCaps) {
EXPECT_EQ(3u, caps.advanced_capabilities[5].values.size()); EXPECT_EQ(3u, caps.advanced_capabilities[5].values.size());
histograms.ExpectUniqueSample("Printing.CUPS.IppAttributesCount", 5, 1); histograms.ExpectUniqueSample("Printing.CUPS.IppAttributesCount", 5, 1);
} }
#endif // defined(OS_CHROMEOS)
} // namespace printing } // namespace printing
...@@ -166,12 +166,10 @@ class PRINTING_EXPORT PrintBackend ...@@ -166,12 +166,10 @@ class PRINTING_EXPORT PrintBackend
const std::string& printer_name, const std::string& printer_name,
PrinterSemanticCapsAndDefaults* printer_info) = 0; PrinterSemanticCapsAndDefaults* printer_info) = 0;
#if !defined(OS_CHROMEOS)
// Gets the capabilities and defaults for a specific printer. // Gets the capabilities and defaults for a specific printer.
virtual bool GetPrinterCapsAndDefaults( virtual bool GetPrinterCapsAndDefaults(
const std::string& printer_name, const std::string& printer_name,
PrinterCapsAndDefaults* printer_info) = 0; PrinterCapsAndDefaults* printer_info) = 0;
#endif // !defined(OS_CHROMEOS)
// Gets the information about driver for a specific printer. // Gets the information about driver for a specific printer.
virtual std::string GetPrinterDriverInfo(const std::string& printer_name) = 0; virtual std::string GetPrinterDriverInfo(const std::string& printer_name) = 0;
......
...@@ -26,6 +26,8 @@ class PrintBackendChromeOS : public PrintBackend { ...@@ -26,6 +26,8 @@ class PrintBackendChromeOS : public PrintBackend {
std::string GetDefaultPrinterName() override; std::string GetDefaultPrinterName() override;
bool GetPrinterBasicInfo(const std::string& printer_name, bool GetPrinterBasicInfo(const std::string& printer_name,
PrinterBasicInfo* printer_info) override; PrinterBasicInfo* printer_info) override;
bool GetPrinterCapsAndDefaults(const std::string& printer_name,
PrinterCapsAndDefaults* printer_info) override;
bool GetPrinterSemanticCapsAndDefaults( bool GetPrinterSemanticCapsAndDefaults(
const std::string& printer_name, const std::string& printer_name,
PrinterSemanticCapsAndDefaults* printer_info) override; PrinterSemanticCapsAndDefaults* printer_info) override;
...@@ -48,6 +50,13 @@ bool PrintBackendChromeOS::GetPrinterBasicInfo(const std::string& printer_name, ...@@ -48,6 +50,13 @@ bool PrintBackendChromeOS::GetPrinterBasicInfo(const std::string& printer_name,
return false; return false;
} }
bool PrintBackendChromeOS::GetPrinterCapsAndDefaults(
const std::string& printer_name,
PrinterCapsAndDefaults* printer_info) {
NOTREACHED();
return false;
}
bool PrintBackendChromeOS::GetPrinterSemanticCapsAndDefaults( bool PrintBackendChromeOS::GetPrinterSemanticCapsAndDefaults(
const std::string& printer_name, const std::string& printer_name,
PrinterSemanticCapsAndDefaults* printer_info) { PrinterSemanticCapsAndDefaults* printer_info) {
......
...@@ -24,6 +24,13 @@ ...@@ -24,6 +24,13 @@
#include "printing/backend/print_backend_consts.h" #include "printing/backend/print_backend_consts.h"
#include "url/gurl.h" #include "url/gurl.h"
#if defined(OS_MACOSX)
#include "printing/backend/cups_connection.h"
#include "printing/backend/cups_ipp_utils.h"
#include "printing/backend/print_backend_cups_ipp.h"
#include "printing/printing_features.h"
#endif // defined(OS_MACOSX)
namespace printing { namespace printing {
PrintBackendCUPS::PrintBackendCUPS(const GURL& print_server_url, PrintBackendCUPS::PrintBackendCUPS(const GURL& print_server_url,
...@@ -211,11 +218,17 @@ bool PrintBackendCUPS::IsValidPrinter(const std::string& printer_name) { ...@@ -211,11 +218,17 @@ bool PrintBackendCUPS::IsValidPrinter(const std::string& printer_name) {
return !!GetNamedDest(printer_name); return !!GetNamedDest(printer_name);
} }
#if !defined(OS_CHROMEOS)
scoped_refptr<PrintBackend> PrintBackend::CreateInstanceImpl( scoped_refptr<PrintBackend> PrintBackend::CreateInstanceImpl(
const base::DictionaryValue* print_backend_settings, const base::DictionaryValue* print_backend_settings,
const std::string& locale, const std::string& locale,
bool for_cloud_print) { bool for_cloud_print) {
#if defined(OS_MACOSX)
if (!for_cloud_print &&
base::FeatureList::IsEnabled(features::kCupsIppPrintingBackend)) {
return base::MakeRefCounted<PrintBackendCupsIpp>(
CreateConnection(print_backend_settings), locale);
}
#endif // defined(OS_MACOSX)
std::string print_server_url_str, cups_blocking; std::string print_server_url_str, cups_blocking;
int encryption = HTTP_ENCRYPT_NEVER; int encryption = HTTP_ENCRYPT_NEVER;
if (print_backend_settings) { if (print_backend_settings) {
...@@ -231,7 +244,6 @@ scoped_refptr<PrintBackend> PrintBackend::CreateInstanceImpl( ...@@ -231,7 +244,6 @@ scoped_refptr<PrintBackend> PrintBackend::CreateInstanceImpl(
print_server_url, static_cast<http_encryption_t>(encryption), print_server_url, static_cast<http_encryption_t>(encryption),
cups_blocking == kValueTrue, locale); cups_blocking == kValueTrue, locale);
} }
#endif // !defined(OS_CHROMEOS)
int PrintBackendCUPS::GetDests(cups_dest_t** dests) { int PrintBackendCUPS::GetDests(cups_dest_t** dests) {
// Default to the local print server (CUPS scheduler) // Default to the local print server (CUPS scheduler)
......
...@@ -75,6 +75,13 @@ bool PrintBackendCupsIpp::GetPrinterBasicInfo(const std::string& printer_name, ...@@ -75,6 +75,13 @@ bool PrintBackendCupsIpp::GetPrinterBasicInfo(const std::string& printer_name,
return printer->ToPrinterInfo(printer_info); return printer->ToPrinterInfo(printer_info);
} }
bool PrintBackendCupsIpp::GetPrinterCapsAndDefaults(
const std::string& printer_name,
PrinterCapsAndDefaults* printer_info) {
NOTREACHED();
return false;
}
bool PrintBackendCupsIpp::GetPrinterSemanticCapsAndDefaults( bool PrintBackendCupsIpp::GetPrinterSemanticCapsAndDefaults(
const std::string& printer_name, const std::string& printer_name,
PrinterSemanticCapsAndDefaults* printer_info) { PrinterSemanticCapsAndDefaults* printer_info) {
......
...@@ -26,6 +26,8 @@ class PrintBackendCupsIpp : public PrintBackend { ...@@ -26,6 +26,8 @@ class PrintBackendCupsIpp : public PrintBackend {
std::string GetDefaultPrinterName() override; std::string GetDefaultPrinterName() override;
bool GetPrinterBasicInfo(const std::string& printer_name, bool GetPrinterBasicInfo(const std::string& printer_name,
PrinterBasicInfo* printer_info) override; PrinterBasicInfo* printer_info) override;
bool GetPrinterCapsAndDefaults(const std::string& printer_name,
PrinterCapsAndDefaults* printer_info) override;
bool GetPrinterSemanticCapsAndDefaults( bool GetPrinterSemanticCapsAndDefaults(
const std::string& printer_name, const std::string& printer_name,
PrinterSemanticCapsAndDefaults* printer_info) override; PrinterSemanticCapsAndDefaults* printer_info) override;
......
...@@ -50,14 +50,12 @@ bool TestPrintBackend::GetPrinterSemanticCapsAndDefaults( ...@@ -50,14 +50,12 @@ bool TestPrintBackend::GetPrinterSemanticCapsAndDefaults(
return true; return true;
} }
#if !defined(OS_CHROMEOS)
bool TestPrintBackend::GetPrinterCapsAndDefaults( bool TestPrintBackend::GetPrinterCapsAndDefaults(
const std::string& printer_name, const std::string& printer_name,
PrinterCapsAndDefaults* printer_info) { PrinterCapsAndDefaults* printer_info) {
// not implemented // not implemented
return false; return false;
} }
#endif // !defined(OS_CHROMEOS)
std::string TestPrintBackend::GetPrinterDriverInfo( std::string TestPrintBackend::GetPrinterDriverInfo(
const std::string& printr_name) { const std::string& printr_name) {
......
...@@ -28,10 +28,8 @@ class TestPrintBackend : public PrintBackend { ...@@ -28,10 +28,8 @@ class TestPrintBackend : public PrintBackend {
bool GetPrinterSemanticCapsAndDefaults( bool GetPrinterSemanticCapsAndDefaults(
const std::string& printer_name, const std::string& printer_name,
PrinterSemanticCapsAndDefaults* printer_info) override; PrinterSemanticCapsAndDefaults* printer_info) override;
#if !defined(OS_CHROMEOS)
bool GetPrinterCapsAndDefaults(const std::string& printer_name, bool GetPrinterCapsAndDefaults(const std::string& printer_name,
PrinterCapsAndDefaults* printer_info) override; PrinterCapsAndDefaults* printer_info) override;
#endif // !defined(OS_CHROMEOS)
std::string GetPrinterDriverInfo(const std::string& printer_name) override; std::string GetPrinterDriverInfo(const std::string& printer_name) override;
bool IsValidPrinter(const std::string& printer_name) override; bool IsValidPrinter(const std::string& printer_name) override;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment