Bug 1270447 Part 3: Authorize silent printing via the parent. r=jimm

MozReview-Commit-ID: IefWVtWwaXc

--HG--
extra : rebase_source : eb62e33244fbe98a07344f7c5e370edb48ce15b5
This commit is contained in:
Bob Owen 2016-05-29 19:53:32 +01:00
parent e69f5d650c
commit a66b7bea7f
2 changed files with 28 additions and 3 deletions

View File

@ -6,6 +6,7 @@
#include "mozilla/dom/Element.h"
#include "mozilla/dom/TabParent.h"
#include "mozilla/Preferences.h"
#include "mozilla/unused.h"
#include "nsIContent.h"
#include "nsIDocument.h"
@ -111,12 +112,32 @@ PrintingParent::ShowPrintDialog(PBrowserParent* aParent,
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);

View File

@ -571,8 +571,10 @@ nsPrintEngine::DoCommonPrint(bool aIsPrintPreview,
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);
@ -596,7 +598,9 @@ nsPrintEngine::DoCommonPrint(bool aIsPrintPreview,
// 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();