Skip to content

Commit

Permalink
Bug 968753 - Save per-printer settings on GTK. r=jwatt
Browse files Browse the repository at this point in the history
I don't see any reason why this shouldn't work off-hand, there's no
gtk globals or such that fundamentally avoid sharing settings.

The PSPrinters stuff is gone so it's not needed to mess up with PS/CUPS
names.

The last used printer name stuff is now just a pref read, so there
shouldn't be sandbox violation shenanigans...

There are some restrictions on what can be set or what not (like, if you
set the paper name that may also override the paper size).

But these are problems that we have when restoring from prefs already,
so there's no reason we shouldn't do this, afaict.

Differential Revision: https://phabricator.services.mozilla.com/D90418
  • Loading branch information
emilio committed Sep 16, 2020
1 parent c98bb99 commit 2b01dbb
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 34 deletions.
7 changes: 0 additions & 7 deletions layout/printing/nsPrintJob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,13 +306,6 @@ static nsresult EnsureSettingsHasPrinterNameSet(
// Mac doesn't support retrieving a printer list.
return NS_OK;
#else
# if defined(MOZ_X11)
// On Linux, last-used printer name should be requested on the parent side.
// Unless we are in the parent, we ignore this function
if (!XRE_IsParentProcess()) {
return NS_OK;
}
# endif
NS_ENSURE_ARG_POINTER(aPrintSettings);

// See if aPrintSettings already has a printer
Expand Down
2 changes: 1 addition & 1 deletion widget/gtk/nsPrintSettingsGTK.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ NS_IMETHODIMP
nsPrintSettingsGTK::GetPaperName(nsAString& aPaperName) {
const gchar* name =
gtk_paper_size_get_name(gtk_page_setup_get_paper_size(mPageSetup));
CopyUTF8toUTF16(MakeStringSpan(name), aPaperName);
CopyUTF8toUTF16(mozilla::MakeStringSpan(name), aPaperName);
return NS_OK;
}
NS_IMETHODIMP
Expand Down
29 changes: 3 additions & 26 deletions widget/nsPrintSettingsService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -867,20 +867,7 @@ nsPrintSettingsService::GetDefaultPrintSettingsForPrinting(

nsAutoString printerName;
settings->GetPrinterName(printerName);

bool shouldGetLastUsedPrinterName = printerName.IsEmpty();
#ifdef MOZ_X11
// In Linux, GTK backend does not support per printer settings.
// Calling GetLastUsedPrinterName causes a sandbox violation (see Bug
// 1329216). The printer name is not needed anywhere else on Linux
// before it gets to the parent. In the parent, we will then query the
// last-used printer name if no name is set. Unless we are in the parent,
// we will skip this part.
if (!XRE_IsParentProcess()) {
shouldGetLastUsedPrinterName = false;
}
#endif
if (shouldGetLastUsedPrinterName) {
if (printerName.IsEmpty()) {
GetLastUsedPrinterName(printerName);
settings->SetPrinterName(printerName);
}
Expand Down Expand Up @@ -945,7 +932,6 @@ nsPrintSettingsService::InitPrintSettingsFromPrinter(
return rv;
}

#ifndef MOZ_X11
/** ---------------------------------------------------
* Helper function - Returns either the name or sets the length to zero
*/
Expand Down Expand Up @@ -978,7 +964,6 @@ static nsresult GetAdjustedPrinterName(nsIPrintSettings* aPS, bool aUsePNP,
}
return NS_OK;
}
#endif

NS_IMETHODIMP
nsPrintSettingsService::InitPrintSettingsFromPrefs(nsIPrintSettings* aPS,
Expand All @@ -997,11 +982,8 @@ nsPrintSettingsService::InitPrintSettingsFromPrefs(nsIPrintSettings* aPS,
nsresult rv = ReadPrefs(aPS, prtName, aFlags);
NS_ENSURE_SUCCESS(rv, rv);

// Do not use printer name in Linux because GTK backend does not support
// per printer settings.
#ifndef MOZ_X11
// Get the Printer Name from the PrintSettings
// to use as a prefix for Pref Names
// Get the Printer Name from the PrintSettings to use as a prefix for Pref
// Names
rv = GetAdjustedPrinterName(aPS, aUsePNP, prtName);
NS_ENSURE_SUCCESS(rv, rv);

Expand All @@ -1013,7 +995,6 @@ nsPrintSettingsService::InitPrintSettingsFromPrefs(nsIPrintSettings* aPS,
// Now read any printer specific prefs
rv = ReadPrefs(aPS, prtName, aFlags);
if (NS_SUCCEEDED(rv)) aPS->SetIsInitializedFromPrefs(true);
#endif

return NS_OK;
}
Expand All @@ -1036,13 +1017,9 @@ nsresult nsPrintSettingsService::SavePrintSettingsToPrefs(

nsAutoString prtName;

// Do not use printer name in Linux because GTK backend does not support
// per printer settings.
#ifndef MOZ_X11
// Get the printer name from the PrinterSettings for an optional prefix.
nsresult rv = GetAdjustedPrinterName(aPS, aUsePrinterNamePrefix, prtName);
NS_ENSURE_SUCCESS(rv, rv);
#endif

// Write the prefs, with or without a printer name prefix.
return WritePrefs(aPS, prtName, aFlags);
Expand Down

0 comments on commit 2b01dbb

Please sign in to comment.