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
--- 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();