Bug 1666964 - Retrieve Printer Default Media Through IPP Attribute r=hiro

cupsGetDestMediaDefault seems to not be returning the correct defaults,
so this patch retrieves the default media through the IPP attribute
instead, in hopes that this will provide more accurate defaults.

Differential Revision: https://phabricator.services.mozilla.com/D91376
This commit is contained in:
Erik Nordin 2020-09-25 02:00:46 +00:00
parent bbfbd2f113
commit 001639575c
2 changed files with 16 additions and 0 deletions

View File

@ -34,11 +34,13 @@ class nsCUPSShim {
X(cupsCopyDest) \
X(cupsCopyDestInfo) \
X(cupsDoRequest) \
X(cupsFindDestDefault) \
X(cupsFreeDestInfo) \
X(cupsFreeDests) \
X(cupsGetDestMediaDefault) \
X(cupsGetDestMediaCount) \
X(cupsGetDestMediaByIndex) \
X(cupsGetDestMediaByName) \
X(cupsGetDest) \
X(cupsGetDests) \
X(cupsGetNamedDest) \

View File

@ -96,9 +96,23 @@ PrintSettingsInitializer nsPrinterCUPS::DefaultSettings() const {
cups_size_t media;
// cupsGetDestMediaDefault appears to return more accurate defaults on macOS,
// and the IPP attribute appears to return more accurate defaults on Linux.
#ifdef XP_MACOSX
bool hasDefaultMedia =
mShim.cupsGetDestMediaDefault(CUPS_HTTP_DEFAULT, mPrinter, printerInfo,
CUPS_MEDIA_FLAGS_DEFAULT, &media);
#else
ipp_attribute_t* defaultMediaIPP = mShim.cupsFindDestDefault(
CUPS_HTTP_DEFAULT, mPrinter, printerInfo, "media");
const char* defaultMediaName =
mShim.ippGetString(defaultMediaIPP, 0, nullptr);
bool hasDefaultMedia = mShim.cupsGetDestMediaByName(
CUPS_HTTP_DEFAULT, mPrinter, printerInfo, defaultMediaName,
CUPS_MEDIA_FLAGS_DEFAULT, &media);
#endif
if (!hasDefaultMedia) {
return PrintSettingsInitializer{