From 546d657b09a1b56e1cd3d2a1729cc0a2b136b45f Mon Sep 17 00:00:00 2001 From: Bob Owen Date: Tue, 28 Nov 2017 08:58:43 +0000 Subject: [PATCH] Bug 1420171 Part 1: Only default the print-to file name on Linux if not already set. r=karlt This allows the web extension saveAsPDF function to work properly. --- widget/gtk/nsDeviceContextSpecG.cpp | 32 +++++++++++++++++------------ 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/widget/gtk/nsDeviceContextSpecG.cpp b/widget/gtk/nsDeviceContextSpecG.cpp index eac145e2b244..1876e90dca49 100644 --- a/widget/gtk/nsDeviceContextSpecG.cpp +++ b/widget/gtk/nsDeviceContextSpecG.cpp @@ -411,20 +411,26 @@ nsPrinterEnumeratorGTK::InitPrintSettingsFromPrinter(const nsAString& aPrinterNa NS_ENSURE_ARG_POINTER(aPrintSettings); - /* Set filename */ - nsAutoCString filename; - const char *path; - - if (!(path = PR_GetEnv("PWD"))) - path = PR_GetEnv("HOME"); - - if (path) - filename = nsPrintfCString("%s/mozilla.pdf", path); - else - filename.AssignLiteral("mozilla.pdf"); + // Set a default file name. + nsAutoString filename; + nsresult rv = aPrintSettings->GetToFileName(filename); + if (NS_FAILED(rv) || filename.IsEmpty()) { + const char* path = PR_GetEnv("PWD"); + if (!path) { + path = PR_GetEnv("HOME"); + } - DO_PR_DEBUG_LOG(("Setting default filename to '%s'\n", filename.get())); - aPrintSettings->SetToFileName(NS_ConvertUTF8toUTF16(filename)); + if (path) { + CopyUTF8toUTF16(path, filename); + filename.AppendLiteral("/mozilla.pdf"); + } else { + filename.AssignLiteral("mozilla.pdf"); + } + + DO_PR_DEBUG_LOG(("Setting default filename to '%s'\n", + NS_ConvertUTF16toUTF8(filename).get())); + aPrintSettings->SetToFileName(filename); + } aPrintSettings->SetIsInitializedFromPrinter(true);