Bug 1270447 Part 3: Authorize silent printing via the parent. r=jimm
authorBob Owen <bobowencode@gmail.com>
Sun, 29 May 2016 19:53:32 +0100
changeset 338545 1531cd2fb7e6dbaa18998b8933dfe596750c25d0
parent 338544 fd97954bd82a4272b1863638c2de356b489954a6
child 338546 386458c8b92652082064128b020b612a060236e8
push id6249
push userjlund@mozilla.com
push dateMon, 01 Aug 2016 13:59:36 +0000
treeherdermozilla-beta@bad9d4f5bf7e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjimm
bugs1270447
milestone49.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 1270447 Part 3: Authorize silent printing via the parent. r=jimm MozReview-Commit-ID: IefWVtWwaXc
embedding/components/printingui/ipc/PrintingParent.cpp
layout/printing/nsPrintEngine.cpp
--- a/embedding/components/printingui/ipc/PrintingParent.cpp
+++ b/embedding/components/printingui/ipc/PrintingParent.cpp
@@ -1,16 +1,17 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "mozilla/dom/Element.h"
 #include "mozilla/dom/TabParent.h"
+#include "mozilla/Preferences.h"
 #include "mozilla/unused.h"
 #include "nsIContent.h"
 #include "nsIDocument.h"
 #include "nsIDOMWindow.h"
 #include "nsIPrintingPromptService.h"
 #include "nsIPrintProgressParams.h"
 #include "nsIPrintSettingsService.h"
 #include "nsIServiceManager.h"
@@ -106,22 +107,42 @@ PrintingParent::ShowPrintDialog(PBrowser
   nsresult rv;
   if (remotePrintJob) {
     settings = remotePrintJob->GetPrintSettings();
   } else {
     rv = mPrintSettingsSvc->GetNewPrintSettings(getter_AddRefs(settings));
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
+  // We only want to use the print silently setting from the parent.
+  bool printSilently;
+  rv = settings->GetPrintSilent(&printSilently);
+  NS_ENSURE_SUCCESS(rv, rv);
+
   rv = mPrintSettingsSvc->DeserializeToPrintSettings(aData, settings);
   NS_ENSURE_SUCCESS(rv, rv);
 
-  rv = pps->ShowPrintDialog(parentWin, wbp, settings);
+  rv = settings->SetPrintSilent(printSilently);
   NS_ENSURE_SUCCESS(rv, rv);
 
+  // If we are printing silently then we just need to initialize the print
+  // settings with anything specific from the printer.
+  if (printSilently ||
+      Preferences::GetBool("print.always_print_silent", printSilently)) {
+    nsXPIDLString printerName;
+    rv = settings->GetPrinterName(getter_Copies(printerName));
+    NS_ENSURE_SUCCESS(rv, rv);
+
+    settings->SetIsInitializedFromPrinter(false);
+    mPrintSettingsSvc->InitPrintSettingsFromPrinter(printerName, settings);
+  } else {
+    rv = pps->ShowPrintDialog(parentWin, wbp, settings);
+    NS_ENSURE_SUCCESS(rv, rv);
+  }
+
   rv = SerializeAndEnsureRemotePrintJob(settings, nullptr, remotePrintJob,
                                         aResult);
 
   return rv;
 }
 
 bool
 PrintingParent::RecvShowPrintDialog(PPrintSettingsDialogParent* aDialog,
--- a/layout/printing/nsPrintEngine.cpp
+++ b/layout/printing/nsPrintEngine.cpp
@@ -566,18 +566,20 @@ nsPrintEngine::DoCommonPrint(bool       
     }
   } else {
     mPrt->mPrintSettings->SetHowToEnableFrameUI(nsIPrintSettings::kFrameEnableNone);
   }
   // Now determine how to set up the Frame print UI
   mPrt->mPrintSettings->SetPrintOptions(nsIPrintSettings::kEnableSelectionRB,
                                         isSelection || mPrt->mIsIFrameSelected);
 
+  bool printingViaParent = XRE_IsContentProcess() &&
+                           Preferences::GetBool("print.print_via_parent");
   nsCOMPtr<nsIDeviceContextSpec> devspec;
-  if (XRE_IsContentProcess() && Preferences::GetBool("print.print_via_parent")) {
+  if (printingViaParent) {
     devspec = new nsDeviceContextSpecProxy();
   } else {
     devspec = do_CreateInstance("@mozilla.org/gfx/devicecontextspec;1", &rv);
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
   nsScriptSuppressor scriptSuppressor(this);
   if (!aIsPrintPreview) {
@@ -591,17 +593,19 @@ nsPrintEngine::DoCommonPrint(bool       
 
     // Check prefs for a default setting as to whether we should print silently
     printSilently =
       Preferences::GetBool("print.always_print_silent", printSilently);
 
     // Ask dialog to be Print Shown via the Plugable Printing Dialog Service
     // This service is for the Print Dialog and the Print Progress Dialog
     // If printing silently or you can't get the service continue on
-    if (!printSilently) {
+    // If printing via the parent then we need to confirm that the pref is set
+    // and get a remote print job, but the parent won't display a prompt.
+    if (!printSilently || printingViaParent) {
       nsCOMPtr<nsIPrintingPromptService> printPromptService(do_GetService(kPrintingPromptService));
       if (printPromptService) {
         nsPIDOMWindowOuter* domWin = mDocument->GetWindow(); 
         NS_ENSURE_TRUE(domWin, NS_ERROR_FAILURE);
 
         // Platforms not implementing a given dialog for the service may
         // return NS_ERROR_NOT_IMPLEMENTED or an error code.
         //