Bug 1255336: Copy DEVMODE details back to print settings in GetDataFromPrinter. r=jimm, a=ritu
authorBob Owen <bobowencode@gmail.com>
Thu, 05 May 2016 13:06:53 +0100
changeset 378799 67b57ffeed5352ce93c403094185d9ccd4348cc4
parent 365921 a4a650440913082f894933d142b68d3d16ec1abb
child 378800 cf7b0c21b647d14112338b0be1f6b1cfacbd8cba
push id21011
push usermak77@bonardo.net
push dateThu, 16 Jun 2016 13:40:45 +0000
reviewersjimm, ritu
bugs1255336
milestone47.0
Bug 1255336: Copy DEVMODE details back to print settings in GetDataFromPrinter. r=jimm, a=ritu nsDeviceContextSpecWin::GetDataFromPrinter is only called with print settings, when the settings aren't properly populated in nsDeviceContextSpecWin::Init. This only happens when printing silently and the print settings have last been populated with prefs. We need to copy the final DEVMODE details back in case any were invalid from the prefs and have been overridden by the printer. MozReview-Commit-ID: EuRTDZTSSJn
widget/windows/nsDeviceContextSpecWin.cpp
--- a/widget/windows/nsDeviceContextSpecWin.cpp
+++ b/widget/windows/nsDeviceContextSpecWin.cpp
@@ -26,16 +26,17 @@
 
 #include "gfxPDFSurface.h"
 #include "gfxWindowsSurface.h"
 
 #include "nsIFileStreams.h"
 #include "nsIWindowWatcher.h"
 #include "nsIDOMWindow.h"
 #include "mozilla/Services.h"
+#include "nsWindowsHelpers.h"
 
 // For NS_CopyNativeToUnicode
 #include "nsNativeCharsetUtils.h"
 
 // File Picker
 #include "nsIFile.h"
 #include "nsIFilePicker.h"
 #include "nsIStringBundle.h"
@@ -366,16 +367,30 @@ nsDeviceContextSpecWin::GetDataFromPrint
     if (dwRet == IDOK && aPS) {
       nsCOMPtr<nsIPrintSettingsWin> psWin = do_QueryInterface(aPS);
       MOZ_ASSERT(psWin);
       psWin->CopyToNative(pDevMode);
       // Sets back the changes we made to the DevMode into the Printer Driver
       dwRet = ::DocumentPropertiesW(nullptr, hPrinter, name,
                                    pDevMode, pDevMode,
                                    DM_IN_BUFFER | DM_OUT_BUFFER);
+
+      // We need to copy the final DEVMODE settings back to our print settings,
+      // because they may have been set from invalid prefs.
+      if (dwRet == IDOK) {
+        // We need to get information from the device as well.
+        nsAutoHDC printerDC(::CreateICW(kDriverName, aName, nullptr, pDevMode));
+        if (NS_WARN_IF(!printerDC)) {
+          ::HeapFree(::GetProcessHeap(), 0, pDevMode);
+          ::ClosePrinter(hPrinter);
+          return NS_ERROR_FAILURE;
+        }
+
+        psWin->CopyFromNative(printerDC, pDevMode);
+      }
     }
 
     if (dwRet != IDOK) {
       ::HeapFree(::GetProcessHeap(), 0, pDevMode);
       ::ClosePrinter(hPrinter);
       PR_PL(("***** nsDeviceContextSpecWin::GetDataFromPrinter - DocumentProperties call failed code: %d/0x%x\n", dwRet, dwRet));
       DISPLAY_LAST_ERROR
       return NS_ERROR_FAILURE;