Back to index

lightning-sunbird  0.9+nobinonly
Defines | Functions | Variables
nsMsgPrintEngine.cpp File Reference
#include "nscore.h"
#include "nsCOMPtr.h"
#include "nsIComponentManager.h"
#include "nsISupports.h"
#include "nsIURI.h"
#include "nsEscape.h"
#include "nsXPIDLString.h"
#include "nsReadableUtils.h"
#include "nsIDocShell.h"
#include "nsIDOMDocument.h"
#include "nsIDOMWindowInternal.h"
#include "nsIDocumentViewer.h"
#include "nsPresContext.h"
#include "nsIPresShell.h"
#include "nsIDocument.h"
#include "nsIMsgMessageService.h"
#include "nsMsgUtils.h"
#include "nsIWebProgress.h"
#include "nsIInterfaceRequestor.h"
#include "nsIInterfaceRequestorUtils.h"
#include "nsIMarkupDocumentViewer.h"
#include "nsIMsgMailSession.h"
#include "nsMsgPrintEngine.h"
#include "nsMsgBaseCID.h"
#include "nsIDocumentLoader.h"
#include "nsIWidget.h"
#include "nsIXULWindow.h"
#include "nsIPrefService.h"
#include "nsIPrefBranch.h"
#include "plevent.h"
#include "nsIEventQueue.h"
#include "nsIEventQueueService.h"
#include "nsIServiceManager.h"
#include "nsIBaseWindow.h"
#include "nsIDocShellTreeOwner.h"
#include "nsIDocShellTreeItem.h"
#include "nsIDocShellTreeNode.h"
#include "nsIWebNavigation.h"
#include "nsIChannel.h"
#include "nsIContentViewerFile.h"
#include "nsIPrintingPromptService.h"

Go to the source code of this file.

Defines

#define DATA_URL_PREFIX   "data:"
#define DATA_URL_PREFIX_LEN   5
#define ADDBOOK_URL_PREFIX   "addbook:"
#define ADDBOOK_URL_PREFIX_LEN   8
#define MESSENGER_STRING_URL   "chrome://messenger/locale/messenger.properties"

Functions

 NS_IMPL_ISUPPORTS4 (nsMsgPrintEngine, nsIMsgPrintEngine, nsIWebProgressListener, nsIObserver, nsISupportsWeakReference) NS_IMETHODIMP nsMsgPrintEngine
PRBool FireEvent (nsMsgPrintEngine *aMPE, PLHandleEventProc handler, PLDestroyEventProc destructor)
void PR_CALLBACK HandlePLEventPrintMsgWindow (PLEvent *aEvent)
void PR_CALLBACK DestroyPLEventPrintMsgWindow (PLEvent *aEvent)
void PR_CALLBACK HandlePLEventStartNext (PLEvent *aEvent)
void PR_CALLBACK DestroyPLEventStartNext (PLEvent *aEvent)

Variables

static const char * kPrintingPromptService = "@mozilla.org/embedcomp/printingprompt-service;1"

Define Documentation

#define ADDBOOK_URL_PREFIX   "addbook:"

Definition at line 491 of file nsMsgPrintEngine.cpp.

Definition at line 492 of file nsMsgPrintEngine.cpp.

#define DATA_URL_PREFIX   "data:"

Definition at line 488 of file nsMsgPrintEngine.cpp.

Definition at line 489 of file nsMsgPrintEngine.cpp.

#define MESSENGER_STRING_URL   "chrome://messenger/locale/messenger.properties"

Definition at line 625 of file nsMsgPrintEngine.cpp.


Function Documentation

Definition at line 793 of file nsMsgPrintEngine.cpp.

