Bug 1432285 - Implement an nsPrintingPromptService::GetSingleton method and make XPCOM use that. r=bobowen
MozReview-Commit-ID: 62zz0IKiXq2
--- a/toolkit/components/printingui/nsPrintingPromptService.cpp
+++ b/toolkit/components/printingui/nsPrintingPromptService.cpp
@@ -1,37 +1,68 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* 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 "nsPrintingPromptService.h"
+#include "mozilla/ClearOnShutdown.h"
+#include "mozilla/RefPtr.h"
+#include "mozilla/StaticPtr.h"
#include "nsIDOMWindow.h"
#include "nsIServiceManager.h"
#include "nsISupportsUtils.h"
#include "nsString.h"
#include "nsIPrintDialogService.h"
#include "nsPIDOMWindow.h"
+#include "nsXULAppAPI.h"
// Printing Progress Includes
#if !defined(XP_MACOSX)
#include "nsPrintProgress.h"
#include "nsPrintProgressParams.h"
static const char* kPrintProgressDialogURL =
"chrome://global/content/printProgress.xul";
static const char* kPrtPrvProgressDialogURL =
"chrome://global/content/printPreviewProgress.xul";
#endif
+using namespace mozilla;
+
NS_IMPL_ISUPPORTS(nsPrintingPromptService,
nsIPrintingPromptService,
nsIWebProgressListener)
+
+StaticRefPtr<nsPrintingPromptService> sSingleton;
+
+/* static */ nsPrintingPromptService*
+nsPrintingPromptService::GetSingleton()
+{
+ MOZ_ASSERT(XRE_IsParentProcess(),
+ "The content process must use nsPrintingProxy");
+
+ if (!sSingleton) {
+ sSingleton = new nsPrintingPromptService();
+ sSingleton->Init();
+ ClearOnShutdown(&sSingleton);
+ }
+
+ return sSingleton;
+}
+
+/* static */ already_AddRefed<nsPrintingPromptService>
+nsPrintingPromptService::GetAddRefedSingleton()
+{
+ return do_AddRef(GetSingleton());
+}
+
+
nsPrintingPromptService::nsPrintingPromptService() = default;
nsPrintingPromptService::~nsPrintingPromptService() = default;
nsresult
nsPrintingPromptService::Init()
{
#if !defined(XP_MACOSX)
--- a/toolkit/components/printingui/nsPrintingPromptService.h
+++ b/toolkit/components/printingui/nsPrintingPromptService.h
@@ -26,32 +26,33 @@
#include "nsIWebProgressListener.h"
#if !defined(XP_MACOSX)
#include "nsPrintProgress.h"
class nsIDOMWindow;
class nsIDialogParamBlock;
#endif
-class nsPrintingPromptService
+class nsPrintingPromptService final
: public nsIPrintingPromptService
, public nsIWebProgressListener
{
public:
- nsPrintingPromptService();
-
- nsresult Init();
+ static nsPrintingPromptService* GetSingleton();
+ static already_AddRefed<nsPrintingPromptService> GetAddRefedSingleton();
NS_DECL_NSIPRINTINGPROMPTSERVICE
NS_DECL_NSIWEBPROGRESSLISTENER
NS_DECL_ISUPPORTS
protected:
+ nsPrintingPromptService();
virtual ~nsPrintingPromptService();
+ nsresult Init();
private:
#if !defined(XP_MACOSX)
nsCOMPtr<nsIWindowWatcher> mWatcher;
nsCOMPtr<nsIPrintProgress> mPrintProgress;
nsCOMPtr<nsIWebProgressListener> mWebProgressListener;
#endif
};
--- a/toolkit/xre/nsEmbeddingModule.cpp
+++ b/toolkit/xre/nsEmbeddingModule.cpp
@@ -33,17 +33,18 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsControl
NS_GENERIC_FACTORY_CONSTRUCTOR(nsCommandManager)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsCommandParams)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsControllerCommandGroup)
NS_GENERIC_FACTORY_CONSTRUCTOR(nsBaseCommandController)
#ifdef MOZ_XUL
NS_GENERIC_FACTORY_CONSTRUCTOR(nsDialogParamBlock)
#ifdef NS_PRINTING
-NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsPrintingPromptService, Init)
+NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsPrintingPromptService,
+ nsPrintingPromptService::GetAddRefedSingleton)
#ifdef PROXY_PRINTING
NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsPrintingProxy,
nsPrintingProxy::GetInstance)
#endif
#endif
#endif
#ifdef MOZ_XUL