Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Public Attributes | Private Member Functions | Private Attributes
nsMsgComposeService Class Reference

#include <nsMsgComposeService.h>

Inheritance diagram for nsMsgComposeService:
Inheritance graph
[legend]
Collaboration diagram for nsMsgComposeService:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 nsMsgComposeService ()
virtual ~nsMsgComposeService ()
NS_DECL_ISUPPORTS
NS_DECL_NSIMSGCOMPOSESERVICE
NS_DECL_NSIOBSERVER
NS_DECL_NSICMDLINEHANDLER
CMDLINEHANDLER_REGISTERPROC_DECLS
nsresult 
Init ()
void Reset ()
void DeleteCachedWindows ()
nsresult AddGlobalHtmlDomains ()
void OpenComposeWindow (in string msgComposeWindowURL, in string originalMsgURI, in MSG_ComposeType type, in MSG_ComposeFormat format, in nsIMsgIdentity identity, in nsIMsgWindow aMsgWindow)
void OpenComposeWindowWithURI (in string msgComposeWindowURL, in nsIURI aURI)
void OpenComposeWindowWithParams (in string msgComposeWindowURL, in nsIMsgComposeParams params)
nsIMsgCompose InitCompose (in nsIDOMWindowInternal aWindow, in nsIMsgComposeParams params)
void TimeStamp (in string label, in boolean resetTime)
boolean determineComposeHTML (in nsIMsgIdentity aIdentity, in MSG_ComposeFormat aFormat)
void cacheWindow (in nsIDOMWindowInternal aWindow, in boolean aComposeHTML, in nsIMsgComposeRecyclingListener listener)
boolean isCachedWindow (in nsIDOMWindowInternal aWindow)
nsIMsgComposeParams getParamsForMailto (in nsIURI aURI)
 given a mailto url, parse the attributes and turn them into a nsIMsgComposeParams object
void forwardMessage (in AString forwardTo, in nsIMsgDBHdr aMsgHdr, in nsIMsgWindow aMsgWindow, in nsIMsgIncomingServer aServer)
void replyWithTemplate (in nsIMsgDBHdr msgHdr, in string templateUri, in nsIMsgWindow aMsgWindow, in nsIMsgIncomingServer server)
void registerComposeWindow (in nsIDOMWindowInternal aWindow, in nsIMsgCompose aMsgCompose)
 Every open compose window registers itself with the compose service This allows consumers to get the msg compose object associated with a dom window.
void unregisterComposeWindow (in nsIDOMWindowInternal aWindow)
 When a compose window is being closed (or recyled), it unregisters itself from the compose service.
nsIMsgCompose getMsgComposeForWindow (in nsIDOMWindowInternal aWindow)
 For aWindow, returns the nsIMsgCompose object associated with the window.
void observe (in nsISupports aSubject, in string aTopic, in wstring aData)
 Observe will be called when there is a notification for the topic |aTopic|.

Public Attributes

readonly attribute nsIMsgIdentity defaultIdentity
 defaultIdentity
readonly attribute boolean logComposePerformance

Private Member Functions

nsresult OpenWindow (const char *chrome, nsIMsgComposeParams *params)
void CloseWindow (nsIDOMWindowInternal *domWindow)
nsresult LoadDraftOrTemplate (const nsACString &aMsgURI, nsMimeOutputType aOutType, nsIMsgIdentity *aIdentity, const char *aOriginalMsgURI, PRBool aAddInlineHeaders, nsIMsgWindow *aMsgWindow)
 LoadDraftOrTemplate Helper routine used to run msgURI through libmime in order to fetch the contents for a draft or template.
nsresult ShowCachedComposeWindow (nsIDOMWindowInternal *aComposeWindow, PRBool aShow)

Private Attributes

PRBool mLogComposePerformance
PRInt32 mMaxRecycledWindows
nsMsgCachedWindowInfomCachedWindows
nsInterfaceHashtable
< nsISupportsHashKey,
nsIWeakReference
mOpenComposeWindows
PRIntervalTime mStartTime
PRIntervalTime mPreviousTime

Detailed Description

Definition at line 79 of file nsMsgComposeService.h.


