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) {
}
declare_args() {
# For now, we only enable print media localization on Chrome OS.
enable_print_media_l10n = is_chromeos
# Enable print media localization only on the platforms that support CUPS IPP
# (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") {
......
......@@ -29,7 +29,7 @@
#include "base/strings/utf_string_conversions.h"
#include "components/strings/grit/components_strings.h"
#include "ui/base/l10n/l10n_util.h"
#endif
#endif // defined(OS_WIN)
#if defined(OS_CHROMEOS)
#include "base/feature_list.h"
......@@ -41,7 +41,10 @@
#if BUILDFLAG(PRINT_MEDIA_L10N_ENABLED)
#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 {
......@@ -111,10 +114,21 @@ base::Value GetPrinterCapabilitiesOnBlockingTaskRunner(
}
#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
if (populate_paper_display_names)
PopulateAllPaperDisplayNames(&info);
#endif // BUILDFLAG(PRINT_MEDIA_L10N_ENABLED)
info.papers.insert(info.papers.end(), additional_papers.begin(),
additional_papers.end());
#if defined(OS_CHROMEOS)
if (!has_secure_protocol)
info.pin_supported = false;
......
......@@ -163,12 +163,10 @@ component("printing") {
configs += [ ":cups" ]
if (is_linux) {
cflags += [
# CUPS 1.6 deprecated the PPD APIs, but we will stay with this
# API for now as the suitability of the replacement is unclear.
# CUPS 1.6 deprecated the PPD APIs, but we will stay with this API
# for now as the suitability of the replacement is unclear.
# More info: crbug.com/226176
"-Wno-deprecated-declarations",
]
cflags += [ "-Wno-deprecated-declarations" ]
}
if (is_mac) {
......@@ -181,9 +179,7 @@ component("printing") {
# of the print backend and enables a custom implementation instead.
defines += [ "PRINT_BACKEND_AVAILABLE" ]
if (is_chromeos) {
deps += [ ":ipp_handlers_generate" ]
if (is_chromeos || is_mac) {
sources += [
"backend/cups_connection.cc",
"backend/cups_connection.h",
......@@ -199,16 +195,25 @@ component("printing") {
"backend/cups_jobs.h",
"backend/cups_printer.cc",
"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_handlers.cc",
"backend/ipp_handlers.h",
"backend/print_backend_cups_ipp.cc",
"backend/print_backend_cups_ipp.h",
"printing_context_chromeos.cc",
"printing_context_chromeos.h",
ipp_handler_map_path,
]
} 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 += [
"backend/cups_helper.cc",
"backend/cups_helper.h",
......@@ -236,9 +241,6 @@ component("printing") {
"backend/printing_restrictions.cc",
"backend/printing_restrictions.h",
"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.h",
]
......@@ -257,6 +259,14 @@ component("printing") {
"printing_context_linux.h",
]
}
if (is_chromeos || is_mac) {
sources += [
"printer_query_result.h",
"printer_status.cc",
"printer_status.h",
]
}
}
static_library("test_support") {
......@@ -333,9 +343,11 @@ test("printing_unittests") {
if (use_cups) {
configs += [ ":cups" ]
if (is_chromeos) {
if (is_chromeos || is_mac) {
sources += [ "backend/cups_ipp_helper_unittest.cc" ]
} else {
}
if (!is_chromeos) {
sources += [
"backend/cups_helper_unittest.cc",
"backend/print_backend_cups_unittest.cc",
......
......@@ -12,6 +12,7 @@
#include "base/logging.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#include "build/build_config.h"
#include "printing/backend/cups_printer.h"
#include "printing/printing_features.h"
#include "testing/gmock/include/gmock/gmock.h"
......@@ -275,6 +276,7 @@ TEST_F(PrintBackendCupsIppHelperTest, OmitPapersWithSpecialVendorIds) {
"iso b0")));
}
#if defined(OS_CHROMEOS)
TEST_F(PrintBackendCupsIppHelperTest, PinSupported) {
printer_->SetSupportedOptions("job-password", MakeInteger(ipp_, 4));
printer_->SetSupportedOptions("job-password-encryption",
......@@ -349,5 +351,6 @@ TEST_F(PrintBackendCupsIppHelperTest, AdvancedCaps) {
EXPECT_EQ(3u, caps.advanced_capabilities[5].values.size());
histograms.ExpectUniqueSample("Printing.CUPS.IppAttributesCount", 5, 1);
}
#endif // defined(OS_CHROMEOS)
} // namespace printing
......@@ -166,12 +166,10 @@ class PRINTING_EXPORT PrintBackend
const std::string& printer_name,
PrinterSemanticCapsAndDefaults* printer_info) = 0;
#if !defined(OS_CHROMEOS)
// Gets the capabilities and defaults for a specific printer.
virtual bool GetPrinterCapsAndDefaults(
const std::string& printer_name,
PrinterCapsAndDefaults* printer_info) = 0;
#endif // !defined(OS_CHROMEOS)
// Gets the information about driver for a specific printer.
virtual std::string GetPrinterDriverInfo(const std::string& printer_name) = 0;
......
......@@ -26,6 +26,8 @@ class PrintBackendChromeOS : public PrintBackend {
std::string GetDefaultPrinterName() override;
bool GetPrinterBasicInfo(const std::string& printer_name,
PrinterBasicInfo* printer_info) override;
bool GetPrinterCapsAndDefaults(const std::string& printer_name,
PrinterCapsAndDefaults* printer_info) override;
bool GetPrinterSemanticCapsAndDefaults(
const std::string& printer_name,
PrinterSemanticCapsAndDefaults* printer_info) override;
......@@ -48,6 +50,13 @@ bool PrintBackendChromeOS::GetPrinterBasicInfo(const std::string& printer_name,
return false;
}
bool PrintBackendChromeOS::GetPrinterCapsAndDefaults(
const std::string& printer_name,
PrinterCapsAndDefaults* printer_info) {
NOTREACHED();
return false;
}
bool PrintBackendChromeOS::GetPrinterSemanticCapsAndDefaults(
const std::string& printer_name,
PrinterSemanticCapsAndDefaults* printer_info) {
......
......@@ -24,6 +24,13 @@
#include "printing/backend/print_backend_consts.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 {
PrintBackendCUPS::PrintBackendCUPS(const GURL& print_server_url,
......@@ -211,11 +218,17 @@ bool PrintBackendCUPS::IsValidPrinter(const std::string& printer_name) {
return !!GetNamedDest(printer_name);
}
#if !defined(OS_CHROMEOS)
scoped_refptr<PrintBackend> PrintBackend::CreateInstanceImpl(
const base::DictionaryValue* print_backend_settings,
const std::string& locale,
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;
int encryption = HTTP_ENCRYPT_NEVER;
if (print_backend_settings) {
......@@ -231,7 +244,6 @@ scoped_refptr<PrintBackend> PrintBackend::CreateInstanceImpl(
print_server_url, static_cast<http_encryption_t>(encryption),
cups_blocking == kValueTrue, locale);
}
#endif // !defined(OS_CHROMEOS)
int PrintBackendCUPS::GetDests(cups_dest_t** dests) {
// Default to the local print server (CUPS scheduler)
......
......@@ -75,6 +75,13 @@ bool PrintBackendCupsIpp::GetPrinterBasicInfo(const std::string& printer_name,
return printer->ToPrinterInfo(printer_info);
}
bool PrintBackendCupsIpp::GetPrinterCapsAndDefaults(
const std::string& printer_name,
PrinterCapsAndDefaults* printer_info) {
NOTREACHED();
return false;
}
bool PrintBackendCupsIpp::GetPrinterSemanticCapsAndDefaults(
const std::string& printer_name,
PrinterSemanticCapsAndDefaults* printer_info) {
......
......@@ -26,6 +26,8 @@ class PrintBackendCupsIpp : public PrintBackend {
std::string GetDefaultPrinterName() override;
bool GetPrinterBasicInfo(const std::string& printer_name,
PrinterBasicInfo* printer_info) override;
bool GetPrinterCapsAndDefaults(const std::string& printer_name,
PrinterCapsAndDefaults* printer_info) override;
bool GetPrinterSemanticCapsAndDefaults(
const std::string& printer_name,
PrinterSemanticCapsAndDefaults* printer_info) override;
......
......@@ -50,14 +50,12 @@ bool TestPrintBackend::GetPrinterSemanticCapsAndDefaults(
return true;
}
#if !defined(OS_CHROMEOS)
bool TestPrintBackend::GetPrinterCapsAndDefaults(
const std::string& printer_name,
PrinterCapsAndDefaults* printer_info) {
// not implemented
return false;
}
#endif // !defined(OS_CHROMEOS)
std::string TestPrintBackend::GetPrinterDriverInfo(
const std::string& printr_name) {
......
......@@ -28,10 +28,8 @@ class TestPrintBackend : public PrintBackend {
bool GetPrinterSemanticCapsAndDefaults(
const std::string& printer_name,
PrinterSemanticCapsAndDefaults* printer_info) override;
#if !defined(OS_CHROMEOS)
bool GetPrinterCapsAndDefaults(const std::string& printer_name,
PrinterCapsAndDefaults* printer_info) override;
#endif // !defined(OS_CHROMEOS)
std::string GetPrinterDriverInfo(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