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 332823 6485fbf9000cadac47e1c50eabf51f7fa6b37dfc
parent 332822 6772bf149f18dad8c43237a682967a341096660d
child 332824 521f93a84891d00a4e860d7281cf8925d23440f2
push id6048
push userkmoir@mozilla.com
push dateMon, 06 Jun 2016 19:02:08 +0000
treeherdermozilla-beta@46d72a56c57d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjimm, ritu
bugs1255336
milestone48.0a2
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;