Constructor & Destructor Documentation

Definition at line 150 of file nsMsgComposeService.cpp.

{
#ifdef NS_DEBUG
  NS_ASSERTION(!_just_to_be_sure_we_create_only_one_compose_service_, "You cannot create several message compose service!");
  _just_to_be_sure_we_create_only_one_compose_service_ = PR_TRUE;
#endif

// Defaulting the value of mLogComposePerformance to FALSE to prevent logging.
  mLogComposePerformance = PR_FALSE;
#ifdef MSGCOMP_TRACE_PERFORMANCE
  if (!MsgComposeLogModule)
      MsgComposeLogModule = PR_NewLogModule("msgcompose");

  mStartTime = PR_IntervalNow();
  mPreviousTime = mStartTime;
#endif

  mMaxRecycledWindows = 0;
  mCachedWindows = nsnull;
}

Member Function Documentation

Check to see if we need to add any global domains. If so, make sure the following prefs are added to mailnews.js

  1. pref("mailnews.global_html_domains.version", version number); This pref registers the current version in the user prefs file. A default value is stored in mailnews file. Depending the changes we plan to make we can move the default version number. Comparing version number from user's prefs file and the default one from mailnews.js, we can effect ppropriate changes.
  1. pref("mailnews.global_html_domains", <comma separated="" domain="" list>="">); This pref contains the list of html domains that ISP can add to make that user's contain all of these under the HTML domains in the Mail&NewsGrpus|Send Format under global preferences.

Definition at line 1246 of file nsMsgComposeService.cpp.

{

  nsresult rv;
  nsCOMPtr<nsIPrefService> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID, &rv);
  NS_ENSURE_SUCCESS(rv,rv);

  nsCOMPtr<nsIPrefBranch> prefBranch;
  rv = prefs->GetBranch(MAILNEWS_ROOT_PREF, getter_AddRefs(prefBranch));
  NS_ENSURE_SUCCESS(rv,rv);

  nsCOMPtr<nsIPrefBranch> defaultsPrefBranch;
  rv = prefs->GetDefaultBranch(MAILNEWS_ROOT_PREF, getter_AddRefs(defaultsPrefBranch));
  NS_ENSURE_SUCCESS(rv,rv);

  PRInt32 htmlDomainListCurrentVersion, htmlDomainListDefaultVersion;
  rv = prefBranch->GetIntPref(HTMLDOMAINUPDATE_VERSION_PREF_NAME, &htmlDomainListCurrentVersion);
  NS_ENSURE_SUCCESS(rv,rv);

  rv = defaultsPrefBranch->GetIntPref(HTMLDOMAINUPDATE_VERSION_PREF_NAME, &htmlDomainListDefaultVersion);
  NS_ENSURE_SUCCESS(rv,rv);
  
  // Update the list as needed
  if (htmlDomainListCurrentVersion <= htmlDomainListDefaultVersion) {
    // Get list of global domains need to be added
    nsXPIDLCString globalHtmlDomainList;
    rv = prefBranch->GetCharPref(HTMLDOMAINUPDATE_DOMAINLIST_PREF_NAME, getter_Copies(globalHtmlDomainList));

    if (NS_SUCCEEDED(rv) && !globalHtmlDomainList.IsEmpty()) {

      // Get user's current HTML domain set for send format
      nsXPIDLCString currentHtmlDomainList;
      rv = prefBranch->GetCharPref(USER_CURRENT_HTMLDOMAINLIST_PREF_NAME, getter_Copies(currentHtmlDomainList));
      NS_ENSURE_SUCCESS(rv,rv);

      nsCAutoString newHtmlDomainList(currentHtmlDomainList);
      // Get the current html domain list into new list var
      nsCStringArray htmlDomainArray;
      if (!currentHtmlDomainList.IsEmpty()) 
        htmlDomainArray.ParseString(currentHtmlDomainList.get(), DOMAIN_DELIMITER);

      // Get user's current Plaintext domain set for send format
      nsXPIDLCString currentPlaintextDomainList;
      rv = prefBranch->GetCharPref(USER_CURRENT_PLAINTEXTDOMAINLIST_PREF_NAME, getter_Copies(currentPlaintextDomainList));
      NS_ENSURE_SUCCESS(rv,rv);

      // Get the current plaintext domain list into new list var
      nsCStringArray plaintextDomainArray;
      if (!currentPlaintextDomainList.IsEmpty()) 
        plaintextDomainArray.ParseString(currentPlaintextDomainList.get(), DOMAIN_DELIMITER);
    
      if (htmlDomainArray.Count() || plaintextDomainArray.Count()) {
        // Tokenize the data and add each html domain if it is not alredy there in 
        // the user's current html or plaintext domain lists
        char *newData;
        char *globalData = ToNewCString(globalHtmlDomainList);
  
        char *token = nsCRT::strtok(globalData, DOMAIN_DELIMITER, &newData);

        nsCAutoString htmlDomain;
        while (token) {
          if (token && *token) {
            htmlDomain.Assign(token);
            htmlDomain.StripWhitespace();

            if (htmlDomainArray.IndexOf(htmlDomain) == -1  && 
                plaintextDomainArray.IndexOf(htmlDomain) == -1) {
              if (!newHtmlDomainList.IsEmpty())
                newHtmlDomainList += DOMAIN_DELIMITER;
              newHtmlDomainList += htmlDomain;
            }
          }
          token = nsCRT::strtok(newData, DOMAIN_DELIMITER, &newData);
        }
        PR_FREEIF(globalData);
      }
      else
      {
        // User has no domains listed either in html or plain text category.
        // Assign the global list to be the user's current html domain list
        newHtmlDomainList = globalHtmlDomainList;
      }

      // Set user's html domain pref with the updated list
      rv = prefBranch->SetCharPref(USER_CURRENT_HTMLDOMAINLIST_PREF_NAME, newHtmlDomainList.get());
      NS_ENSURE_SUCCESS(rv,rv);

      // Increase the version to avoid running the update code unless needed (based on default version)
      rv = prefBranch->SetIntPref(HTMLDOMAINUPDATE_VERSION_PREF_NAME, htmlDomainListCurrentVersion + 1);
      NS_ENSURE_SUCCESS(rv,rv);
    }
  }
  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 318 of file nsMsgComposeService.cpp.

