Bug 1754308 p2 - Stop sending nsIPrintSettings.printerName to content processes. r=bobowen

This avoids exposing printer names to potentially compromised content processes.

The changes in bug 1770211 mean that we no longer create platform specific
nsIDeviceContextSpec instances in the content process, so we no longer need
the printer name to instantiate an nsDeviceContextSpecWin there.

Differential Revision: https://phabricator.services.mozilla.com/D146868
This commit is contained in:
Jonathan Watt 2022-05-20 22:51:00 +00:00
Родитель 43e1613319
Коммит ca15f68e8a
4 изменённых файлов: 8 добавлений и 44 удалений

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

@ -212,43 +212,6 @@ static void BuildNestedPrintObjects(const UniquePtr<nsPrintObject>& aParentPO,
}
}
/**
* On platforms that support it, sets the printer name stored in the
* nsIPrintSettings to the last-used printer if a printer name is not already
* set.
* XXXjwatt: Why is this necessary? Can't the code that reads the printer
* name later "just" use the last-used printer if a name isn't specified? Then
* we wouldn't have this inconsistency between platforms and processes.
*/
static nsresult EnsureSettingsHasPrinterNameSet(
nsIPrintSettings* aPrintSettings) {
#if defined(XP_MACOSX) || defined(ANDROID)
// Mac doesn't support retrieving a printer list.
return NS_OK;
#else
NS_ENSURE_ARG_POINTER(aPrintSettings);
// See if aPrintSettings already has a printer
nsString printerName;
nsresult rv = aPrintSettings->GetPrinterName(printerName);
if (NS_SUCCEEDED(rv) && !printerName.IsEmpty()) {
return NS_OK;
}
// aPrintSettings doesn't have a printer set.
// Try to fetch the name of the last-used printer.
nsCOMPtr<nsIPrintSettingsService> printSettingsService =
do_GetService(sPrintSettingsServiceContractID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
rv = printSettingsService->GetLastUsedPrinterName(printerName);
if (NS_SUCCEEDED(rv) && !printerName.IsEmpty()) {
rv = aPrintSettings->SetPrinterName(printerName);
}
return rv;
#endif
}
static nsresult GetDefaultPrintSettings(nsIPrintSettings** aSettings) {
*aSettings = nullptr;
@ -476,8 +439,6 @@ nsresult nsPrintJob::DoCommonPrint(bool aIsPrintPreview,
!printData->mPrintObject->mDocument->GetRootElement())
return NS_ERROR_GFX_PRINTER_STARTDOC;
MOZ_TRY(EnsureSettingsHasPrinterNameSet(printData->mPrintSettings));
printData->mPrintSettings->GetShrinkToFit(&printData->mShrinkToFit);
bool printingViaParent =

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

@ -59,12 +59,12 @@ struct PrintData {
// We do not transfer the following to the child process, since the child
// process should not need this information, and we don't want to leak it if
// the child process is compromised.
//nsString printerName;
//nsString toFileName;
// TODO: Do we really need to deal with these in child processes?
short outputDestination;
short outputFormat;
nsString printerName;
int32_t printPageDelay;
int32_t resolution;

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

@ -291,7 +291,13 @@ interface nsIPrintSettings : nsISupports
[infallible] attribute nsIPrintSettings_OutputDestinationType outputDestination;
[infallible] attribute short outputFormat;
attribute AString printerName; /* for kOutputDestinationPrinter */
/**
* If outputDestination==kOutputDestinationPrinter, this is set to the name
* of the printer that the print output should be saved to, but only in the
* parent process (we don't want to leak printer names to potentially
* compromised content processes).
*/
attribute AString printerName;
/**
* If outputDestination==kOutputDestinationFile, this is set to the path

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

@ -147,8 +147,6 @@ nsPrintSettingsService::SerializeToPrintData(nsIPrintSettings* aSettings,
aSettings->GetNumCopies(&data->numCopies());
aSettings->GetNumPagesPerSheet(&data->numPagesPerSheet());
aSettings->GetPrinterName(data->printerName());
data->outputDestination() = aSettings->GetOutputDestination();
data->outputFormat() = aSettings->GetOutputFormat();
@ -228,7 +226,6 @@ nsPrintSettingsService::DeserializeToPrintSettings(const PrintData& data,
settings->SetOutputDestination(
nsIPrintSettings::OutputDestinationType(data.outputDestination()));
settings->SetPrinterName(data.printerName());
// Output stream intentionally unset, child processes shouldn't care about it.
settings->SetOutputFormat(data.outputFormat());