Skip to content

Commit

Permalink
Bug 1666964 - Retrieve Printer Default Media Through IPP Attribute r=…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
nordzilla committed Sep 25, 2020
1 parent bbfbd2f commit 0016395
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions widget/nsCUPSShim.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) \
Expand Down
14 changes: 14 additions & 0 deletions widget/nsPrinterCUPS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit 0016395

Please sign in to comment.