{
  if (domWindow)
  {
    nsCOMPtr<nsIDocShell> docshell;
    nsCOMPtr<nsIScriptGlobalObject> globalObj(do_QueryInterface(domWindow));
    if (globalObj)
    {
      nsCOMPtr<nsIDocShellTreeItem> treeItem =
        do_QueryInterface(globalObj->GetDocShell());

      if (treeItem)
      {
        nsCOMPtr<nsIDocShellTreeOwner> treeOwner;
        treeItem->GetTreeOwner(getter_AddRefs(treeOwner));
        if (treeOwner)
        {
          nsCOMPtr<nsIBaseWindow> baseWindow;
          baseWindow = do_QueryInterface(treeOwner);
          if (baseWindow)
            baseWindow->Destroy();
        }
      }
    }
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 242 of file nsMsgComposeService.cpp.

{
  PRInt32 i;
  for (i = 0; i < mMaxRecycledWindows; i ++)
  {
    CloseWindow(mCachedWindows[i].window);
    mCachedWindows[i].Clear();
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsIMsgComposeService::forwardMessage ( in AString  forwardTo,
in nsIMsgDBHdr  aMsgHdr,
in nsIMsgWindow  aMsgWindow,
in nsIMsgIncomingServer  aServer 
) [inherited]

For aWindow, returns the nsIMsgCompose object associated with the window.

Parameters:
aWindowThe DOMWindow associated with the compose window.
Returns:
NS_ERROR_FAILURE if we could not find a nsIMsgCompose for the passed in DOM Window.

given a mailto url, parse the attributes and turn them into a nsIMsgComposeParams object

Returns:
nsIMsgComposeParams which corresponds to the passed in mailto url

Definition at line 188 of file nsMsgComposeService.cpp.

{
  nsresult rv = NS_OK;
  // Register observers

  // Register for quit application and profile change, we will need to clear the cache.
  nsCOMPtr<nsIObserverService> observerService = do_GetService("@mozilla.org/observer-service;1", &rv);
  if (NS_SUCCEEDED(rv))
  {
    rv = observerService->AddObserver(this, "quit-application", PR_TRUE);
    rv = observerService->AddObserver(this, "profile-do-change", PR_TRUE);
  }

  // Register some pref observer
  nsCOMPtr<nsIPrefBranch2> pbi = do_GetService(NS_PREFSERVICE_CONTRACTID);
  if (pbi)
    rv = pbi->AddObserver(PREF_MAIL_COMPOSE_MAXRECYCLEDWINDOWS, this, PR_TRUE);

  mOpenComposeWindows.Init();
  Reset();

  AddGlobalHtmlDomains();
  return rv;
}

Here is the call graph for this function:

nsresult nsMsgComposeService::LoadDraftOrTemplate ( const nsACString &  aMsgURI,
nsMimeOutputType  aOutType,
nsIMsgIdentity aIdentity,
const char *  aOriginalMsgURI,
PRBool  aAddInlineHeaders,
nsIMsgWindow aMsgWindow 
) [private]

LoadDraftOrTemplate Helper routine used to run msgURI through libmime in order to fetch the contents for a draft or template.

Definition at line 1415 of file nsMsgComposeService.cpp.

{
  nsresult rv;
  nsCOMPtr <nsIMsgMessageService> messageService;
  rv = GetMessageServiceFromURI(nsPromiseFlatCString(aMsgURI).get(), getter_AddRefs(messageService));
  NS_ENSURE_SUCCESS(rv, rv);

  // Now, we can create a mime parser (nsIStreamConverter)!
  nsCOMPtr<nsIMimeStreamConverter> mimeConverter = 
    do_CreateInstance(NS_MAILNEWS_MIME_STREAM_CONVERTER_CONTRACTID, &rv);
  NS_ENSURE_SUCCESS(rv, rv);
  
  mimeConverter->SetMimeOutputType(aOutType);  // Set the type of output for libmime
  mimeConverter->SetForwardInline(aAddInlineHeaders);
  mimeConverter->SetIdentity(aIdentity);
  mimeConverter->SetOriginalMsgURI(aOriginalMsgURI);

  nsCOMPtr<nsIURI> url;
  PRBool fileUrl = StringBeginsWith(aMsgURI, NS_LITERAL_CSTRING("file:"));
  nsACString::const_iterator start, end;
  aMsgURI.BeginReading(start);
  aMsgURI.EndReading(end);
  if (fileUrl || FindInReadable(NS_LITERAL_CSTRING("&type=application/x-message-display"), start, end))
    rv = NS_NewURI(getter_AddRefs(url), aMsgURI);
  else
    rv = messageService->GetUrlForUri(nsPromiseFlatCString(aMsgURI).get(), getter_AddRefs(url), aMsgWindow);
  NS_ENSURE_SUCCESS(rv, rv);

  rv = url->SetSpec(aMsgURI);
  NS_ENSURE_SUCCESS(rv, rv);

  // if we are forwarding a message and that message used a charset over ride
  // then use that over ride charset instead of the charset specified in the message
  nsXPIDLCString mailCharset;
  if (aMsgWindow)
  {
    PRBool charsetOverride;
    if (NS_SUCCEEDED(aMsgWindow->GetCharsetOverride(&charsetOverride)) && charsetOverride)
    {
      if (NS_SUCCEEDED(aMsgWindow->GetMailCharacterSet(getter_Copies(mailCharset))))
      {
        nsCOMPtr<nsIMsgI18NUrl> i18nUrl(do_QueryInterface(url));
        if (i18nUrl)
          (void) i18nUrl->SetCharsetOverRide(mailCharset.get());
      }
    }
  }

  nsCOMPtr<nsIChannel> channel;
  rv = NS_NewInputStreamChannel(getter_AddRefs(channel), url, nsnull);
  NS_ENSURE_SUCCESS(rv, rv);
  
  nsCOMPtr<nsIStreamConverter> converter = do_QueryInterface(mimeConverter);
  rv = converter->AsyncConvertData(nsnull, nsnull, nsnull, channel);
  NS_ENSURE_SUCCESS(rv, rv);

  // Now, just plug the two together and get the hell out of the way!
  nsCOMPtr<nsIStreamListener> streamListener = do_QueryInterface(mimeConverter); 
  return messageService->DisplayMessage(nsPromiseFlatCString(aMsgURI).get(), streamListener, aMsgWindow, nsnull, mailCharset, nsnull);;
}

Here is the call graph for this function:

void nsIObserver::observe ( in nsISupports  aSubject,
in string  aTopic,
in wstring  aData 
) [inherited]

Observe will be called when there is a notification for the topic |aTopic|.

This assumes that the object implementing this interface has been registered with an observer service such as the nsIObserverService.

If you expect multiple topics/subjects, the impl is responsible for filtering.

You should not modify, add, remove, or enumerate notifications in the implemention of observe.

Parameters:
aSubject: Notification specific interface pointer.
aTopic: The notification topic or subject.
aData: Notification specific wide string. subject event.
void nsIMsgComposeService::OpenComposeWindow ( in string  msgComposeWindowURL,
in string  originalMsgURI,
in MSG_ComposeType  type,
in MSG_ComposeFormat  format,
in nsIMsgIdentity  identity,
in nsIMsgWindow  aMsgWindow 
) [inherited]
void nsIMsgComposeService::OpenComposeWindowWithParams ( in string  msgComposeWindowURL,
in nsIMsgComposeParams  params 
) [inherited]
void nsIMsgComposeService::OpenComposeWindowWithURI ( in string  msgComposeWindowURL,
in nsIURI  aURI 
) [inherited]
nsresult nsMsgComposeService::OpenWindow ( const char *  chrome,
nsIMsgComposeParams params 
) [private]

Definition at line 253 of file nsMsgComposeService.cpp.

{
  nsresult rv;
  
  NS_ENSURE_ARG_POINTER(params);
  
  //Use default identity if no identity has been specified
  nsCOMPtr<nsIMsgIdentity> identity; 
  params->GetIdentity(getter_AddRefs(identity));
  if (!identity)
  {
    GetDefaultIdentity(getter_AddRefs(identity));
    params->SetIdentity(identity);
  }

  //if we have a cached window for the default chrome, try to reuse it...
  if (chrome == nsnull || nsCRT::strcasecmp(chrome, DEFAULT_CHROME) == 0)
  {
    MSG_ComposeFormat format;
    params->GetFormat(&format);

    PRBool composeHTML = PR_TRUE;
    rv = DetermineComposeHTML(identity, format, &composeHTML);
    if (NS_SUCCEEDED(rv))
    {
      PRInt32 i;
      for (i = 0; i < mMaxRecycledWindows; i ++)
      {
        if (mCachedWindows[i].window && (mCachedWindows[i].htmlCompose == composeHTML) && mCachedWindows[i].listener)
        {
          /* We need to save the window pointer as OnReopen will call nsMsgComposeService::InitCompose which will
             clear the cache entry if everything goes well
          */
          nsCOMPtr<nsIDOMWindowInternal> domWindow(mCachedWindows[i].window);
          rv = ShowCachedComposeWindow(domWindow, PR_TRUE);
          if (NS_SUCCEEDED(rv))
          {
            mCachedWindows[i].listener->OnReopen(params);
            return NS_OK;
          }
        }
      }
    }
  }
      
  //Else, create a new one...
  nsCOMPtr<nsIWindowWatcher> wwatch(do_GetService(NS_WINDOWWATCHER_CONTRACTID));
  if (!wwatch)
    return NS_ERROR_FAILURE;

  nsCOMPtr<nsISupportsInterfacePointer> msgParamsWrapper =
    do_CreateInstance(NS_SUPPORTS_INTERFACE_POINTER_CONTRACTID, &rv);
  NS_ENSURE_SUCCESS(rv, rv);

  msgParamsWrapper->SetData(params);
  msgParamsWrapper->SetDataIID(&NS_GET_IID(nsIMsgComposeParams));

  nsCOMPtr<nsIDOMWindow> newWindow;
  rv = wwatch->OpenWindow(0, chrome && *chrome ? chrome : DEFAULT_CHROME,
                 "_blank", "all,chrome,dialog=no,status,toolbar", msgParamsWrapper,
                 getter_AddRefs(newWindow));

  return rv;
}

Here is the call graph for this function:

Every open compose window registers itself with the compose service This allows consumers to get the msg compose object associated with a dom window.

Parameters:
aWindowThe DOM Window
aMsgComposeThe compose object associated with the compose window
void nsIMsgComposeService::replyWithTemplate ( in nsIMsgDBHdr  msgHdr,
in string  templateUri,
in nsIMsgWindow  aMsgWindow,
in nsIMsgIncomingServer  server 
) [inherited]

Definition at line 213 of file nsMsgComposeService.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1181 of file nsMsgComposeService.cpp.

{
  nsresult rv = NS_OK;

  nsCOMPtr <nsIScriptGlobalObject> globalScript = do_QueryInterface(aComposeWindow, &rv);

  NS_ENSURE_SUCCESS(rv,rv);

  nsIDocShell *docShell = globalScript->GetDocShell();

  nsCOMPtr <nsIDocShellTreeItem> treeItem = do_QueryInterface(docShell, &rv);
  NS_ENSURE_SUCCESS(rv,rv);

  nsCOMPtr <nsIDocShellTreeOwner> treeOwner;
  rv = treeItem->GetTreeOwner(getter_AddRefs(treeOwner));
  NS_ENSURE_SUCCESS(rv,rv);
  
  if (treeOwner) {

    // the window need to be sticky before we hide it.
    nsCOMPtr<nsIContentViewer> contentViewer;
    rv = docShell->GetContentViewer(getter_AddRefs(contentViewer));
    NS_ENSURE_SUCCESS(rv,rv);
    
    rv = contentViewer->SetSticky(!aShow);
    NS_ENSURE_SUCCESS(rv,rv);

    // disable (enable) the cached window
    nsCOMPtr<nsIBaseWindow> baseWindow;
    baseWindow = do_QueryInterface(treeOwner, &rv);
    NS_ENSURE_SUCCESS(rv,rv);

    baseWindow->SetEnabled(aShow);
    NS_ENSURE_SUCCESS(rv,rv);

    nsCOMPtr <nsIXULWindow> xulWindow = do_GetInterface(treeOwner, &rv);
    NS_ENSURE_SUCCESS(rv,rv);

    nsCOMPtr<nsIWindowMediator> windowMediator = 
                do_GetService(NS_WINDOWMEDIATOR_CONTRACTID, &rv);
    NS_ENSURE_SUCCESS(rv,rv);

    // if showing, reinstate the window with the mediator
    if (aShow) {
      rv = windowMediator->RegisterWindow(xulWindow);
      NS_ENSURE_SUCCESS(rv,rv);
    }

    // hide (show) the cached window
    rv = baseWindow->SetVisibility(aShow);
    NS_ENSURE_SUCCESS(rv,rv);

    // if hiding, remove the window from the mediator,
    // so that it will be removed from the task list
    if (!aShow) {
      rv = windowMediator->UnregisterWindow(xulWindow);
      NS_ENSURE_SUCCESS(rv,rv);
    }
  }
  else {
    rv = NS_ERROR_FAILURE;
  }
  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsIMsgComposeService::TimeStamp ( in string  label,
in boolean  resetTime 
) [inherited]

When a compose window is being closed (or recyled), it unregisters itself from the compose service.

Parameters:
aWindowThe DOM Window

Member Data Documentation

defaultIdentity

Returns:
the default identity, in case no identity has been setup yet, will return null

Definition at line 78 of file nsIMsgComposeService.idl.

Definition at line 84 of file nsIMsgComposeService.idl.

Definition at line 109 of file nsMsgComposeService.h.

Definition at line 106 of file nsMsgComposeService.h.

Definition at line 108 of file nsMsgComposeService.h.

Definition at line 122 of file nsMsgComposeService.h.

Definition at line 126 of file nsMsgComposeService.h.

Definition at line 125 of file nsMsgComposeService.h.


The documentation for this class was generated from the following files: