Frank-Rainer Grahl 9 months ago
parent
commit
9fee8f3498
2 changed files with 108 additions and 0 deletions
  1. 107 0
      mozilla-release/patches/1660223-11507.patch
  2. 1 0
      mozilla-release/patches/series

+ 107 - 0
mozilla-release/patches/1660223-11507.patch

@@ -0,0 +1,107 @@
+# HG changeset patch
+# User Daniel Holbert <dholbert@cs.stanford.edu>
+# Date 1703683199 0
+# Node ID 0168b085c45b39f0f2ddb3d671e2e3a6f6631ff6
+# Parent  721fd6cadf7060a361887235aa54b5a0a85fb5d1
+Bug 1660223: Let printer enumeration run to completion, to avoid a GTK bug.  a=dmeehan
+
+Original Revision: https://phabricator.services.mozilla.com/D195949
+
+Differential Revision: https://phabricator.services.mozilla.com/D196685
+
+diff --git a/widget/gtk/nsDeviceContextSpecG.cpp b/widget/gtk/nsDeviceContextSpecG.cpp
+--- a/widget/gtk/nsDeviceContextSpecG.cpp
++++ b/widget/gtk/nsDeviceContextSpecG.cpp
+@@ -240,16 +240,22 @@ ns_release_macro(gpointer aData) {
+   NS_RELEASE(spoolFile);
+ }
+ 
+ /* static */
+ gboolean nsDeviceContextSpecGTK::PrinterEnumerator(GtkPrinter *aPrinter,
+                                                    gpointer aData) {
+   nsDeviceContextSpecGTK *spec = (nsDeviceContextSpecGTK*)aData;
+ 
++  if (spec->mHasEnumerationFoundAMatch) {
++    // We're already done, but we're letting the enumeration run its course,
++    // to avoid a GTK bug.
++    return FALSE;
++  }
++
+   // Find the printer whose name matches the one inside the settings.
+   nsString printerName;
+   nsresult rv =
+     spec->mPrintSettings->GetPrinterName(printerName);
+   if (NS_SUCCEEDED(rv) && !printerName.IsVoid()) {
+     NS_ConvertUTF16toUTF8 requestedName(printerName);
+     const char* currentName = gtk_printer_get_name(aPrinter);
+     if (requestedName.Equals(currentName)) {
+@@ -259,17 +265,24 @@ gboolean nsDeviceContextSpecGTK::Printer
+       // during this tick of the event loop will result in the printer backend
+       // misunderstanding what the capabilities of the printer are due to a
+       // GTK bug (https://bugzilla.gnome.org/show_bug.cgi?id=753041). We
+       // sidestep this by deferring the print to the next tick.
+       NS_DispatchToCurrentThread(
+         NewRunnableMethod("nsDeviceContextSpecGTK::StartPrintJob",
+                           spec,
+                           &nsDeviceContextSpecGTK::StartPrintJob));
+-      return TRUE;
++
++      // We're already done, but we need to let the enumeration run its course,
++      // to avoid a GTK bug. So we record that we've found a match and
++      // then return FALSE.
++      // TODO: If/when we can be sure that GTK handles this OK, we could
++      // return TRUE to avoid some needless enumeration.
++      spec->mHasEnumerationFoundAMatch = true;
++      return FALSE;
+     }
+   }
+ 
+   // We haven't found it yet - keep searching...
+   return FALSE;
+ }
+ 
+ void nsDeviceContextSpecGTK::StartPrintJob() {
+@@ -280,19 +293,18 @@ void nsDeviceContextSpecGTK::StartPrintJ
+ 
+   if (!gtk_print_job_set_source_file(job, mSpoolName.get(), nullptr))
+     return;
+ 
+   NS_ADDREF(mSpoolFile.get());
+   gtk_print_job_send(job, print_callback, mSpoolFile, ns_release_macro);
+ }
+ 
+-void
+-nsDeviceContextSpecGTK::EnumeratePrinters()
+-{
++void nsDeviceContextSpecGTK::EnumeratePrinters() {
++  mHasEnumerationFoundAMatch = false;
+   gtk_enumerate_printers(&nsDeviceContextSpecGTK::PrinterEnumerator, this,
+                          nullptr, TRUE);
+ }
+ 
+ NS_IMETHODIMP
+ nsDeviceContextSpecGTK::BeginDocument(const nsAString& aTitle,
+                                       const nsAString& aPrintToFileName,
+                                       int32_t aStartPage, int32_t aEndPage)
+diff --git a/widget/gtk/nsDeviceContextSpecG.h b/widget/gtk/nsDeviceContextSpecG.h
+--- a/widget/gtk/nsDeviceContextSpecG.h
++++ b/widget/gtk/nsDeviceContextSpecG.h
+@@ -47,16 +47,18 @@ protected:
+   bool mToPrinter : 1;      /* If true, print to printer */
+   bool mIsPPreview : 1;     /* If true, is print preview */
+   GtkPrintSettings* mGtkPrintSettings;
+   GtkPageSetup*     mGtkPageSetup;
+ 
+   nsCString         mSpoolName;
+   nsCOMPtr<nsIFile> mSpoolFile;
+   nsCString         mTitle;
++  // Helper for EnumeratePrinters / PrinterEnumerator:
++  bool mHasEnumerationFoundAMatch = false;
+ 
+ private:
+   void EnumeratePrinters();
+   void StartPrintJob();
+   static gboolean PrinterEnumerator(GtkPrinter *aPrinter, gpointer aData);
+ };
+ 
+ //-------------------------------------------------------------------------

+ 1 - 0
mozilla-release/patches/series

@@ -6235,3 +6235,4 @@ TOP-NOBUG-killtelemetry-debugger-25319.patch
 1854076-11505.patch
 1826791-121a1.patch
 WIP-1729459-comment25.patch
+1660223-11507.patch