{
  nsMsgPrintEngine *msgPrintEngine = (nsMsgPrintEngine*)PL_GetEventOwner(aEvent);
  NS_IF_RELEASE(msgPrintEngine);

  delete aEvent;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 821 of file nsMsgPrintEngine.cpp.

{
  nsMsgPrintEngine *msgPrintEngine = (nsMsgPrintEngine*)PL_GetEventOwner(aEvent);
  NS_IF_RELEASE(msgPrintEngine);

  delete aEvent;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool FireEvent ( nsMsgPrintEngine aMPE,
PLHandleEventProc  handler,
PLDestroyEventProc  destructor 
)

Definition at line 735 of file nsMsgPrintEngine.cpp.

{
  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, aMPE, handler, destructor);

  // The event owns the msgPrintEngine pointer now.
  NS_ADDREF(aMPE);

  if (NS_FAILED(event_queue->PostEvent(event)))
  {
    NS_WARNING("Failed to post event");
    PL_DestroyEvent(event);
    return PR_FALSE;
  }

  return PR_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 781 of file nsMsgPrintEngine.cpp.

{
  nsMsgPrintEngine *msgPrintEngine = (nsMsgPrintEngine*)PL_GetEventOwner(aEvent);

  NS_ASSERTION(msgPrintEngine, "The event owner is null.");
  if (msgPrintEngine)
  {
    msgPrintEngine->PrintMsgWindow();
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 809 of file nsMsgPrintEngine.cpp.

{
  nsMsgPrintEngine *msgPrintEngine = (nsMsgPrintEngine*)PL_GetEventOwner(aEvent);

  NS_ASSERTION(msgPrintEngine, "The event owner is null.");
  if (msgPrintEngine)
  {
    msgPrintEngine->StartNextPrintOperation();
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 108 of file nsMsgPrintEngine.cpp.

{
  nsresult rv = NS_OK;

  // top-level document load data
  if (progressStateFlags & nsIWebProgressListener::STATE_IS_DOCUMENT) {
    if (progressStateFlags & nsIWebProgressListener::STATE_START) {
      // Tell the user we are loading...
      PRUnichar *msg = GetString(NS_LITERAL_STRING("LoadingMessageToPrint").get());
      SetStatusMessage( msg );
      CRTFREEIF(msg)
    }

    if (progressStateFlags & nsIWebProgressListener::STATE_STOP) {
      nsCOMPtr<nsIDocumentLoader> docLoader(do_QueryInterface(aWebProgress));
      if (docLoader)
      {
        // Check to see if the document DOMWin that is finished loading is the same
        // one as the mail msg that we started to load.
        // We only want to print when the entire msg and all of its attachments
        // have finished loading.
        // The mail msg doc is the last one to receive the STATE_STOP notification
        nsCOMPtr<nsISupports> container;
        docLoader->GetContainer(getter_AddRefs(container));
        nsCOMPtr<nsIDOMWindow> domWindow(do_GetInterface(container));
        if (domWindow.get() != mMsgDOMWin.get()) {
          return NS_OK;
        }
      }
      nsCOMPtr<nsIWebProgressListener> wpl(do_QueryInterface(mPrintPromptService));
      if (wpl) {
        wpl->OnStateChange(nsnull, nsnull, nsIWebProgressListener::STATE_STOP|nsIWebProgressListener::STATE_IS_DOCUMENT, nsnull);
        mPrintProgressListener = nsnull;
        mPrintProgress         = nsnull;
        mPrintProgressParams   = nsnull;
      }

      PRBool isPrintingCancelled = PR_FALSE;
      if (mPrintSettings)
      {
        mPrintSettings->GetIsCancelled(&isPrintingCancelled);
      }
      if (!isPrintingCancelled) {
        // if aWebProgress is a documentloader than the notification from
        // loading the documents. If it is NULL (or not a DocLoader) then it
        // it coming from Printing
        if (docLoader) {
          // Now, fire off the print operation!
          rv = NS_ERROR_FAILURE;

          // Tell the user the message is loaded...
          PRUnichar *msg = GetString(NS_LITERAL_STRING("MessageLoaded").get());
          SetStatusMessage( msg );
          if (msg) nsCRT::free(msg);

          NS_ASSERTION(mDocShell,"can't print, there is no docshell");
          if ( (!mDocShell) || (!aRequest) )
          {
            return StartNextPrintOperation();
          }
          nsCOMPtr<nsIChannel> aChannel = do_QueryInterface(aRequest);
          if (!aChannel) return NS_ERROR_FAILURE;

          // Make sure this isn't just "about:blank" finishing....
          nsCOMPtr<nsIURI> originalURI = nsnull;
          if (NS_SUCCEEDED(aChannel->GetOriginalURI(getter_AddRefs(originalURI))) && originalURI)
          {
            nsCAutoString spec;

            if (NS_SUCCEEDED(originalURI->GetSpec(spec)))
            {
              if (spec.Equals("about:blank"))
              {
                return StartNextPrintOperation();
              }
            }
          }

          // If something bad happens here (menaing we can fire the PLEvent, highly unlikely)
          // we will still ask the msg to print, but if the user "cancels" out of the
          // print dialog the hidden print window will not be "closed"
          if (!FirePrintEvent())
          {
            PrintMsgWindow();
          }
        } else {
          FireStartNextEvent();
          rv = NS_OK;
        }
      }
      else
      {
        mWindow->Close();
      }
    }
  }

  return rv;
}

Here is the call graph for this function:


Variable Documentation

const char* kPrintingPromptService = "@mozilla.org/embedcomp/printingprompt-service;1" [static]

Definition at line 89 of file nsMsgPrintEngine.cpp.