Bug 1088070 - If saving print settings in the content process, proxy to the parent. r=smaug.

This commit is contained in:
Mike Conley 2015-03-05 13:12:41 -05:00
parent 96d242fdfa
commit b39f3cc38e
8 changed files with 101 additions and 1 deletions

View File

@ -40,7 +40,8 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsDialogParamBlock)
#ifdef NS_PRINTING
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsPrintingPromptService, Init)
#ifdef PROXY_PRINTING
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsPrintingProxy, Init)
NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsPrintingProxy,
nsPrintingProxy::GetInstance)
#endif
#endif
#endif

View File

@ -102,6 +102,10 @@ parent:
PPrintProgressDialog();
sync SavePrintSettings(PrintData settings, bool usePrinterNamePrefix,
uint32_t flags)
returns(nsresult rv);
child:
__delete__();
};

View File

@ -12,6 +12,7 @@
#include "nsIPrintingPromptService.h"
#include "nsIPrintOptions.h"
#include "nsIPrintProgressParams.h"
#include "nsIPrintSettingsService.h"
#include "nsIServiceManager.h"
#include "nsIWebProgressListener.h"
#include "PrintingParent.h"
@ -111,6 +112,31 @@ PrintingParent::RecvShowPrintDialog(PBrowserParent* parent,
return true;
}
bool
PrintingParent::RecvSavePrintSettings(const PrintData& aData,
const bool& aUsePrinterNamePrefix,
const uint32_t& aFlags,
nsresult* aResult)
{
nsCOMPtr<nsIPrintSettingsService> pss =
do_GetService("@mozilla.org/gfx/printsettings-service;1", aResult);
NS_ENSURE_SUCCESS(*aResult, true);
nsCOMPtr<nsIPrintOptions> po = do_QueryInterface(pss, aResult);
NS_ENSURE_SUCCESS(*aResult, true);
nsCOMPtr<nsIPrintSettings> settings;
*aResult = po->CreatePrintSettings(getter_AddRefs(settings));
NS_ENSURE_SUCCESS(*aResult, true);
*aResult = po->DeserializeToPrintSettings(aData, settings);
NS_ENSURE_SUCCESS(*aResult, true);
*aResult = pss->SavePrintSettingsToPrefs(settings, aUsePrinterNamePrefix, aFlags);
return true;
}
PPrintProgressDialogParent*
PrintingParent::AllocPPrintProgressDialogParent()
{

View File

@ -31,6 +31,12 @@ public:
PrintData* retVal,
bool* success);
virtual bool
RecvSavePrintSettings(const PrintData& aData,
const bool& aUsePrinterNamePrefix,
const uint32_t& aFlags,
nsresult* aResult);
virtual PPrintProgressDialogParent*
AllocPPrintProgressDialogParent();

View File

@ -4,6 +4,10 @@
# 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/.
EXPORTS += [
'nsPrintingProxy.h',
]
EXPORTS.mozilla.embedding.printingui += [
'PrintingParent.h',
]

View File

@ -4,6 +4,7 @@
* 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/ClearOnShutdown.h"
#include "mozilla/dom/ContentChild.h"
#include "mozilla/dom/TabChild.h"
#include "mozilla/unused.h"
@ -20,6 +21,8 @@ using namespace mozilla;
using namespace mozilla::dom;
using namespace mozilla::embedding;
static StaticRefPtr<nsPrintingProxy> sPrintingProxyInstance;
NS_IMPL_ISUPPORTS(nsPrintingProxy, nsIPrintingPromptService)
nsPrintingProxy::nsPrintingProxy()
@ -30,6 +33,27 @@ nsPrintingProxy::~nsPrintingProxy()
{
}
/* static */
already_AddRefed<nsPrintingProxy>
nsPrintingProxy::GetInstance()
{
if (!sPrintingProxyInstance) {
sPrintingProxyInstance = new nsPrintingProxy();
if (!sPrintingProxyInstance) {
return nullptr;
}
nsresult rv = sPrintingProxyInstance->Init();
if (NS_FAILED(rv)) {
sPrintingProxyInstance = nullptr;
return nullptr;
}
ClearOnShutdown(&sPrintingProxyInstance);
}
nsRefPtr<nsPrintingProxy> inst = sPrintingProxyInstance.get();
return inst.forget();
}
nsresult
nsPrintingProxy::Init()
{
@ -144,6 +168,25 @@ nsPrintingProxy::ShowPrinterProperties(nsIDOMWindow *parent,
return NS_ERROR_NOT_IMPLEMENTED;
}
nsresult
nsPrintingProxy::SavePrintSettings(nsIPrintSettings* aPS,
bool aUsePrinterNamePrefix,
uint32_t aFlags)
{
nsresult rv;
nsCOMPtr<nsIPrintOptions> po =
do_GetService("@mozilla.org/gfx/printsettings-service;1", &rv);
NS_ENSURE_SUCCESS(rv, rv);
PrintData settings;
rv = po->SerializeToPrintData(aPS, nullptr, &settings);
NS_ENSURE_SUCCESS(rv, rv);
unused << SendSavePrintSettings(settings, aUsePrinterNamePrefix, aFlags,
&rv);
return rv;
}
PPrintProgressDialogChild*
nsPrintingProxy::AllocPPrintProgressDialogChild()
{

View File

@ -17,11 +17,17 @@ class nsPrintingProxy: public nsIPrintingPromptService,
public:
nsPrintingProxy();
static already_AddRefed<nsPrintingProxy> GetInstance();
nsresult Init();
NS_DECL_ISUPPORTS
NS_DECL_NSIPRINTINGPROMPTSERVICE
nsresult SavePrintSettings(nsIPrintSettings* aPS,
bool aUsePrinterNamePrefix,
uint32_t aFlags);
virtual PPrintProgressDialogChild*
AllocPPrintProgressDialogChild() MOZ_OVERRIDE;

View File

@ -4,6 +4,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "mozilla/embedding/PPrinting.h"
#include "nsPrintingProxy.h"
#include "nsPrintOptionsImpl.h"
#include "nsReadableUtils.h"
#include "nsPrintSettingsImpl.h"
@ -1297,6 +1298,15 @@ nsPrintOptions::SavePrintSettingsToPrefs(nsIPrintSettings *aPS,
uint32_t aFlags)
{
NS_ENSURE_ARG_POINTER(aPS);
if (GeckoProcessType_Content == XRE_GetProcessType()) {
// If we're in the content process, we can't directly write to the
// Preferences service - we have to proxy the save up to the
// parent process.
nsRefPtr<nsPrintingProxy> proxy = nsPrintingProxy::GetInstance();
return proxy->SavePrintSettings(aPS, aUsePrinterNamePrefix, aFlags);
}
nsAutoString prtName;
// Do not use printer name in Linux because GTK backend does not support