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/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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user