Bug 1411589 - Notify flatpak print portal that print to file has finished, r?stransky draft
authorJan Horak <jhorak@redhat.com>
Mon, 16 Apr 2018 12:28:51 +0200
changeset 783055 8ada53df8bfed6b44166c7f1bb11ab7e97c0fe43
parent 783054 ee760f45764d6ce9c683a572f94a23beb1111c8a
child 784914 cc9e96f3c6563fe563782e675d26f82f04ac4da7
child 784915 1e6f3c2474644729b68c95a91aadcf31288c8f64
push id106586
push userbmo:jhorak@redhat.com
push dateMon, 16 Apr 2018 14:07:20 +0000
reviewersstransky
bugs1411589
milestone61.0a1
Bug 1411589 - Notify flatpak print portal that print to file has finished, r?stransky The GTK print portal is notified by the observer service with 'print-to-file-finished' topic. The print filename is used as an identifier of the target in case multiple printing jobs are in progress. MozReview-Commit-ID: 1BZKDcK5De3
widget/gtk/nsDeviceContextSpecG.cpp
--- a/widget/gtk/nsDeviceContextSpecG.cpp
+++ b/widget/gtk/nsDeviceContextSpecG.cpp
@@ -28,16 +28,19 @@
 #include "nsThreadUtils.h"
 
 #include "mozilla/Preferences.h"
 
 #include <unistd.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 
+// To check if we need to use flatpak portal for printing
+#include "nsIGIOService.h"
+
 using namespace mozilla;
 
 using mozilla::gfx::IntSize;
 using mozilla::gfx::PrintTarget;
 using mozilla::gfx::PrintTargetPDF;
 using mozilla::gfx::PrintTargetPS;
 
 static LazyLogModule sDeviceContextSpecGTKLog("DeviceContextSpecGTK");
@@ -350,16 +353,30 @@ NS_IMETHODIMP nsDeviceContextSpecGTK::En
     NS_ENSURE_SUCCESS(rv, rv);
 
     // This is the standard way to get the UNIX umask. Ugh.
     mode_t mask = umask(0);
     umask(mask);
     // If you're not familiar with umasks, they contain the bits of what NOT to set in the permissions
     // (thats because files and directories have different numbers of bits for their permissions)
     destFile->SetPermissions(0666 & ~(mask));
+
+    // Notify flatpak printing portal that file is completely written
+    nsCOMPtr<nsIGIOService> giovfs =
+      do_GetService(NS_GIOSERVICE_CONTRACTID);
+    bool shouldUsePortal;
+    if (giovfs) {
+      giovfs->ShouldUseFlatpakPortal(&shouldUsePortal);
+      if (shouldUsePortal) {
+        // Use the name of the file for printing to match with nsFlatpakPrintPortal
+        nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
+        // Pass filename to be sure that observer process the right data
+        os->NotifyObservers(nullptr, "print-to-file-finished", targetPath.get());
+      }
+    }
   }
   return NS_OK;
 }
 
 //  Printer Enumerator
 nsPrinterEnumeratorGTK::nsPrinterEnumeratorGTK()
 {
 }