mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-02 01:48:05 +00:00
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:
parent
76563e652c
commit
22c7b2a254
@ -12,6 +12,7 @@
|
||||
#include "mozilla/Preferences.h"
|
||||
#include "mozilla/RefPtr.h"
|
||||
#include "mozilla/Telemetry.h"
|
||||
#include "nsAnonymousTemporaryFile.h"
|
||||
|
||||
#include <wchar.h>
|
||||
#include <windef.h>
|
||||
@ -74,6 +75,10 @@ NS_IMPL_ISUPPORTS(nsDeviceContextSpecWin, nsIDeviceContextSpec)
|
||||
nsDeviceContextSpecWin::~nsDeviceContextSpecWin() {
|
||||
SetDevMode(nullptr);
|
||||
|
||||
if (mTempFile) {
|
||||
mTempFile->Remove(/* recursive = */ false);
|
||||
}
|
||||
|
||||
if (nsCOMPtr<nsIPrintSettingsWin> ps = do_QueryInterface(mPrintSettings)) {
|
||||
ps->SetDeviceName(EmptyString());
|
||||
ps->SetDriverName(EmptyString());
|
||||
@ -287,9 +292,17 @@ already_AddRefed<PrintTarget> nsDeviceContextSpecWin::MakePrintTarget() {
|
||||
width /= TWIPS_PER_POINT_FLOAT;
|
||||
height /= TWIPS_PER_POINT_FLOAT;
|
||||
|
||||
nsCOMPtr<nsIFile> file = do_CreateInstance("@mozilla.org/file/local;1");
|
||||
nsresult rv = file->InitWithPath(filename);
|
||||
if (NS_FAILED(rv)) {
|
||||
nsCOMPtr<nsIFile> file;
|
||||
nsresult 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;
|
||||
}
|
||||
|
||||
|
@ -14,6 +14,7 @@
|
||||
#include "mozilla/Attributes.h"
|
||||
#include "mozilla/RefPtr.h"
|
||||
|
||||
class nsIFile;
|
||||
class nsIWidget;
|
||||
|
||||
class nsDeviceContextSpecWin : public nsIDeviceContextSpec {
|
||||
@ -71,6 +72,10 @@ class nsDeviceContextSpecWin : public nsIDeviceContextSpec {
|
||||
nsCOMPtr<nsIPrintSettings> mPrintSettings;
|
||||
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
|
||||
|
||||
// This variable is independant of nsIPrintSettings::kOutputFormatPDF.
|
||||
|
Loading…
Reference in New Issue
Block a user