Bug 1755153 p2 - Prevent saving print settings to prefs if print.save_print_settings=false. r=emilio

Depends on D146943

Differential Revision: https://phabricator.services.mozilla.com/D146944
This commit is contained in:
Jonathan Watt 2022-10-30 10:32:28 +00:00
Родитель 17f8eb8dec
Коммит 2b527f4d33
8 изменённых файлов: 32 добавлений и 21 удалений

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

@ -398,7 +398,7 @@ var PrintEventHandler = {
await window._initialized;
// This seems like it should be handled automatically but it isn't.
PSSVC.saveLastUsedPrinterNameToPrefs(settings.printerName);
PSSVC.maybeSaveLastUsedPrinterNameToPrefs(settings.printerName);
try {
// We'll provide our own progress indicator.
@ -795,7 +795,7 @@ var PrintEventHandler = {
},
saveSettingsToPrefs(flags) {
PSSVC.savePrintSettingsToPrefs(this.settings, flags);
PSSVC.maybeSavePrintSettingsToPrefs(this.settings, flags);
},
/**

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

@ -522,7 +522,7 @@ function onAccept() {
// XXX Should we do this in nsPrintDialogServiceWin::ShowPageSetup (the code
// that invokes us), since ShowPageSetup is where we do the saving for the
// other platforms?
gPrintService.savePrintSettingsToPrefs(gPrintSettings, flags);
gPrintService.maybeSavePrintSettingsToPrefs(gPrintSettings, flags);
}
// ---------------------------------------------------

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

@ -115,8 +115,8 @@ var PrintUtils = {
);
if (!PSSVC.lastUsedPrinterName) {
if (printSettings.printerName) {
PSSVC.saveLastUsedPrinterNameToPrefs(printSettings.printerName);
PSSVC.savePrintSettingsToPrefs(
PSSVC.maybeSaveLastUsedPrinterNameToPrefs(printSettings.printerName);
PSSVC.maybeSavePrintSettingsToPrefs(
printSettings,
Ci.nsIPrintSettings.kInitSaveAll
);
@ -352,8 +352,8 @@ var PrintUtils = {
var PSSVC = Cc["@mozilla.org/gfx/printsettings-service;1"].getService(
Ci.nsIPrintSettingsService
);
PSSVC.saveLastUsedPrinterNameToPrefs(settings.printerName);
PSSVC.savePrintSettingsToPrefs(
PSSVC.maybeSaveLastUsedPrinterNameToPrefs(settings.printerName);
PSSVC.maybeSavePrintSettingsToPrefs(
settings,
Ci.nsIPrintSettings.kInitSaveAll
);

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

@ -122,7 +122,8 @@ nsPrintDialogServiceX::ShowPrintDialog(mozIDOMWindowProxy* aParent, bool aHaveSe
// Save settings unless saving is pref'd off
if (Preferences::GetBool("print.save_print_settings", false)) {
printSettingsSvc->SavePrintSettingsToPrefs(settingsX, nsIPrintSettings::kInitSaveNativeData);
printSettingsSvc->MaybeSavePrintSettingsToPrefs(settingsX,
nsIPrintSettings::kInitSaveNativeData);
}
return NS_OK;
@ -166,7 +167,7 @@ nsPrintDialogServiceX::ShowPageSetupDialog(mozIDOMWindowProxy* aParent,
uint32_t flags = nsIPrintSettings::kInitSaveNativeData |
nsIPrintSettings::kInitSavePaperSize |
nsIPrintSettings::kInitSaveOrientation | nsIPrintSettings::kInitSaveScaling;
printSettingsService->SavePrintSettingsToPrefs(aNSSettings, flags);
printSettingsService->MaybeSavePrintSettingsToPrefs(aNSSettings, flags);
}
return NS_OK;
}

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

@ -598,7 +598,7 @@ nsPrintDialogServiceGTK::ShowPageSetupDialog(mozIDOMWindowProxy* aParent,
g_object_unref(newPageSetup);
if (psService)
psService->SavePrintSettingsToPrefs(
psService->MaybeSavePrintSettingsToPrefs(
aNSSettings, nsIPrintSettings::kInitSaveOrientation |
nsIPrintSettings::kInitSavePaperSize |
nsIPrintSettings::kInitSaveUnwriteableMargins);

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

@ -85,8 +85,9 @@ interface nsIPrintSettingsService : nsISupports
void initPrintSettingsFromPrefs(in nsIPrintSettings aPrintSettings, in boolean aUsePrinterNamePrefix, in unsigned long aFlags);
/**
* Writes PrintSettings values to Prefs,
* the values to be written are indicated by the "flags" arg.
* As long as the pref print.save_print_settings isn't set to false, this
* saves to prefs the settings from aPrintSettings that are indicated by
* aFlags.
*
* If there is no PrinterName in the PrinterSettings
* the values are saved as the "generic" values not associated with any printer.
@ -101,12 +102,13 @@ interface nsIPrintSettingsService : nsISupports
* printSilent, shrinkToFit, numCopies
*
*/
void savePrintSettingsToPrefs(in nsIPrintSettings aPrintSettings, in unsigned long aFlags);
void maybeSavePrintSettingsToPrefs(in nsIPrintSettings aPrintSettings, in unsigned long aFlags);
/**
* Saves the given printer name as the last used printer name.
* As long as the pref print.save_print_settings isn't set to false, this
* saves the given printer name as the last used printer name.
*/
void saveLastUsedPrinterNameToPrefs(in AString aPrinterName);
void maybeSaveLastUsedPrinterNameToPrefs(in AString aPrinterName);
/**
* Given some nsIPrintSettings,

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

@ -930,13 +930,17 @@ nsPrintSettingsService::InitPrintSettingsFromPrefs(nsIPrintSettings* aPS,
* Save all of the printer settings; if we can find a printer name, save
* printer-specific preferences. Otherwise, save generic ones.
*/
nsresult nsPrintSettingsService::SavePrintSettingsToPrefs(nsIPrintSettings* aPS,
uint32_t aFlags) {
nsresult nsPrintSettingsService::MaybeSavePrintSettingsToPrefs(
nsIPrintSettings* aPS, uint32_t aFlags) {
NS_ENSURE_ARG_POINTER(aPS);
MOZ_DIAGNOSTIC_ASSERT(XRE_GetProcessType() == GeckoProcessType_Default);
MOZ_ASSERT(!(aFlags & nsIPrintSettings::kInitSavePrinterName),
"Use SaveLastUsedPrintNameToPrefs");
if (!Preferences::GetBool("print.save_print_settings", false)) {
return NS_OK;
}
// Get the printer name from the PrinterSettings for an optional prefix.
nsAutoString prtName;
nsresult rv = GetAdjustedPrinterName(aPS, true, prtName);
@ -957,10 +961,14 @@ nsresult nsPrintSettingsService::SavePrintSettingsToPrefs(nsIPrintSettings* aPS,
return WritePrefs(aPS, prtName, aFlags);
}
nsresult nsPrintSettingsService::SaveLastUsedPrinterNameToPrefs(
nsresult nsPrintSettingsService::MaybeSaveLastUsedPrinterNameToPrefs(
const nsAString& aPrinterName) {
MOZ_DIAGNOSTIC_ASSERT(XRE_GetProcessType() == GeckoProcessType_Default);
if (!Preferences::GetBool("print.save_print_settings", false)) {
return NS_OK;
}
if (!aPrinterName.IsEmpty()) {
Preferences::SetString(kPrinterName, aPrinterName);
}

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

@ -93,9 +93,9 @@ nsPrintDialogServiceWin::ShowPageSetupDialog(mozIDOMWindowProxy* aParent,
return status == 0 ? NS_ERROR_ABORT : NS_OK;
}
// We don't call nsPrintSettingsService::SavePrintSettingsToPrefs here since
// it's called for us in printPageSetup.js. Maybe we should move that call
// here for consistency with the other platforms though?
// We don't call nsPrintSettingsService::MaybeSavePrintSettingsToPrefs here
// since it's called for us in printPageSetup.js. Maybe we should move that
// call here for consistency with the other platforms though?
return rv;
}