mWWatch(do_GetService("@mozilla.org/embedcomp/window-watcher;1")),
mWWatch(do_GetService(NS_WINDOWWATCHER_CONTRACTID)),
static void PR_CALLBACK DestroyPLEvent(PLEvent* aEvent);//*****************************************************************************NS_IMPL_ISUPPORTS2(CPrintingPromptService, nsIPrintingPromptService, nsIWebProgressListener)CPrintingPromptService::CPrintingPromptService() :  mWWatch(do_GetService("@mozilla.org/embedcomp/window-watcher;1")),  m_PPDlg(NULL){  NS_INIT_REFCNT();}CPrintingPromptService::~CPrintingPromptService() {}CWnd *CPrintingPromptService::CWndForDOMWindow(nsIDOMWindow *aWindow){  nsCOMPtr<nsIWebBrowserChrome> chrome;  CWnd *val = 0;  if (mWWatch) {    nsCOMPtr<nsIDOMWindow> fosterParent;    if (!aWindow) { // it will be a dependent window. try to find a foster parent.      mWWatch->GetActiveWindow(getter_AddRefs(fosterParent));      aWindow = fosterParent;    }    mWWatch->GetChromeForWindow(aWindow, getter_AddRefs(chrome));  }  if (chrome) {    nsCOMPtr<nsIEmbeddingSiteWindow> site(do_QueryInterface(chrome));    if (site) {      HWND w;      site->GetSiteWindow(reinterpret_cast<void **>(&w));      val = CWnd::FromHandle(w);    }  }  return val;}///////////////////////////////////////////////////////////////////////////////// nsIPrintingPrompt//-----------------------------------------------------------NS_IMETHODIMP CPrintingPromptService::ShowPrintDialog(nsIDOMWindow *parent, nsIWebBrowserPrint *webBrowserPrint, nsIPrintSettings *printSettings){    //NS_ENSURE_ARG(parent);    CWnd* wnd = CWndForDOMWindow(parent);    NS_ASSERTION(wnd && wnd->m_hWnd, "Couldn't get native window for PRint Dialog!");    if (wnd && wnd->m_hWnd) {      return NativeShowPrintDialog(wnd->m_hWnd, webBrowserPrint, printSettings);    } else {      return NS_ERROR_FAILURE;    }}//-----------------------------------------------------------PRBoolCPrintingPromptService::FirePauseEvent(){  static NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID);  nsCOMPtr<nsIEventQueueService> event_service = do_GetService(kEventQueueServiceCID);  if (!event_service)   {    NS_WARNING("Failed to get event queue service");    return PR_FALSE;  }  nsCOMPtr<nsIEventQueue> event_queue;  event_service->GetThreadEventQueue(NS_CURRENT_THREAD,                                     getter_AddRefs(event_queue));  if (!event_queue)   {    NS_WARNING("Failed to get event queue from service");    return PR_FALSE;  }  PLEvent *event = new PLEvent;  if (!event)   {    NS_WARNING("Out of memory?");    return PR_FALSE;  }  PL_InitEvent(event, this, (PLHandleEventProc)::HandlePLEvent, (PLDestroyEventProc)::DestroyPLEvent);  // The event owns the content pointer now.  NS_ADDREF_THIS();  event_queue->PostEvent(event);  return PR_TRUE;}/* void showProgress (in nsIDOMWindow parent, in nsIWebBrowserPrint webBrowserPrint, in nsIPrintSettings printSettings, in nsIObserver openDialogObserver, in boolean isForPrinting, out nsIWebProgressListener webProgressListener, out nsIPrintProgressParams printProgressParams, out boolean notifyOnOpen); */NS_IMETHODIMP CPrintingPromptService::ShowProgress(nsIDOMWindow*            parent,                                       nsIWebBrowserPrint*      webBrowserPrint,    // ok to be null                                      nsIPrintSettings*        printSettings,      // ok to be null                                      nsIObserver*             openDialogObserver, // ok to be null                                      PRBool                   isForPrinting,                                      nsIWebProgressListener** webProgressListener,                                      nsIPrintProgressParams** printProgressParams,                                      PRBool*                  notifyOnOpen){    NS_ENSURE_ARG(webProgressListener);    NS_ENSURE_ARG(printProgressParams);    NS_ENSURE_ARG(notifyOnOpen);    ResourceState setState;    nsresult rv;    nsPrintProgressParams* prtProgressParams = new nsPrintProgressParams();    rv = prtProgressParams->QueryInterface(NS_GET_IID(nsIPrintProgressParams), (void**)printProgressParams);    NS_ENSURE_SUCCESS(rv, rv);    mObserver = openDialogObserver;    *notifyOnOpen = PR_FALSE;    if (printProgressParams)     {      CWnd *wnd = CWndForDOMWindow(parent);      m_PPDlg = new CPrintProgressDialog(wnd, isForPrinting, *printProgressParams, webBrowserPrint, printSettings);      m_PPDlg->Create(IDD_PRINT_PROGRESS_DIALOG);      m_PPDlg->ShowWindow(SW_SHOW);      m_PPDlg->UpdateWindow();      *notifyOnOpen = FirePauseEvent();    }    *webProgressListener = NS_STATIC_CAST(nsIWebProgressListener*, this);    NS_ADDREF(*webProgressListener);    return rv;}/* void showPageSetup (in nsIDOMWindow parent, in nsIPrintSettings printSettings); */NS_IMETHODIMP CPrintingPromptService::ShowPageSetup(nsIDOMWindow *parent, nsIPrintSettings *printSettings, nsIObserver *aObs){    NS_ENSURE_ARG(printSettings);    return NS_ERROR_NOT_IMPLEMENTED;}/* void showPrinterProperties (in nsIDOMWindow parent, in wstring printerName, in nsIPrintSettings printSettings); */NS_IMETHODIMP CPrintingPromptService::ShowPrinterProperties(nsIDOMWindow *parent, const PRUnichar *printerName, nsIPrintSettings *printSettings){    return NS_ERROR_NOT_IMPLEMENTED;}//------------------------------------------------------------------------void CPrintingPromptService::NotifyObserver(){  if (mObserver) {    mObserver->Observe(nsnull, nsnull, nsnull);  }}//------------------------------------------------------------------------void PR_CALLBACK HandlePLEvent(PLEvent* aEvent){  CPrintingPromptService *printingPromptService = (CPrintingPromptService*)PL_GetEventOwner(aEvent);  NS_ASSERTION(printingPromptService, "The event owner is null.");  if (printingPromptService) {    printingPromptService->NotifyObserver();  }}//------------------------------------------------------------------------void PR_CALLBACK DestroyPLEvent(PLEvent* aEvent){  CPrintingPromptService *printingPromptService = (CPrintingPromptService*)PL_GetEventOwner(aEvent);  NS_IF_RELEASE(printingPromptService);  delete aEvent;}