Bug 1369386: Fix old invalid millimeter page size prefs using print_paper_size_type as trigger. r=jimm
authorBob Owen <bobowencode@gmail.com>
Fri, 02 Jun 2017 11:58:44 +0100
changeset 362017 a8ed8eb7016547be34fa40bb018a02a95042b177
parent 362016 21f37512b62aa16f04362252c96f804fb9708e2e
child 362018 a37ca72024c661afc148740be2c3a21e0e20f30e
push id31955
push userryanvm@gmail.com
push dateFri, 02 Jun 2017 15:10:12 +0000
treeherdermozilla-central@95d2d23ff510 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjimm
bugs1369386
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1369386: Fix old invalid millimeter page size prefs using print_paper_size_type as trigger. r=jimm These old invalid prefs were caused by us not clearing out old inch page size prefs when the user switched to a standard mm page size (for example A4). This fix uses the fact that an old print_paper_size_type pref was removed at the same time to trigger a one off sanitization.
widget/nsPrintOptionsImpl.cpp
--- a/widget/nsPrintOptionsImpl.cpp
+++ b/widget/nsPrintOptionsImpl.cpp
@@ -492,48 +492,58 @@ nsPrintOptions::ReadPrefs(nsIPrintSettin
     bool success = GETINTPREF(kPrintPaperSizeUnit, &sizeUnit)
                   && GETDBLPREF(kPrintPaperWidth, width)
                   && GETDBLPREF(kPrintPaperHeight, height)
                   && GETSTRPREF(kPrintPaperName, &str);
 
     // Bug 315687: Sanity check paper size to avoid paper size values in
     // mm when the size unit flag is inches. The value 100 is arbitrary
     // and can be changed.
+    bool saveSanitizedSizePrefs = false;
     if (success) {
       success = (sizeUnit != nsIPrintSettings::kPaperSizeInches)
              || (width < 100.0)
              || (height < 100.0);
 #if defined(XP_WIN)
       // Work around legacy invalid prefs where the size unit gets set to
-      // millimeters, but the height and width remains as the default inches
-      // ones for letter. See bug 1276717.
+      // millimeters, but the height and width remains as the previous inches
+      // settings. See bug 1276717 and bug 1369386 for details.
       if (sizeUnit == nsIPrintSettings::kPaperSizeMillimeters &&
-          height == 11L && width == 8.5L) {
+          height >= 0L && height < 25L &&
+          width >= 0L && width < 25L) {
 
-        // As an extra precaution only override, when the resolution is also
-        // set to the legacy invalid, uninitialized value. We'll just broadly
-        // assume that anything outside of a million DPI is invalid.
-        if (GETINTPREF(kPrintResolution, &iVal) &&
-            (iVal <= 0 || iVal > 1000000)) {
+        // As small pages sizes can be valid we only override when the old
+        // (now no longer set) pref print_paper_size_type exists. This will be
+        // removed when we save the prefs below.
+        const char* paperSizeTypePref =
+          GetPrefName("print_paper_size_type", aPrinterName);
+        if (Preferences::HasUserValue(paperSizeTypePref)) {
+          saveSanitizedSizePrefs = true;
           height = -1L;
           width = -1L;
         }
       }
 #endif
     }
 
     if (success) {
       aPS->SetPaperSizeUnit(sizeUnit);
       DUMP_INT(kReadStr, kPrintPaperSizeUnit, sizeUnit);
       aPS->SetPaperWidth(width);
       DUMP_DBL(kReadStr, kPrintPaperWidth, width);
       aPS->SetPaperHeight(height);
       DUMP_DBL(kReadStr, kPrintPaperHeight, height);
       aPS->SetPaperName(str.get());
       DUMP_STR(kReadStr, kPrintPaperName, str.get());
+#if defined(XP_WIN)
+      if (saveSanitizedSizePrefs) {
+        SavePrintSettingsToPrefs(aPS, !aPrinterName.IsEmpty(),
+                                 nsIPrintSettings::kInitSavePaperSize);
+      }
+#endif
     }
   }
 
   if (aFlags & nsIPrintSettings::kInitSaveOddEvenPages) {
   if (GETBOOLPREF(kPrintEvenPages, &b)) {
     aPS->SetPrintOptions(nsIPrintSettings::kPrintEvenPages, b);
     DUMP_BOOL(kReadStr, kPrintEvenPages, b);
   }
@@ -765,16 +775,30 @@ nsPrintOptions::WritePrefs(nsIPrintSetti
       Preferences::SetInt(GetPrefName(kPrintPaperSizeUnit, aPrinterName),
                           int32_t(sizeUnit));
       DUMP_DBL(kWriteStr, kPrintPaperWidth, width);
       WritePrefDouble(GetPrefName(kPrintPaperWidth, aPrinterName), width);
       DUMP_DBL(kWriteStr, kPrintPaperHeight, height);
       WritePrefDouble(GetPrefName(kPrintPaperHeight, aPrinterName), height);
       DUMP_STR(kWriteStr, kPrintPaperName, name);
       Preferences::SetString(GetPrefName(kPrintPaperName, aPrinterName), name);
+#if defined(XP_WIN)
+      // If the height and width are -1 then this might be a save triggered by
+      // print pref sanitizing code. This is done as a one off and is partly
+      // triggered by the existence of an old (now no longer set) pref. We
+      // remove that pref if it exists here, so that we don't try and sanitize
+      // what might be valid prefs. See bug 1276717 and bug 1369386 for details.
+      if (height == -1L && width == -1L) {
+        const char* paperSizeTypePref =
+          GetPrefName("print_paper_size_type", aPrinterName);
+        if (Preferences::HasUserValue(paperSizeTypePref)) {
+          Preferences::ClearUser(paperSizeTypePref);
+        }
+      }
+#endif
     }
   }
 
   bool       b;
   char16_t* uStr;
   int32_t    iVal;
   int16_t    iVal16;
   double     dbl;