Bug 1659470 - Handle printing with an empty file name in nsDeviceContextSpecWin. r=jwatt
Ideally print preview and co. shouldn't need a PrintTarget at all, I'd think... Though that's a bigger refactoring. Differential Revision: https://phabricator.services.mozilla.com/D89452
This commit is contained in:
@@ -12,6 +12,7 @@
|
|||||||
#include "mozilla/Preferences.h"
|
#include "mozilla/Preferences.h"
|
||||||
#include "mozilla/RefPtr.h"
|
#include "mozilla/RefPtr.h"
|
||||||
#include "mozilla/Telemetry.h"
|
#include "mozilla/Telemetry.h"
|
||||||
|
#include "nsAnonymousTemporaryFile.h"
|
||||||
|
|
||||||
#include <wchar.h>
|
#include <wchar.h>
|
||||||
#include <windef.h>
|
#include <windef.h>
|
||||||
@@ -74,6 +75,10 @@ NS_IMPL_ISUPPORTS(nsDeviceContextSpecWin, nsIDeviceContextSpec)
|
|||||||
nsDeviceContextSpecWin::~nsDeviceContextSpecWin() {
|
nsDeviceContextSpecWin::~nsDeviceContextSpecWin() {
|
||||||
SetDevMode(nullptr);
|
SetDevMode(nullptr);
|
||||||
|
|
||||||
|
if (mTempFile) {
|
||||||
|
mTempFile->Remove(/* recursive = */ false);
|
||||||
|
}
|
||||||
|
|
||||||
if (nsCOMPtr<nsIPrintSettingsWin> ps = do_QueryInterface(mPrintSettings)) {
|
if (nsCOMPtr<nsIPrintSettingsWin> ps = do_QueryInterface(mPrintSettings)) {
|
||||||
ps->SetDeviceName(EmptyString());
|
ps->SetDeviceName(EmptyString());
|
||||||
ps->SetDriverName(EmptyString());
|
ps->SetDriverName(EmptyString());
|
||||||
@@ -287,9 +292,17 @@ already_AddRefed<PrintTarget> nsDeviceContextSpecWin::MakePrintTarget() {
|
|||||||
width /= TWIPS_PER_POINT_FLOAT;
|
width /= TWIPS_PER_POINT_FLOAT;
|
||||||
height /= TWIPS_PER_POINT_FLOAT;
|
height /= TWIPS_PER_POINT_FLOAT;
|
||||||
|
|
||||||
nsCOMPtr<nsIFile> file = do_CreateInstance("@mozilla.org/file/local;1");
|
nsCOMPtr<nsIFile> file;
|
||||||
nsresult rv = file->InitWithPath(filename);
|
nsresult rv;
|
||||||
if (NS_FAILED(rv)) {
|
if (!filename.IsEmpty()) {
|
||||||
|
file = do_CreateInstance("@mozilla.org/file/local;1");
|
||||||
|
rv = file->InitWithPath(filename);
|
||||||
|
} else {
|
||||||
|
rv = NS_OpenAnonymousTemporaryNsIFile(getter_AddRefs(mTempFile));
|
||||||
|
file = mTempFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,7 @@
|
|||||||
#include "mozilla/Attributes.h"
|
#include "mozilla/Attributes.h"
|
||||||
#include "mozilla/RefPtr.h"
|
#include "mozilla/RefPtr.h"
|
||||||
|
|
||||||
|
class nsIFile;
|
||||||
class nsIWidget;
|
class nsIWidget;
|
||||||
|
|
||||||
class nsDeviceContextSpecWin : public nsIDeviceContextSpec {
|
class nsDeviceContextSpecWin : public nsIDeviceContextSpec {
|
||||||
@@ -71,6 +72,10 @@ class nsDeviceContextSpecWin : public nsIDeviceContextSpec {
|
|||||||
nsCOMPtr<nsIPrintSettings> mPrintSettings;
|
nsCOMPtr<nsIPrintSettings> mPrintSettings;
|
||||||
int16_t mOutputFormat = nsIPrintSettings::kOutputFormatNative;
|
int16_t mOutputFormat = nsIPrintSettings::kOutputFormatNative;
|
||||||
|
|
||||||
|
// A temporary file to create an "anonymous" print target. See bug 1664253,
|
||||||
|
// this should ideally not be needed.
|
||||||
|
nsCOMPtr<nsIFile> mTempFile;
|
||||||
|
|
||||||
#ifdef MOZ_ENABLE_SKIA_PDF
|
#ifdef MOZ_ENABLE_SKIA_PDF
|
||||||
|
|
||||||
// This variable is independant of nsIPrintSettings::kOutputFormatPDF.
|
// This variable is independant of nsIPrintSettings::kOutputFormatPDF.
|
||||||
|
|||||||
Reference in New Issue
Block a user