Bug 1432285 - Implement an nsPrintingPromptService::GetSingleton method and make XPCOM use that. r=bobowen

MozReview-Commit-ID: AsiAnJrxKlB
This commit is contained in:
Jonathan Watt 2018-01-16 11:47:19 +00:00
Родитель 98d61a685f
Коммит eec7e0d104
3 изменённых файлов: 31 добавлений и 6 удалений

Просмотреть файл

@ -5,12 +5,16 @@
#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)
@ -23,10 +27,31 @@ static const char* kPrtPrvProgressDialogURL =
"chrome://global/content/printPreviewProgress.xul";
#endif
using namespace mozilla;
NS_IMPL_ISUPPORTS(nsPrintingPromptService,
nsIPrintingPromptService,
nsIWebProgressListener)
StaticRefPtr<nsPrintingPromptService> sSingleton;
/* static */ already_AddRefed<nsPrintingPromptService>
nsPrintingPromptService::GetSingleton()
{
MOZ_ASSERT(XRE_IsParentProcess(),
"The content process must use nsPrintingProxy");
if (!sSingleton) {
sSingleton = new nsPrintingPromptService();
sSingleton->Init();
ClearOnShutdown(&sSingleton);
}
return do_AddRef(sSingleton);
}
nsPrintingPromptService::nsPrintingPromptService() = default;
nsPrintingPromptService::~nsPrintingPromptService() = default;

Просмотреть файл

@ -31,22 +31,21 @@ class nsIDOMWindow;
class nsIDialogParamBlock;
#endif
class nsPrintingPromptService
class nsPrintingPromptService final
: public nsIPrintingPromptService
, public nsIWebProgressListener
{
public:
nsPrintingPromptService();
nsresult Init();
static already_AddRefed<nsPrintingPromptService> GetSingleton();
NS_DECL_NSIPRINTINGPROMPTSERVICE
NS_DECL_NSIWEBPROGRESSLISTENER
NS_DECL_ISUPPORTS
protected:
nsPrintingPromptService();
virtual ~nsPrintingPromptService();
nsresult Init();
private:
#if !defined(XP_MACOSX)

Просмотреть файл

@ -38,7 +38,8 @@ 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::GetSingleton)
#ifdef PROXY_PRINTING
NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsPrintingProxy,
nsPrintingProxy::GetInstance)