зеркало из https://github.com/mozilla/pjs.git
Fixing bug 387712 Add a helper function to nsIMessenger to allow easy listening to attachment saving. r/sr=bienvenu. Tbird trunk only.
This commit is contained in:
Родитель
9811e30102
Коммит
476d84b9c3
|
@ -47,8 +47,10 @@ interface nsIMsgDBHdr;
|
|||
interface nsIDOMWindowInternal;
|
||||
interface nsITransactionManager;
|
||||
interface nsIMsgMessageService;
|
||||
interface nsIFile;
|
||||
interface nsIUrlListener;
|
||||
|
||||
[scriptable, uuid(3CFFB7E3-D7C6-4335-8941-7B94BBAFB607)]
|
||||
[scriptable, uuid(BE8C45B1-F810-4B7E-BB44-790B53631D52)]
|
||||
interface nsIMessenger : nsISupports {
|
||||
|
||||
const long eUnknown = 0;
|
||||
|
@ -107,6 +109,10 @@ interface nsIMessenger : nsISupports {
|
|||
void saveAllAttachments(in unsigned long count, [array, size_is(count)] in string contentTypeArray,
|
||||
[array, size_is(count)] in string urlArray, [array, size_is(count)] in string displayNameArray,
|
||||
[array, size_is(count)] in string messageUriArray);
|
||||
|
||||
void saveAttachmentToFile(in nsIFile aFile, in ACString aUrl, in ACString aMessageUri,
|
||||
in ACString aContentType, in nsIUrlListener aListener);
|
||||
|
||||
void detachAttachment(in string contentTpe, in string url, in string displayName, in string messageUri, in boolean saveFirst);
|
||||
void detachAllAttachments(in unsigned long count, [array, size_is(count)] in string contentTypeArray,
|
||||
[array, size_is(count)] in string urlArray, [array, size_is(count)] in string displayNameArray,
|
||||
|
|
|
@ -238,7 +238,7 @@ class nsSaveMsgListener : public nsIUrlListener,
|
|||
public nsICancelable
|
||||
{
|
||||
public:
|
||||
nsSaveMsgListener(nsIFile* file, nsMessenger* aMessenger);
|
||||
nsSaveMsgListener(nsIFile *file, nsMessenger *aMessenger, nsIUrlListener *aListener);
|
||||
virtual ~nsSaveMsgListener();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
@ -270,6 +270,7 @@ public:
|
|||
nsCString m_contentType; // used only when saving attachment
|
||||
|
||||
nsCOMPtr<nsITransfer> mTransfer;
|
||||
nsCOMPtr<nsIUrlListener> mListener;
|
||||
PRInt32 mProgress;
|
||||
PRInt32 mContentLength;
|
||||
PRBool mCanceled;
|
||||
|
@ -680,12 +681,21 @@ nsMessenger::LoadURL(nsIDOMWindowInternal *aWin, const nsACString& aURL)
|
|||
return mDocShell->LoadURI(uri, loadInfo, 0, PR_TRUE);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsMessenger::SaveAttachment(nsIFile * aFile,
|
||||
NS_IMETHODIMP nsMessenger::SaveAttachmentToFile(nsIFile *aFile,
|
||||
const nsACString &aURL,
|
||||
const nsACString &aMessageUri,
|
||||
const nsACString &aContentType,
|
||||
void *closure)
|
||||
nsIUrlListener *aListener)
|
||||
{
|
||||
return SaveAttachment(aFile, aURL, aMessageUri, aContentType, nsnull, aListener);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMessenger::SaveAttachment(nsIFile *aFile,
|
||||
const nsACString &aURL,
|
||||
const nsACString &aMessageUri,
|
||||
const nsACString &aContentType,
|
||||
void *closure,
|
||||
nsIUrlListener *aListener)
|
||||
{
|
||||
nsIMsgMessageService * messageService = nsnull;
|
||||
nsSaveAllAttachmentsState *saveState= (nsSaveAllAttachmentsState*) closure;
|
||||
|
@ -697,7 +707,7 @@ nsMessenger::SaveAttachment(nsIFile * aFile,
|
|||
// XXX todo
|
||||
// document the ownership model of saveListener
|
||||
// whacky ref counting here...what's the deal? when does saveListener get released? it's not clear.
|
||||
nsSaveMsgListener *saveListener = new nsSaveMsgListener(aFile, this);
|
||||
nsSaveMsgListener *saveListener = new nsSaveMsgListener(aFile, this, aListener);
|
||||
if (!saveListener)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
|
@ -828,7 +838,7 @@ nsMessenger::SaveAttachmentToFolder(const nsACString& contentType, const nsACStr
|
|||
rv = attachmentDestination->AppendNative(unescapedFileName);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = SaveAttachment(attachmentDestination, url, messageUri, contentType, nsnull);
|
||||
rv = SaveAttachment(attachmentDestination, url, messageUri, contentType, nsnull, nsnull);
|
||||
attachmentDestination.swap(*aOutFile);
|
||||
return rv;
|
||||
}
|
||||
|
@ -875,7 +885,7 @@ nsMessenger::SaveAttachment(const nsACString& aContentType, const nsACString& aU
|
|||
|
||||
SetLastSaveDirectory(localFile);
|
||||
|
||||
rv = SaveAttachment(localFile, aURL, aMessageUri, aContentType, nsnull);
|
||||
rv = SaveAttachment(localFile, aURL, aMessageUri, aContentType, nsnull, nsnull);
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
@ -948,7 +958,7 @@ nsMessenger::SaveAllAttachments(PRUint32 count,
|
|||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
rv = SaveAttachment(localFile, nsDependentCString(urlArray[0]), nsDependentCString(messageUriArray[0]),
|
||||
nsDependentCString(contentTypeArray[0]), (void *)saveState);
|
||||
nsDependentCString(contentTypeArray[0]), (void *)saveState, nsnull);
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
@ -1108,7 +1118,7 @@ nsMessenger::SaveAs(const nsACString& aURI, PRBool aAsFile, nsIMsgIdentity *aIde
|
|||
|
||||
// XXX todo
|
||||
// document the ownership model of saveListener
|
||||
saveListener = new nsSaveMsgListener(localFile, this);
|
||||
saveListener = new nsSaveMsgListener(localFile, this, nsnull);
|
||||
if (!saveListener) {
|
||||
rv = NS_ERROR_OUT_OF_MEMORY;
|
||||
goto done;
|
||||
|
@ -1197,7 +1207,7 @@ nsMessenger::SaveAs(const nsACString& aURI, PRBool aAsFile, nsIMsgIdentity *aIde
|
|||
|
||||
// XXX todo
|
||||
// document the ownership model of saveListener
|
||||
saveListener = new nsSaveMsgListener(tmpFile, this);
|
||||
saveListener = new nsSaveMsgListener(tmpFile, this, nsnull);
|
||||
if (!saveListener) {
|
||||
rv = NS_ERROR_OUT_OF_MEMORY;
|
||||
goto done;
|
||||
|
@ -1710,10 +1720,11 @@ nsMessenger::SendUnsentMessages(nsIMsgIdentity *aIdentity, nsIMsgWindow *aMsgWin
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
nsSaveMsgListener::nsSaveMsgListener(nsIFile* aFile, nsMessenger *aMessenger)
|
||||
nsSaveMsgListener::nsSaveMsgListener(nsIFile* aFile, nsMessenger *aMessenger, nsIUrlListener *aListener)
|
||||
{
|
||||
m_file = do_QueryInterface(aFile);
|
||||
m_messenger = aMessenger;
|
||||
mListener = aListener;
|
||||
|
||||
// rhp: for charset handling
|
||||
m_doCharsetConversion = PR_FALSE;
|
||||
|
@ -1751,6 +1762,7 @@ nsSaveMsgListener::Cancel(nsresult status)
|
|||
NS_IMETHODIMP
|
||||
nsSaveMsgListener::OnStartRunningUrl(nsIURI* url)
|
||||
{
|
||||
mListener->OnStartRunningUrl(url);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -1793,6 +1805,7 @@ done:
|
|||
if (killSelf)
|
||||
Release(); // no more work needs to be done; kill ourself
|
||||
|
||||
mListener->OnStopRunningUrl(url, exitCode);
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
@ -1923,7 +1936,6 @@ nsSaveMsgListener::OnStartRequest(nsIRequest* request, nsISupports* aSupport)
|
|||
if (m_messenger)
|
||||
m_messenger->Alert("saveAttachmentFailed");
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -1974,8 +1986,7 @@ nsSaveMsgListener::OnStopRequest(nsIRequest* request, nsISupports* aSupport,
|
|||
if (m_saveAllAttachmentsState)
|
||||
{
|
||||
m_saveAllAttachmentsState->m_curIndex++;
|
||||
if (!mCanceled && m_saveAllAttachmentsState->m_curIndex <
|
||||
m_saveAllAttachmentsState->m_count)
|
||||
if (!mCanceled && m_saveAllAttachmentsState->m_curIndex < m_saveAllAttachmentsState->m_count)
|
||||
{
|
||||
nsSaveAllAttachmentsState *state = m_saveAllAttachmentsState;
|
||||
PRUint32 i = state->m_curIndex;
|
||||
|
@ -1998,7 +2009,7 @@ nsSaveMsgListener::OnStopRequest(nsIRequest* request, nsISupports* aSupport,
|
|||
nsDependentCString(state->m_urlArray[i]),
|
||||
nsDependentCString(state->m_messageUriArray[i]),
|
||||
nsDependentCString(state->m_contentTypeArray[i]),
|
||||
(void *)state);
|
||||
(void *)state, nsnull);
|
||||
done:
|
||||
if (NS_FAILED(rv))
|
||||
{
|
||||
|
|
|
@ -63,9 +63,10 @@ public:
|
|||
NS_DECL_NSIFOLDERLISTENER
|
||||
|
||||
nsresult Alert(const char * stringName);
|
||||
|
||||
nsresult SaveAttachment(nsIFile *file, const nsACString& unescapedUrl,
|
||||
const nsACString& messageUri, const nsACString& contentType,
|
||||
void *closure);
|
||||
void *closure, nsIUrlListener *aListener);
|
||||
nsresult PromptIfFileExists(nsILocalFile *file);
|
||||
nsresult DetachAttachments(PRUint32 aCount,
|
||||
const char ** aContentTypeArray,
|
||||
|
|
Загрузка…
Ссылка в новой задаче