Bug 1663920 - Ignore CUPS_PRINTER_DISCOVERED, CUPS_PRINTER_FAX and CUPS_PRINTER_SCANNER in the CUPS backend. ?AlaskanEmily r=AlaskanEmily

Differential Revision: https://phabricator.services.mozilla.com/D90508
This commit is contained in:
Hiroyuki Ikezoe 2020-09-25 01:10:12 +00:00
Родитель baf3127120
Коммит fd92b1e73e
1 изменённых файлов: 18 добавлений и 0 удалений

Просмотреть файл

@ -39,12 +39,30 @@ nsTArray<PrinterInfo> nsPrinterListCUPS::Printers() const {
nsTArray<PrinterInfo> printerInfoList;
cups_dest_t* printers = nullptr;
// Ideally we should use cupsEnumDests with CUPS_PRINTER_DISCOVERED, etc.
// flags instead of calling cupsGetDests and filtering out
// CUPS_PRINTER_DISCOVERED later, because it should be faster than the
// cupsGetDests call. That being said, unfortunately at least on Ubuntu 20.20
// cupsEnumDests doesn't filter out CUPS_PRINTER_DISCOVERED-ed printers at
// all. So for now we use cupsGetDests but if we still have perf issues when
// we enumerate available printers on Mac, we should use cupsEnumDest at least
// on Mac.
auto numPrinters = sCupsShim.cupsGetDests(&printers);
printerInfoList.SetCapacity(numPrinters);
for (auto i : mozilla::IntegerRange(0, numPrinters)) {
cups_dest_t* dest = printers + i;
if (const char* printerType = sCupsShim.cupsGetOption(
"printer-type", dest->num_options, dest->options)) {
nsresult rv;
int64_t type = nsAutoCString(printerType).ToInteger64(&rv);
if (NS_SUCCEEDED(rv) && (type & (CUPS_PRINTER_FAX | CUPS_PRINTER_SCANNER |
CUPS_PRINTER_DISCOVERED))) {
continue;
}
}
cups_dest_t* ownedDest = nullptr;
mozilla::DebugOnly<const int> numCopied =
sCupsShim.cupsCopyDest(dest, 0, &ownedDest);