diff options
author | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2019-08-30 10:22:43 +0200 |
---|---|---|
committer | Allan Sandfeld Jensen <allan.jensen@qt.io> | 2019-08-30 12:36:28 +0000 |
commit | 271a6c3487a14599023a9106329505597638d793 (patch) | |
tree | e040d58ffc86c1480b79ca8528020ca9ec919bf8 /chromium/printing | |
parent | 7b2ffa587235a47d4094787d72f38102089f402a (diff) | |
download | qtwebengine-chromium-271a6c3487a14599023a9106329505597638d793.tar.gz |
BASELINE: Update Chromium to 77.0.3865.59
Change-Id: I1e89a5f3b009a9519a6705102ad65c92fe736f21
Reviewed-by: Michael BrĂ¼ning <michael.bruning@qt.io>
Diffstat (limited to 'chromium/printing')
25 files changed, 223 insertions, 164 deletions
diff --git a/chromium/printing/BUILD.gn b/chromium/printing/BUILD.gn index 50faec780ee..5fe480f5450 100644 --- a/chromium/printing/BUILD.gn +++ b/chromium/printing/BUILD.gn @@ -22,6 +22,14 @@ if ((enable_basic_printing && is_win) || enable_print_preview) { "set enable_pdf=true.") } +# Several targets want to include this header file. We separate it out +# here so multiple targets can depend on it. +source_set("printing_export") { + sources = [ + "printing_export.h", + ] +} + component("printing") { sources = [ "backend/print_backend.cc", @@ -67,7 +75,6 @@ component("printing") { "printed_document_win.cc", "printing_context.cc", "printing_context.h", - "printing_export.h", "printing_utils.cc", "printing_utils.h", "pwg_raster_settings.h", @@ -82,6 +89,7 @@ component("printing") { "//printing/buildflags", ] deps = [ + ":printing_export", "//base", "//base:i18n", "//base/third_party/dynamic_annotations", @@ -227,6 +235,7 @@ component("printing") { "backend/printing_restrictions.cc", "backend/printing_restrictions.h", "printed_document_chromeos.cc", + "printer_query_result_chromeos.h", "printing_context_no_system_dialog.cc", "printing_context_no_system_dialog.h", "printing_features_chromeos.cc", @@ -359,7 +368,6 @@ if (is_android) { sources = [ "android/java/src/org/chromium/printing/PrintingContext.java", ] - jni_package = "printing" } android_library("printing_java") { diff --git a/chromium/printing/DEPS b/chromium/printing/DEPS index fb7ac6ec1e2..41732d72750 100644 --- a/chromium/printing/DEPS +++ b/chromium/printing/DEPS @@ -1,6 +1,6 @@ include_rules = [ "+cc/paint", - "+jni", + "+printing/printing_jni_headers", "+skia/ext", "+third_party/icu/source/common/unicode", "+third_party/icu/source/i18n/unicode", diff --git a/chromium/printing/android/java/src/org/chromium/printing/PrintingControllerImpl.java b/chromium/printing/android/java/src/org/chromium/printing/PrintingControllerImpl.java index 6e4ac21eb75..1e8e49cc133 100644 --- a/chromium/printing/android/java/src/org/chromium/printing/PrintingControllerImpl.java +++ b/chromium/printing/android/java/src/org/chromium/printing/PrintingControllerImpl.java @@ -213,7 +213,13 @@ public class PrintingControllerImpl implements PrintingController, PdfGenerator @Override public void pdfWritingDone(int pageCount) { - if (mPrintingState == PRINTING_STATE_FINISHED) return; + if (mPrintingState == PRINTING_STATE_READY) { + assert pageCount + == 0 : "There is no pending printing task, should only be a failure report"; + } + + if (mPrintingState != PRINTING_STATE_STARTED_FROM_ONWRITE) return; + mPrintingState = PRINTING_STATE_READY; closeFileDescriptor(); if (pageCount > 0) { diff --git a/chromium/printing/backend/cups_ipp_util.cc b/chromium/printing/backend/cups_ipp_util.cc index 7c5aab22ee2..f7f64f9e780 100644 --- a/chromium/printing/backend/cups_ipp_util.cc +++ b/chromium/printing/backend/cups_ipp_util.cc @@ -30,7 +30,6 @@ constexpr char kIppColor[] = CUPS_PRINT_COLOR_MODE; constexpr char kIppMedia[] = CUPS_MEDIA; constexpr char kIppDuplex[] = CUPS_SIDES; constexpr char kIppResolution[] = "printer-resolution"; // RFC 2911 -constexpr char kIppDocumentName[] = "document-name"; // RFC 8011 constexpr char kIppRequestingUserName[] = "requesting-user-name"; // RFC 8011 constexpr char kIppPin[] = "job-password"; // PWG 5100.11 constexpr char kIppPinEncryption[] = "job-password-encryption"; // PWG 5100.11 @@ -39,8 +38,10 @@ constexpr char kIppPinEncryption[] = "job-password-encryption"; // PWG 5100.11 constexpr char kCollated[] = "collated"; constexpr char kUncollated[] = "uncollated"; +#if defined(OS_CHROMEOS) constexpr int kPinMinimumLength = 4; constexpr char kPinEncryptionNone[] = "none"; +#endif // defined(OS_CHROMEOS) namespace { @@ -159,6 +160,31 @@ PrinterSemanticCapsAndDefaults::Paper ParsePaper(base::StringPiece value) { return paper; } +ColorModel DefaultColorModel(const CupsOptionProvider& printer) { + // default color + ipp_attribute_t* attr = printer.GetDefaultOptionValue(kIppColor); + if (!attr) + return UNKNOWN_COLOR_MODEL; + + return ColorModelFromIppColor(ippGetString(attr, 0, nullptr)); +} + +std::vector<ColorModel> SupportedColorModels( + const CupsOptionProvider& printer) { + std::vector<ColorModel> colors; + + std::vector<base::StringPiece> color_modes = + printer.GetSupportedOptionValueStrings(kIppColor); + for (base::StringPiece color : color_modes) { + ColorModel color_model = ColorModelFromIppColor(color); + if (color_model != UNKNOWN_COLOR_MODEL) { + colors.push_back(color_model); + } + } + + return colors; +} + void ExtractColor(const CupsOptionProvider& printer, PrinterSemanticCapsAndDefaults* printer_info) { printer_info->bw_model = UNKNOWN_COLOR_MODEL; @@ -204,6 +230,18 @@ void ExtractDuplexModes(const CupsOptionProvider& printer, : UNKNOWN_DUPLEX_MODE; } +void CopiesRange(const CupsOptionProvider& printer, + int* lower_bound, + int* upper_bound) { + ipp_attribute_t* attr = printer.GetSupportedOptionValues(kIppCopies); + if (!attr) { + *lower_bound = -1; + *upper_bound = -1; + } + + *lower_bound = ippGetRange(attr, 0, upper_bound); +} + void ExtractCopies(const CupsOptionProvider& printer, PrinterSemanticCapsAndDefaults* printer_info) { // copies @@ -250,42 +288,6 @@ void ExtractResolutions(const CupsOptionProvider& printer, printer_info->default_dpi = size.value(); } -} // namespace - -ColorModel DefaultColorModel(const CupsOptionProvider& printer) { - // default color - ipp_attribute_t* attr = printer.GetDefaultOptionValue(kIppColor); - if (!attr) - return UNKNOWN_COLOR_MODEL; - - return ColorModelFromIppColor(ippGetString(attr, 0, nullptr)); -} - -std::vector<ColorModel> SupportedColorModels( - const CupsOptionProvider& printer) { - std::vector<ColorModel> colors; - - std::vector<base::StringPiece> color_modes = - printer.GetSupportedOptionValueStrings(kIppColor); - for (base::StringPiece color : color_modes) { - ColorModel color_model = ColorModelFromIppColor(color); - if (color_model != UNKNOWN_COLOR_MODEL) { - colors.push_back(color_model); - } - } - - return colors; -} - -PrinterSemanticCapsAndDefaults::Paper DefaultPaper( - const CupsOptionProvider& printer) { - ipp_attribute_t* attr = printer.GetDefaultOptionValue(kIppMedia); - if (!attr) - return PrinterSemanticCapsAndDefaults::Paper(); - - return ParsePaper(ippGetString(attr, 0, nullptr)); -} - PrinterSemanticCapsAndDefaults::Papers SupportedPapers( const CupsOptionProvider& printer) { std::vector<base::StringPiece> papers = @@ -298,22 +300,10 @@ PrinterSemanticCapsAndDefaults::Papers SupportedPapers( return parsed_papers; } -void CopiesRange(const CupsOptionProvider& printer, - int* lower_bound, - int* upper_bound) { - ipp_attribute_t* attr = printer.GetSupportedOptionValues(kIppCopies); - if (!attr) { - *lower_bound = -1; - *upper_bound = -1; - } - - *lower_bound = ippGetRange(attr, 0, upper_bound); -} - bool CollateCapable(const CupsOptionProvider& printer) { std::vector<base::StringPiece> values = printer.GetSupportedOptionValueStrings(kIppCollate); - return base::ContainsValue(values, kCollated); + return base::Contains(values, kCollated); } bool CollateDefault(const CupsOptionProvider& printer) { @@ -325,6 +315,7 @@ bool CollateDefault(const CupsOptionProvider& printer) { return name.compare(kCollated) == 0; } +#if defined(OS_CHROMEOS) bool PinSupported(const CupsOptionProvider& printer) { ipp_attribute_t* attr = printer.GetSupportedOptionValues(kIppPin); if (!attr) @@ -335,7 +326,19 @@ bool PinSupported(const CupsOptionProvider& printer) { std::vector<base::StringPiece> values = printer.GetSupportedOptionValueStrings(kIppPinEncryption); - return base::ContainsValue(values, kPinEncryptionNone); + return base::Contains(values, kPinEncryptionNone); +} +#endif // defined(OS_CHROMEOS) + +} // namespace + +PrinterSemanticCapsAndDefaults::Paper DefaultPaper( + const CupsOptionProvider& printer) { + ipp_attribute_t* attr = printer.GetDefaultOptionValue(kIppMedia); + if (!attr) + return PrinterSemanticCapsAndDefaults::Paper(); + + return ParsePaper(ippGetString(attr, 0, nullptr)); } void CapsAndDefaultsFromPrinter(const CupsOptionProvider& printer, diff --git a/chromium/printing/backend/cups_ipp_util.h b/chromium/printing/backend/cups_ipp_util.h index 41c7a9fe165..21675c3d116 100644 --- a/chromium/printing/backend/cups_ipp_util.h +++ b/chromium/printing/backend/cups_ipp_util.h @@ -8,7 +8,6 @@ #define PRINTING_BACKEND_CUPS_IPP_UTIL_H_ #include <memory> -#include <vector> #include "printing/backend/cups_printer.h" #include "printing/backend/print_backend.h" @@ -21,7 +20,6 @@ extern const char kIppCopies[]; extern const char kIppColor[]; extern const char kIppMedia[]; extern const char kIppDuplex[]; -extern const char kIppDocumentName[]; extern const char kIppRequestingUserName[]; extern const char kIppPin[]; extern const char kIppPinEncryption[]; @@ -34,33 +32,10 @@ extern const char kPinEncryptionNone[]; // Smart ptr wrapper for CUPS ipp_t using ScopedIppPtr = std::unique_ptr<ipp_t, void (*)(ipp_t*)>; -// Returns the default ColorModel for |printer|. -ColorModel DefaultColorModel(const CupsOptionProvider& printer); - -// Returns the set of supported ColorModels for |printer|. -std::vector<ColorModel> SupportedColorModels(const CupsOptionProvider& printer); - // Returns the default paper setting for |printer|. PrinterSemanticCapsAndDefaults::Paper DefaultPaper( const CupsOptionProvider& printer); -// Returns the list of papers supported by the |printer|. -PrinterSemanticCapsAndDefaults::Papers SupportedPapers( - const CupsOptionProvider& printer); - -// Retrieves the supported number of copies from |printer| and writes the -// extremities of the range into |lower_bound| and |upper_bound|. Values are -// set to -1 if there is an error. -void CopiesRange(const CupsOptionProvider& printer, - int* lower_bound, - int* upper_bound); - -// Returns true if |printer| can do collation. -bool CollateCapable(const CupsOptionProvider& printer); - -// Returns true if |printer| has collation enabled by default. -bool CollateDefault(const CupsOptionProvider& printer); - // Populates the |printer_info| object with attributes retrived using IPP from // |printer|. PRINTING_EXPORT void CapsAndDefaultsFromPrinter( diff --git a/chromium/printing/backend/cups_jobs.cc b/chromium/printing/backend/cups_jobs.cc index 80d47634b9c..2ebcc422ae3 100644 --- a/chromium/printing/backend/cups_jobs.cc +++ b/chromium/printing/backend/cups_jobs.cc @@ -297,12 +297,6 @@ void ParseJobs(ipp_t* response, } } -// Returns the uri for printer with |id| as served by CUPS. Assumes that |id| -// is a valid CUPS printer name and performs no error checking or escaping. -std::string PrinterUriFromName(const std::string& id) { - return base::StringPrintf("ipp://localhost/printers/%s", id.c_str()); -} - // Extracts PrinterInfo fields from |response| and populates |printer_info|. // Returns true if at least printer-make-and-model and ipp-versions-supported // were read. @@ -325,8 +319,7 @@ bool ParsePrinterInfo(ipp_t* response, PrinterInfo* printer_info) { } else if (name == base::StringPiece(kIppFeaturesSupported)) { std::vector<std::string> features; ParseCollection(attr, &features); - printer_info->ipp_everywhere = - base::ContainsValue(features, kIppEverywhere); + printer_info->ipp_everywhere = base::Contains(features, kIppEverywhere); } else if (name == base::StringPiece(kDocumentFormatSupported)) { ParseCollection(attr, &printer_info->document_formats); } @@ -354,6 +347,10 @@ PrinterInfo::PrinterInfo() = default; PrinterInfo::~PrinterInfo() = default; +std::string PrinterUriFromName(const std::string& id) { + return base::StringPrintf("ipp://localhost/printers/%s", id.c_str()); +} + void ParseJobsResponse(ipp_t* response, const std::string& printer_id, std::vector<CupsJob>* jobs) { @@ -430,18 +427,18 @@ void ParsePrinterStatus(ipp_t* response, PrinterStatus* printer_status) { } } -bool GetPrinterInfo(const std::string& address, - const int port, - const std::string& resource, - bool encrypted, - PrinterInfo* printer_info) { +PrinterQueryResult GetPrinterInfo(const std::string& address, + const int port, + const std::string& resource, + bool encrypted, + PrinterInfo* printer_info) { ScopedHttpPtr http = ScopedHttpPtr(httpConnect2( address.c_str(), port, nullptr, AF_INET, encrypted ? HTTP_ENCRYPTION_ALWAYS : HTTP_ENCRYPTION_IF_REQUESTED, 0, kHttpConnectTimeoutMs, nullptr)); if (!http) { LOG(WARNING) << "Could not connect to host"; - return false; + return PrinterQueryResult::UNREACHABLE; } // TODO(crbug.com/821497): Use a library to canonicalize the URL. @@ -460,10 +457,13 @@ bool GetPrinterInfo(const std::string& address, kPrinterInfo.size(), kPrinterInfo.data(), &status); if (status != IPP_STATUS_OK || response.get() == nullptr) { LOG(WARNING) << "Get attributes failure: " << status; - return false; + return PrinterQueryResult::UNKNOWN_FAILURE; } - return ParsePrinterInfo(response.get(), printer_info); + if (ParsePrinterInfo(response.get(), printer_info)) { + return PrinterQueryResult::SUCCESS; + } + return PrinterQueryResult::UNKNOWN_FAILURE; } bool GetPrinterStatus(http_t* http, diff --git a/chromium/printing/backend/cups_jobs.h b/chromium/printing/backend/cups_jobs.h index c2606ebde97..854619e8ee3 100644 --- a/chromium/printing/backend/cups_jobs.h +++ b/chromium/printing/backend/cups_jobs.h @@ -14,6 +14,7 @@ #include <vector> #include "base/version.h" +#include "printing/printer_query_result_chromeos.h" #include "printing/printing_export.h" // This file contains a collection of functions used to query IPP printers or @@ -143,6 +144,10 @@ enum JobCompletionState { PROCESSING // only jobs that are being processed }; +// Returns the uri for printer with |id| as served by CUPS. Assumes that |id| is +// a valid CUPS printer name and performs no error checking or escaping. +std::string PRINTING_EXPORT PrinterUriFromName(const std::string& id); + // Extracts structured job information from the |response| for |printer_id|. // Extracted jobs are added to |jobs|. void ParseJobsResponse(ipp_t* response, @@ -155,11 +160,11 @@ void ParsePrinterStatus(ipp_t* response, PrinterStatus* printer_status); // Queries the printer at |address| on |port| with a Get-Printer-Attributes // request to populate |printer_info|. If |encrypted| is true, request is made // using ipps, otherwise, ipp is used. Returns false if the request failed. -bool PRINTING_EXPORT GetPrinterInfo(const std::string& address, - const int port, - const std::string& resource, - bool encrypted, - PrinterInfo* printer_info); +PrinterQueryResult PRINTING_EXPORT GetPrinterInfo(const std::string& address, + const int port, + const std::string& resource, + bool encrypted, + PrinterInfo* printer_info); // Attempts to retrieve printer status using connection |http| for |printer_id|. // Returns true if succcssful and updates the fields in |printer_status| as diff --git a/chromium/printing/backend/cups_printer.cc b/chromium/printing/backend/cups_printer.cc index 2fe9da8a919..44b686a2ee4 100644 --- a/chromium/printing/backend/cups_printer.cc +++ b/chromium/printing/backend/cups_printer.cc @@ -147,36 +147,40 @@ bool CupsPrinter::InitializeDestInfo() const { ipp_status_t CupsPrinter::CreateJob(int* job_id, const std::string& title, - const base::Optional<std::string>& username, + const std::string& username, const std::vector<cups_option_t>& options) { DCHECK(dest_info_) << "Verify availability before starting a print job"; cups_option_t* data = const_cast<cups_option_t*>( options.data()); // createDestJob will not modify the data - if (username) - cupsSetUser(username->c_str()); + if (!username.empty()) + cupsSetUser(username.c_str()); - ipp_status_t create_status = - cupsCreateDestJob(cups_http_, destination_.get(), dest_info_.get(), - job_id, title.c_str(), options.size(), data); + ipp_status_t create_status = cupsCreateDestJob( + cups_http_, destination_.get(), dest_info_.get(), job_id, + title.empty() ? nullptr : title.c_str(), options.size(), data); cupsSetUser(nullptr); // reset to default username ("anonymous") return create_status; } bool CupsPrinter::StartDocument(int job_id, - const std::string& document_name, + const std::string& docname, bool last_document, + const std::string& username, const std::vector<cups_option_t>& options) { DCHECK(dest_info_); DCHECK(job_id); + if (!username.empty()) + cupsSetUser(username.c_str()); cups_option_t* data = const_cast<cups_option_t*>( options.data()); // createStartDestDocument will not modify the data - http_status_t start_doc_status = - cupsStartDestDocument(cups_http_, destination_.get(), dest_info_.get(), - job_id, document_name.c_str(), CUPS_FORMAT_PDF, - options.size(), data, last_document ? 0 : 1); + http_status_t start_doc_status = cupsStartDestDocument( + cups_http_, destination_.get(), dest_info_.get(), job_id, + docname.empty() ? nullptr : docname.c_str(), CUPS_FORMAT_PDF, + options.size(), data, last_document ? 1 : 0); + cupsSetUser(nullptr); // reset to default username ("anonymous") return start_doc_status == HTTP_CONTINUE; } @@ -195,12 +199,16 @@ bool CupsPrinter::FinishDocument() { return status == IPP_STATUS_OK; } -ipp_status_t CupsPrinter::CloseJob(int job_id) { +ipp_status_t CupsPrinter::CloseJob(int job_id, const std::string& username) { DCHECK(dest_info_); DCHECK(job_id); + if (!username.empty()) + cupsSetUser(username.c_str()); - return cupsCloseDestJob(cups_http_, destination_.get(), dest_info_.get(), - job_id); + ipp_status_t result = cupsCloseDestJob(cups_http_, destination_.get(), + dest_info_.get(), job_id); + cupsSetUser(nullptr); // reset to default username ("anonymous") + return result; } bool CupsPrinter::CancelJob(int job_id) { diff --git a/chromium/printing/backend/cups_printer.h b/chromium/printing/backend/cups_printer.h index d1b666d6626..d66ba52448e 100644 --- a/chromium/printing/backend/cups_printer.h +++ b/chromium/printing/backend/cups_printer.h @@ -87,21 +87,23 @@ class PRINTING_EXPORT CupsPrinter : public CupsOptionProvider { bool ToPrinterInfo(PrinterBasicInfo* basic_info) const; // Start a print job. Writes the id of the started job to |job_id|. |job_id| - // is 0 if there is an error. Check availability before using this operation. - // Usage on an unavailable printer is undefined. + // is 0 if there is an error. |title| is not sent if empty. |username| is + // not sent if empty. Check availability before using this operation. Usage + // on an unavailable printer is undefined. ipp_status_t CreateJob(int* job_id, const std::string& title, - const base::Optional<std::string>& username, + const std::string& username, const std::vector<cups_option_t>& options); // Add a document to a print job. |job_id| must be non-zero and refer to a - // job started with CreateJob. |document_name| will be displayed in print - // status. |last_doc| should be true if this is the last document for this - // print job. |options| should be IPP key value pairs for the Send-Document - // operation. + // job started with CreateJob. |docname| will be displayed in print status + // if not empty. |last_doc| should be true if this is the last document for + // this print job. |username| is not sent if empty. |options| should be IPP + // key value pairs for the Send-Document operation. bool StartDocument(int job_id, - const std::string& document_name, + const std::string& docname, bool last_doc, + const std::string& username, const std::vector<cups_option_t>& options); // Add data to the current document started by StartDocument. Calling this @@ -113,8 +115,9 @@ class PRINTING_EXPORT CupsPrinter : public CupsOptionProvider { bool FinishDocument(); // Close the job. If the job is not closed, the documents will not be - // printed. |job_id| should match the id from CreateJob. - ipp_status_t CloseJob(int job_id); + // printed. |job_id| should match the id from CreateJob. |username| is not + // sent if empty. + ipp_status_t CloseJob(int job_id, const std::string& username); // Cancel the print job |job_id|. Returns true if the operation succeeded. // Returns false if it failed for any reason. diff --git a/chromium/printing/backend/test_print_backend.cc b/chromium/printing/backend/test_print_backend.cc index fdb7e8dbf53..0388951dc1a 100644 --- a/chromium/printing/backend/test_print_backend.cc +++ b/chromium/printing/backend/test_print_backend.cc @@ -66,7 +66,7 @@ std::string TestPrintBackend::GetPrinterDriverInfo( } bool TestPrintBackend::IsValidPrinter(const std::string& printer_name) { - return base::ContainsKey(valid_printers_, printer_name); + return base::Contains(valid_printers_, printer_name); } void TestPrintBackend::PopulatePrinterList(const PrinterList& printer_list) { diff --git a/chromium/printing/common/BUILD.gn b/chromium/printing/common/BUILD.gn index c40a79c8721..4143ca728c7 100644 --- a/chromium/printing/common/BUILD.gn +++ b/chromium/printing/common/BUILD.gn @@ -6,10 +6,15 @@ source_set("common") { sources = [ "metafile_utils.cc", "metafile_utils.h", + "printing_features.cc", + "printing_features.h", ] deps = [ "//base", + "//printing:printing_export", "//skia", ] + + defines = [ "PRINTING_IMPLEMENTATION" ] } diff --git a/chromium/printing/common/metafile_utils.cc b/chromium/printing/common/metafile_utils.cc index 1dcae3a89c7..eae01fb862e 100644 --- a/chromium/printing/common/metafile_utils.cc +++ b/chromium/printing/common/metafile_utils.cc @@ -5,6 +5,7 @@ #include "printing/common/metafile_utils.h" #include "base/time/time.h" +#include "printing/common/printing_features.h" #include "third_party/skia/include/core/SkCanvas.h" #include "third_party/skia/include/core/SkPicture.h" #include "third_party/skia/include/core/SkPictureRecorder.h" @@ -51,6 +52,10 @@ sk_sp<SkDocument> MakePdfDocument(const std::string& creator, ? SkString("Chromium") : SkString(creator.c_str(), creator.size()); metadata.fRasterDPI = 300.0f; + metadata.fSubsetter = + base::FeatureList::IsEnabled(printing::features::kHarfBuzzPDFSubsetter) + ? SkPDF::Metadata::kHarfbuzz_Subsetter + : SkPDF::Metadata::kSfntly_Subsetter; return SkPDF::MakeDocument(stream, metadata); } diff --git a/chromium/printing/common/printing_features.cc b/chromium/printing/common/printing_features.cc new file mode 100644 index 00000000000..41b37e0c4ea --- /dev/null +++ b/chromium/printing/common/printing_features.cc @@ -0,0 +1,14 @@ +// Copyright 2019 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. + +#include "printing/common/printing_features.h" + +namespace printing { +namespace features { + +const base::Feature kHarfBuzzPDFSubsetter{"HarfBuzzPDFSubsetter", + base::FEATURE_DISABLED_BY_DEFAULT}; + +} // namespace features +} // namespace printing diff --git a/chromium/printing/common/printing_features.h b/chromium/printing/common/printing_features.h new file mode 100644 index 00000000000..22c62950896 --- /dev/null +++ b/chromium/printing/common/printing_features.h @@ -0,0 +1,19 @@ +// Copyright 2019 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 PRINTING_COMMON_PRINTING_FEATURES_H_ +#define PRINTING_COMMON_PRINTING_FEATURES_H_ + +#include "base/feature_list.h" +#include "printing/printing_export.h" + +namespace printing { +namespace features { + +PRINTING_EXPORT extern const base::Feature kHarfBuzzPDFSubsetter; + +} // namespace features +} // namespace printing + +#endif // PRINTING_COMMON_PRINTING_FEATURES_H_ diff --git a/chromium/printing/metafile_skia.cc b/chromium/printing/metafile_skia.cc index b6e5876fa57..b0c1ea7873f 100644 --- a/chromium/printing/metafile_skia.cc +++ b/chromium/printing/metafile_skia.cc @@ -343,7 +343,7 @@ uint32_t MetafileSkia::CreateContentForRemoteFrame(const gfx::Rect& rect, // Store the map between content id and the proxy id. uint32_t content_id = pic->uniqueID(); - DCHECK(!base::ContainsKey(data_->subframe_content_info, content_id)); + DCHECK(!base::Contains(data_->subframe_content_info, content_id)); data_->subframe_content_info[content_id] = render_proxy_id; // Store the picture content. @@ -378,7 +378,7 @@ SkStreamAsset* MetafileSkia::GetPdfData() const { void MetafileSkia::CustomDataToSkPictureCallback(SkCanvas* canvas, uint32_t content_id) { // Check whether this is the one we need to handle. - if (!base::ContainsKey(data_->subframe_content_info, content_id)) + if (!base::Contains(data_->subframe_content_info, content_id)) return; auto it = data_->subframe_pics.find(content_id); diff --git a/chromium/printing/print_job_constants.cc b/chromium/printing/print_job_constants.cc index 5817cb0b75a..82d7644637f 100644 --- a/chromium/printing/print_job_constants.cc +++ b/chromium/printing/print_job_constants.cc @@ -63,9 +63,6 @@ const char kSettingFitToPageScaling[] = "fitToPageScaling"; // Print job duplex mode. Value is an int from DuplexMode enum. const char kSettingDuplexMode[] = "duplex"; -// Job title to be sent to printer. -const char kSettingJobTitle[] = "jobTitle"; - // Option to fit source page contents to printer paper size: true if // selected else false. const char kSettingFitToPageEnabled[] = "fitToPageEnabled"; diff --git a/chromium/printing/print_job_constants.h b/chromium/printing/print_job_constants.h index 017b6b828b6..299a97f4fe2 100644 --- a/chromium/printing/print_job_constants.h +++ b/chromium/printing/print_job_constants.h @@ -34,7 +34,6 @@ PRINTING_EXPORT extern const float kSettingHeaderFooterInterstice; PRINTING_EXPORT extern const char kSettingHeaderFooterDate[]; PRINTING_EXPORT extern const char kSettingHeaderFooterTitle[]; PRINTING_EXPORT extern const char kSettingHeaderFooterURL[]; -PRINTING_EXPORT extern const char kSettingJobTitle[]; PRINTING_EXPORT extern const char kSettingLandscape[]; PRINTING_EXPORT extern const char kSettingMediaSize[]; PRINTING_EXPORT extern const char kSettingMediaSizeHeightMicrons[]; diff --git a/chromium/printing/print_settings.h b/chromium/printing/print_settings.h index 7ac22759c6b..3d9c3c5fa7e 100644 --- a/chromium/printing/print_settings.h +++ b/chromium/printing/print_settings.h @@ -199,9 +199,6 @@ class PRINTING_EXPORT PrintSettings { void set_username(const std::string& username) { username_ = username; } const std::string& username() const { return username_; } - void set_job_title(const std::string& job_title) { job_title_ = job_title; } - const std::string& job_title() const { return job_title_; } - void set_pin_value(const std::string& pin_value) { pin_value_ = pin_value; } const std::string& pin_value() const { return pin_value_; } #endif diff --git a/chromium/printing/print_settings_conversion.cc b/chromium/printing/print_settings_conversion.cc index 2ba73332677..2563ae6a87b 100644 --- a/chromium/printing/print_settings_conversion.cc +++ b/chromium/printing/print_settings_conversion.cc @@ -217,10 +217,6 @@ bool PrintSettingsFromJobSettings(const base::Value& job_settings, const std::string* username = job_settings.FindStringKey(kSettingUsername); if (username) settings->set_username(*username); - - const std::string* job_title = job_settings.FindStringKey(kSettingJobTitle); - if (job_title) - settings->set_job_title(*job_title); } const std::string* pin_value = job_settings.FindStringKey(kSettingPinValue); diff --git a/chromium/printing/print_settings_conversion_unittest.cc b/chromium/printing/print_settings_conversion_unittest.cc index 2b28cb90e7c..e8a0a7cabed 100644 --- a/chromium/printing/print_settings_conversion_unittest.cc +++ b/chromium/printing/print_settings_conversion_unittest.cc @@ -42,7 +42,6 @@ const char kPrinterSettings[] = R"({ "previewModifiable": true, "sendUserInfo": true, "username": "username@domain.net", - "jobTitle": "test.pdf", "pinValue": "0000" })"; @@ -59,7 +58,6 @@ TEST(PrintSettingsConversionTest, ConversionTest) { #if defined(OS_CHROMEOS) EXPECT_TRUE(settings.send_user_info()); EXPECT_EQ("username@domain.net", settings.username()); - EXPECT_EQ("test.pdf", settings.job_title()); EXPECT_EQ("0000", settings.pin_value()); #endif } @@ -76,7 +74,6 @@ TEST(PrintSettingsConversionTest, ConversionTest_DontSendUsername) { ASSERT_TRUE(success); EXPECT_FALSE(settings.send_user_info()); EXPECT_EQ("", settings.username()); - EXPECT_EQ("", settings.job_title()); } #endif diff --git a/chromium/printing/printer_query_result_chromeos.h b/chromium/printing/printer_query_result_chromeos.h new file mode 100644 index 00000000000..8f926a8da13 --- /dev/null +++ b/chromium/printing/printer_query_result_chromeos.h @@ -0,0 +1,21 @@ +// Copyright 2019 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 PRINTING_PRINTER_QUERY_RESULT_CHROMEOS_H_ +#define PRINTING_PRINTER_QUERY_RESULT_CHROMEOS_H_ + +#include "printing/printing_export.h" + +namespace printing { + +// Specifies query status codes. +enum PRINTING_EXPORT PrinterQueryResult { + UNKNOWN_FAILURE, // catchall error + SUCCESS, // successful + UNREACHABLE, // failed to reach the host +}; + +} // namespace printing + +#endif // PRINTING_PRINTER_QUERY_RESULT_CHROMEOS_H_ diff --git a/chromium/printing/printing_context_android.cc b/chromium/printing/printing_context_android.cc index ec40ab6877f..05f9ed64b6c 100644 --- a/chromium/printing/printing_context_android.cc +++ b/chromium/printing/printing_context_android.cc @@ -16,9 +16,9 @@ #include "base/memory/ptr_util.h" #include "base/strings/string_number_conversions.h" #include "base/values.h" -#include "jni/PrintingContext_jni.h" #include "printing/metafile.h" #include "printing/print_job_constants.h" +#include "printing/printing_jni_headers/PrintingContext_jni.h" #include "printing/units.h" #include "third_party/icu/source/i18n/unicode/ulocdata.h" #include "ui/android/window_android.h" diff --git a/chromium/printing/printing_context_chromeos.cc b/chromium/printing/printing_context_chromeos.cc index db0972fa77f..ed78b7619e3 100644 --- a/chromium/printing/printing_context_chromeos.cc +++ b/chromium/printing/printing_context_chromeos.cc @@ -125,11 +125,6 @@ std::vector<ScopedCupsOption> SettingsToCupsOptions( options.push_back( ConstructOption(kIppCollate, GetCollateString(settings.collate()))); // collate - if (settings.send_user_info()) { - options.push_back(ConstructOption(kIppDocumentName, settings.job_title())); - options.push_back( - ConstructOption(kIppRequestingUserName, settings.username())); - } if (!settings.pin_value().empty()) { options.push_back(ConstructOption(kIppPin, settings.pin_value())); options.push_back(ConstructOption(kIppPinEncryption, kPinEncryptionNone)); @@ -162,7 +157,8 @@ std::unique_ptr<PrintingContext> PrintingContext::Create(Delegate* delegate) { PrintingContextChromeos::PrintingContextChromeos(Delegate* delegate) : PrintingContext(delegate), - connection_(GURL(), HTTP_ENCRYPT_NEVER, true) {} + connection_(GURL(), HTTP_ENCRYPT_NEVER, true), + send_user_info_(false) {} PrintingContextChromeos::~PrintingContextChromeos() { ReleaseContext(); @@ -268,6 +264,9 @@ PrintingContext::Result PrintingContextChromeos::UpdatePrinterSettings( } SetPrintableArea(&settings_, media, true); + cups_options_ = SettingsToCupsOptions(settings_); + send_user_info_ = settings_.send_user_info(); + username_ = send_user_info_ ? settings_.username() : std::string(); return OK; } @@ -292,17 +291,13 @@ PrintingContext::Result PrintingContextChromeos::NewDocument( DCHECK(!in_print_job_); in_print_job_ = true; - std::string converted_name = base::UTF16ToUTF8(document_name); - std::string title = base::UTF16ToUTF8(settings_.title()); - std::vector<ScopedCupsOption> cups_options = SettingsToCupsOptions(settings_); + std::string converted_name; + if (send_user_info_) + converted_name = base::UTF16ToUTF8(document_name); std::vector<cups_option_t> options; - base::Optional<std::string> username; - const base::StringPiece requestingUserName(kIppRequestingUserName); - for (const ScopedCupsOption& option : cups_options) { - if (option->name == requestingUserName) { - username = option->value; - } else if (printer_->CheckOptionSupported(option->name, option->value)) { + for (const ScopedCupsOption& option : cups_options_) { + if (printer_->CheckOptionSupported(option->name, option->value)) { options.push_back(*(option.get())); } else { DVLOG(1) << "Unsupported option skipped " << option->name << ", " @@ -311,7 +306,7 @@ PrintingContext::Result PrintingContextChromeos::NewDocument( } ipp_status_t create_status = - printer_->CreateJob(&job_id_, title, username, options); + printer_->CreateJob(&job_id_, converted_name, username_, options); if (job_id_ == 0) { DLOG(WARNING) << "Creating cups job failed" @@ -320,7 +315,8 @@ PrintingContext::Result PrintingContextChromeos::NewDocument( } // we only send one document, so it's always the last one - if (!printer_->StartDocument(job_id_, converted_name, true, options)) { + if (!printer_->StartDocument(job_id_, converted_name, true, username_, + options)) { LOG(ERROR) << "Starting document failed"; return OnError(); } @@ -361,7 +357,7 @@ PrintingContext::Result PrintingContextChromeos::DocumentDone() { return OnError(); } - ipp_status_t job_status = printer_->CloseJob(job_id_); + ipp_status_t job_status = printer_->CloseJob(job_id_, username_); job_id_ = 0; if (job_status != IPP_STATUS_OK) { diff --git a/chromium/printing/printing_context_chromeos.h b/chromium/printing/printing_context_chromeos.h index f2c30be9ce8..519c2557659 100644 --- a/chromium/printing/printing_context_chromeos.h +++ b/chromium/printing/printing_context_chromeos.h @@ -42,11 +42,16 @@ class PRINTING_EXPORT PrintingContextChromeos : public PrintingContext { Result StreamData(const std::vector<char>& buffer); private: + using ScopedCupsOption = std::unique_ptr<cups_option_t, OptionDeleter>; + // Lazily initializes |printer_|. Result InitializeDevice(const std::string& device); CupsConnection connection_; std::unique_ptr<CupsPrinter> printer_; + std::vector<ScopedCupsOption> cups_options_; + bool send_user_info_; + std::string username_; DISALLOW_COPY_AND_ASSIGN(PrintingContextChromeos); }; diff --git a/chromium/printing/printing_context_win_unittest.cc b/chromium/printing/printing_context_win_unittest.cc index 09ae599da72..59aabfc2a19 100644 --- a/chromium/printing/printing_context_win_unittest.cc +++ b/chromium/printing/printing_context_win_unittest.cc @@ -8,7 +8,7 @@ #include <stdint.h> #include "base/bind.h" -#include "base/message_loop/message_loop.h" +#include "base/test/scoped_task_environment.h" #include "base/win/scoped_handle.h" #include "base/win/scoped_hdc.h" #include "printing/backend/printing_info_win.h" @@ -145,7 +145,7 @@ TEST_F(PrintingContextTest, PrintAll) { if (IsTestCaseDisabled()) return; - base::MessageLoop message_loop; + base::test::ScopedTaskEnvironment scoped_task_environment; MockPrintingContextWin context(this); context.AskUserForSettings( 123, false, false, @@ -160,7 +160,7 @@ TEST_F(PrintingContextTest, Color) { if (IsTestCaseDisabled()) return; - base::MessageLoop message_loop; + base::test::ScopedTaskEnvironment scoped_task_environment; MockPrintingContextWin context(this); context.AskUserForSettings( 123, false, false, |