Bug 1319116 - Part 1 - Firefox print settings for header and footer not remembered r=jwatt

Load the saved printer-specific settings prefs before displaying the print dialog.

PrintSettings received from sandboxed content processes do not include the printer name because access to the printer server is blocked by sandboxing.

Differential Revision: https://phabricator.services.mozilla.com/D23888

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Haik Aftandilian 2019-03-26 20:15:53 +00:00
Родитель b9a573d30f
Коммит 29bb07756f
3 изменённых файлов: 29 добавлений и 3 удалений

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

@ -47,6 +47,12 @@ nsPrintDialogServiceX::Show(nsPIDOMWindowOuter* aParent, nsIPrintSettings* aSett
nsCOMPtr<nsIPrintSettingsService> printSettingsSvc =
do_GetService("@mozilla.org/gfx/printsettings-service;1");
// Set the printer name and then read the saved printer settings
// from prefs. Reading printer-specific prefs requires the printer
// name to be set.
settingsX->SetPrinterNameFromPrintInfo();
printSettingsSvc->InitPrintSettingsFromPrefs(settingsX, true,
nsIPrintSettings::kInitSaveAll);
// Set the print job title
char16_t** docTitles;
uint32_t titleCount;
@ -72,9 +78,6 @@ nsPrintDialogServiceX::Show(nsPIDOMWindowOuter* aParent, nsIPrintSettings* aSett
titleCount = 0;
}
// Read default print settings from prefs
printSettingsSvc->InitPrintSettingsFromPrefs(settingsX, true,
nsIPrintSettings::kInitSaveNativeData);
NSPrintInfo* printInfo = settingsX->GetCocoaPrintInfo();
// Put the print info into the current print operation, since that's where

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

@ -85,6 +85,9 @@ class nsPrintSettingsX : public nsPrintSettings {
void GetAdjustedPaperSize(double *aWidth, double *aHeight);
nsresult SetCocoaPaperSize(double aWidth, double aHeight);
// Set the printer name using the native PrintInfo data.
void SetPrinterNameFromPrintInfo();
protected:
virtual ~nsPrintSettingsX();

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

@ -457,3 +457,23 @@ nsresult nsPrintSettingsX::SetCocoaPaperSize(double aWidth, double aHeight) {
NS_OBJC_END_TRY_ABORT_BLOCK_NSRESULT;
}
void nsPrintSettingsX::SetPrinterNameFromPrintInfo() {
NS_OBJC_BEGIN_TRY_ABORT_BLOCK;
// Don't attempt to call this from child processes.
// Process sandboxing prevents access to the print
// server and printer-related settings.
MOZ_ASSERT(XRE_IsParentProcess());
MOZ_ASSERT(mPrintInfo);
NSMutableDictionary* printInfoDict = [mPrintInfo dictionary];
NSString* nsPrinterNameValue = [printInfoDict objectForKey:@"NSPrinterName"];
if (nsPrinterNameValue) {
nsAutoString printerName;
nsCocoaUtils::GetStringForNSString(nsPrinterNameValue, printerName);
mPrinter.Assign(printerName);
}
NS_OBJC_END_TRY_ABORT_BLOCK;
}