When initializing the compose app core, use the app cores service manager to register our app core. When deleting the app core, remove ourselves from the appcores manager. More memory leak fixes from Bruce Mitchener <bruce@cybersight.com>.

This commit is contained in:
mscott%netscape.com 1999-03-30 01:12:58 +00:00
Родитель fcf9ca4c61
Коммит 7486dfc494
1 изменённых файлов: 131 добавлений и 72 удалений

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

@ -19,7 +19,9 @@
#include "nsIDOMComposeAppCore.h"
#include "nsComposeAppCore.h"
#include "nsIScriptObjectOwner.h"
#include "nsAppCoresCIDs.h"
#include "nsIDOMBaseAppCore.h"
#include "nsIDOMAppCoresManager.h"
#include "nsJSComposeAppCore.h"
#include "nsIDOMDocument.h"
#include "nsIDOMNodeList.h"
@ -59,6 +61,8 @@
#include "nsFileSpec.h"
#include "nsFileStream.h"
static NS_DEFINE_IID(kIDOMAppCoresManagerIID, NS_IDOMAPPCORESMANAGER_IID);
static NS_DEFINE_IID(kAppCoresManagerCID, NS_APPCORESMANAGER_CID);
static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
static NS_DEFINE_IID(kIDocumentIID, nsIDocument::GetIID());
@ -74,12 +78,6 @@ static NS_DEFINE_CID(kMsgSendCID, NS_MSGSEND_CID);
static NS_DEFINE_CID(kAppShellServiceCID, NS_APPSHELL_SERVICE_CID);
static NS_DEFINE_IID(kIRDFResourceIID, NS_IRDFRESOURCE_IID);
NS_BEGIN_EXTERN_C
//nsresult NS_MailNewsLoadUrl(const nsString& urlString, nsISupports * aConsumer);
NS_END_EXTERN_C
// defined in msgCompGlue.cpp
extern char * INTL_GetDefaultMailCharset(void);
extern nsresult ConvertFromUnicode(const nsString aCharset,
@ -158,6 +156,7 @@ protected:
//
nsComposeAppCore::nsComposeAppCore()
{
NS_INIT_REFCNT();
mScriptObject = nsnull;
mWebShell = nsnull;
mScriptContext = nsnull;
@ -165,12 +164,23 @@ nsComposeAppCore::nsComposeAppCore()
mEditor = nsnull;
mMsgCompFields = nsnull;
mMsgSend = nsnull;
NS_INIT_REFCNT();
}
nsComposeAppCore::~nsComposeAppCore()
{
// remove ourselves from the app cores manager...
// if we were able to inherit directly from nsBaseAppCore then it would do this for
// us automatically
nsIDOMAppCoresManager * appCoreManager;
nsresult rv = nsServiceManager::GetService(kAppCoresManagerCID, kIDOMAppCoresManagerIID,
(nsISupports**)&appCoreManager);
if (NS_SUCCEEDED(rv) && appCoreManager)
{
appCoreManager->Remove((nsIDOMBaseAppCore *) this);
nsServiceManager::ReleaseService(kAppCoresManagerCID, appCoreManager);
}
NS_IF_RELEASE(mWebShell);
NS_IF_RELEASE(mScriptContext);
NS_IF_RELEASE(mWindow);
@ -310,7 +320,12 @@ nsComposeAppCore::HackToGetBody(PRInt32 what)
msgBody += "> ";
msgBody += buffer;
}
mMsgCompFields->SetBody(msgBody.ToNewCString(), NULL);
// mMsgCompFields->SetBody(msgBody.ToNewCString(), NULL);
// SetBody() strdup()'s cmsgBody.
char* cmsgBody = msgBody.ToNewCString();
mMsgCompFields->SetBody(cmsgBody, NULL);
delete[] cmsgBody;
PR_Free(buffer);
}
}
@ -446,9 +461,21 @@ nsComposeAppCore::SetScriptObject(void* aScriptObject)
nsresult
nsComposeAppCore::Init(const nsString& aId)
{
printf("Init\n");
mId = aId;
nsresult res;
mId = aId;
// add ourselves to the app cores manager...
// if we were able to inherit directly from nsBaseAppCore then it would do this for
// us automatically
nsIDOMAppCoresManager * appCoreManager;
nsresult rv = nsServiceManager::GetService(kAppCoresManagerCID, kIDOMAppCoresManagerIID,
(nsISupports**)&appCoreManager);
if (NS_SUCCEEDED(rv) && appCoreManager)
{
appCoreManager->Add((nsIDOMBaseAppCore *) this);
nsServiceManager::ReleaseService(kAppCoresManagerCID, appCoreManager);
}
if (!mMsgSend)
{
@ -476,7 +503,6 @@ nsComposeAppCore::Init(const nsString& aId)
nsresult
nsComposeAppCore::GetId(nsString& aId)
{
printf("GetID\n");
aId = mId;
return NS_OK;
}
@ -593,9 +619,15 @@ nsComposeAppCore::NewMessage(nsAutoString& aUrl,
{
bString += "Re: ";
bString += aString;
mMsgCompFields->SetSubject(bString.ToNewCString(), NULL);
char* cSubject = bString.ToNewCString();
mMsgCompFields->SetSubject(cSubject, NULL);
delete[] cSubject;
message->GetAuthor(aString);
mMsgCompFields->SetTo(aString.ToNewCString(), NULL);
char * cTo = aString.ToNewCString();
mMsgCompFields->SetTo(cTo, NULL);
delete[] cTo;
if (messageType == 1)
{
nsString cString, dString;
@ -604,7 +636,9 @@ nsComposeAppCore::NewMessage(nsAutoString& aUrl,
if (cString.Length() > 0 && dString.Length() > 0)
cString = cString + ", ";
cString = cString + dString;
mMsgCompFields->SetCc(cString.ToNewCString(), NULL);
char* cCc = cString.ToNewCString();
mMsgCompFields->SetCc(cCc, NULL);
delete[] cCc;
}
HackToGetBody(1);
break;
@ -616,7 +650,11 @@ nsComposeAppCore::NewMessage(nsAutoString& aUrl,
bString += "[Fwd: ";
bString += aString;
bString += "]";
mMsgCompFields->SetSubject(bString.ToNewCString(), NULL);
char* cSubject = bString.ToNewCString();
mMsgCompFields->SetSubject(cSubject, NULL);
delete[] cSubject;
/* We need to get more information out from the message. */
nsCOMPtr<nsIRDFResource> rdfResource;
rv = object->QueryInterface(kIRDFResourceIID,
@ -670,7 +708,8 @@ NS_IMETHODIMP nsComposeAppCore::SendMessage(nsAutoString& aAddrTo,
#endif //DEBUG
// nsIMsgCompose *pMsgCompose;
if (mMsgCompFields) {
if (mMsgCompFields)
{
// Get the default charset from pref, use this as a mail charset for now.
// TODO: For reply/forward, original charset need to be used instead.
// TODO: Also need to update charset for the charset menu.
@ -686,48 +725,68 @@ NS_IMETHODIMP nsComposeAppCore::SendMessage(nsAutoString& aAddrTo,
mMsgCompFields->SetOrganization((char *)pCompPrefs.GetOrganization(), NULL);
// Convert fields to UTF-8
if (NS_SUCCEEDED(ConvertFromUnicode(aCharset, aAddrTo, &outCString))) {
if (NS_SUCCEEDED(ConvertFromUnicode(aCharset, aAddrTo, &outCString)))
{
mMsgCompFields->SetTo(outCString, NULL);
PR_Free(outCString);
}
else {
mMsgCompFields->SetTo(aAddrTo.ToNewCString(), NULL);
else
{
char* cAddrTo = aAddrTo.ToNewCString();
mMsgCompFields->SetTo(cAddrTo, NULL);
delete[] cAddrTo;
}
if (NS_SUCCEEDED(ConvertFromUnicode(aCharset, aAddrCc, &outCString))) {
if (NS_SUCCEEDED(ConvertFromUnicode(aCharset, aAddrCc, &outCString)))
{
mMsgCompFields->SetCc(outCString, NULL);
PR_Free(outCString);
}
else {
mMsgCompFields->SetCc(aAddrCc.ToNewCString(), NULL);
else
{
char* cAddrCc = aAddrCc.ToNewCString();
mMsgCompFields->SetCc(cAddrCc, NULL);
delete[] cAddrCc;
}
if (NS_SUCCEEDED(ConvertFromUnicode(aCharset, aAddrBcc, &outCString))) {
if (NS_SUCCEEDED(ConvertFromUnicode(aCharset, aAddrBcc, &outCString)))
{
mMsgCompFields->SetBcc(outCString, NULL);
PR_Free(outCString);
}
else {
mMsgCompFields->SetBcc(aAddrBcc.ToNewCString(), NULL);
else
{
char* cAddrBcc = aAddrBcc.ToNewCString();
mMsgCompFields->SetBcc(cAddrBcc, NULL);
delete[] cAddrBcc;
}
if (NS_SUCCEEDED(ConvertFromUnicode(aCharset, aSubject, &outCString))) {
if (NS_SUCCEEDED(ConvertFromUnicode(aCharset, aSubject, &outCString)))
{
mMsgCompFields->SetSubject(outCString, NULL);
PR_Free(outCString);
}
else {
mMsgCompFields->SetSubject(aSubject.ToNewCString(), NULL);
else
{
char* cSubject = aSubject.ToNewCString();
mMsgCompFields->SetSubject(cSubject, NULL);
delete[] cSubject;
}
// Convert body to mail charset not to utf-8 (because we don't manipulate body text)
char *mail_charset;
mMsgCompFields->GetCharacterSet(&mail_charset);
aCharset.SetString(mail_charset);
if (NS_SUCCEEDED(ConvertFromUnicode(aCharset, aMsg, &outCString))) {
if (NS_SUCCEEDED(ConvertFromUnicode(aCharset, aMsg, &outCString)))
{
mMsgCompFields->SetBody(outCString, NULL);
PR_Free(outCString);
}
else {
mMsgCompFields->SetBody(aMsg.ToNewCString(), NULL);
else
{
char* cMsg = aMsg.ToNewCString();
mMsgCompFields->SetBody(cMsg, NULL);
delete[] cMsg;
}
if (mMsgSend)