Bug 1411589 - Notify flatpak print portal that print to file has finished, r?bz draft
authorJan Horak <jhorak@redhat.com>
Thu, 05 Apr 2018 16:25:42 +0200
changeset 779591 bed5b3b681e7474c15736905a9764cb8600cdcef
parent 779590 b2845716d5b9d732310b3306dd461f017e1e2c6f
child 779592 3122b482eae4159fb91173088265d5dc3186a726
child 780279 fe9f820d82d0818cbd19eff0e54f8425b8bf0782
child 780444 ce931b6a81b48e706e6aa6fe589f69fc0f9ffd98
push id105818
push userbmo:jhorak@redhat.com
push dateTue, 10 Apr 2018 09:08:46 +0000
reviewersbz
bugs1411589
milestone61.0a1
Bug 1411589 - Notify flatpak print portal that print to file has finished, r?bz 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: 9BEjgSzycPh
layout/base/nsDocumentViewer.cpp
--- a/layout/base/nsDocumentViewer.cpp
+++ b/layout/base/nsDocumentViewer.cpp
@@ -88,23 +88,27 @@
 //--------------------------
 // Printing Include
 //---------------------------
 #ifdef NS_PRINTING
 
 #include "nsIWebBrowserPrint.h"
 
 #include "nsPrintJob.h"
+// To check if we need to use flatpak portal for printing
+#include "nsIGIOService.h"
 
 // Print Options
 #include "nsIPrintSettings.h"
 #include "nsIPrintSettingsService.h"
 #include "nsISimpleEnumerator.h"
 
 #include "nsIPluginDocument.h"
+// To notify the parent that print to file has been finished
+#include "mozilla/dom/ContentChild.h"
 
 #endif // NS_PRINTING
 
 //focus
 #include "nsIDOMEventTarget.h"
 #include "nsIDOMEventListener.h"
 #include "nsISelectionController.h"
 
@@ -4483,21 +4487,56 @@ nsDocumentViewer::OnDonePrinting()
 {
 #if defined(NS_PRINTING) && defined(NS_PRINT_PREVIEW)
   // If Destroy() has been called during calling nsPrintJob::Print() or
   // nsPrintJob::PrintPreview(), mPrintJob is already nullptr here.
   // So, the following clean up does nothing in such case.
   // (Do we need some of this for that case?)
   if (mPrintJob) {
     RefPtr<nsPrintJob> printJob = mPrintJob;
+
+#ifdef MOZ_WIDGET_GTK
+    // Reference settings in case we need it for getting filename
+    // for flatpak portal.
+    nsCOMPtr<nsIPrintSettings> printSettings;
+    printJob->GetCurrentPrintSettings(getter_AddRefs(printSettings));
+#endif
+
     if (GetIsPrintPreview()) {
       printJob->DestroyPrintingData();
     } else {
       mPrintJob = nullptr;
       printJob->Destroy();
+
+#ifdef MOZ_WIDGET_GTK
+      // 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 && printSettings) {
+          // Get the name of the file used for printing to match with
+          // nsFlatpakPrintPortal.
+          nsAutoString filenameStr;
+          printSettings->GetToFileName(filenameStr);
+          // When in content process we need to notify the parent
+          if (XRE_IsContentProcess()) {
+            ContentChild* contentChild = ContentChild::GetSingleton();
+            if (contentChild) {
+              contentChild->SendNotifyPrintToFileFinished(filenameStr);
+            }
+          } else {
+            nsCOMPtr<nsIObserverService> os = mozilla::services::GetObserverService();
+            // Pass filename to be sure that observer process the right data
+            os->NotifyObservers(nullptr, "print-to-file-finished", filenameStr.get());
+          }
+        }
+      }
+#endif
     }
 
     // We are done printing, now cleanup
     if (mDeferredWindowClose) {
       mDeferredWindowClose = false;
       if (mContainer) {
         if (nsCOMPtr<nsPIDOMWindowOuter> win = do_QueryInterface(mContainer->GetWindow())) {
           win->Close();