зеркало из https://github.com/mozilla/gecko-dev.git
Use the URILoader to load attachment urls when sending a reply to a message with attachments. this allows us to use the
stream converter logic in the uri loader. r=rhp
This commit is contained in:
Родитель
78e2bb3f76
Коммит
268927d21c
|
@ -458,7 +458,11 @@ nsMsgAttachmentHandler::SnarfMsgAttachment(nsMsgCompFields *compFields)
|
|||
rv = mFetcher->Initialize(mOutFile, FetcherURLDoneCallback, this);
|
||||
rv = GetMessageServiceFromURI(m_uri, &messageService);
|
||||
if (NS_SUCCEEDED(rv) && messageService)
|
||||
rv = messageService->DisplayMessage(m_uri, mFetcher, nsnull, nsnull, nsnull);
|
||||
{
|
||||
nsCOMPtr<nsIStreamListener> strListener;
|
||||
mFetcher->QueryInterface(NS_GET_IID(nsIStreamListener), getter_AddRefs(strListener));
|
||||
rv = messageService->DisplayMessage(m_uri, strListener, nsnull, nsnull, nsnull);
|
||||
}
|
||||
}
|
||||
done:
|
||||
if (NS_FAILED(rv))
|
||||
|
|
|
@ -60,9 +60,16 @@ nsresult NS_NewURLFetcher(nsURLFetcher ** aInstancePtrResult)
|
|||
return NS_ERROR_NULL_POINTER; // aInstancePtrResult was NULL....
|
||||
}
|
||||
|
||||
// The following macros actually implement addref, release and
|
||||
// query interface for our component.
|
||||
NS_IMPL_ISUPPORTS2(nsURLFetcher, nsIStreamListener, nsIStreamObserver);
|
||||
NS_IMPL_ADDREF(nsURLFetcher)
|
||||
NS_IMPL_RELEASE(nsURLFetcher)
|
||||
|
||||
NS_INTERFACE_MAP_BEGIN(nsURLFetcher)
|
||||
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIURIContentListener)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIStreamListener)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIStreamObserver)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIInterfaceRequestor)
|
||||
NS_INTERFACE_MAP_ENTRY(nsIURIContentListener)
|
||||
NS_INTERFACE_MAP_END
|
||||
|
||||
/*
|
||||
* Inherited methods for nsMimeConverter
|
||||
|
@ -86,6 +93,52 @@ nsURLFetcher::~nsURLFetcher()
|
|||
PR_FREEIF(mContentType);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsURLFetcher::GetInterface(const nsIID & aIID, void * *aInstancePtr)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aInstancePtr);
|
||||
return QueryInterface(aIID, aInstancePtr);
|
||||
}
|
||||
|
||||
// nsIURIContentListener support
|
||||
NS_IMETHODIMP
|
||||
nsURLFetcher::GetProtocolHandler(nsIURI *aURI, nsIProtocolHandler **aProtocolHandler)
|
||||
{
|
||||
*aProtocolHandler = nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsURLFetcher::CanHandleContent(const char * aContentType,
|
||||
nsURILoadCommand aCommand,
|
||||
const char * aWindowTarget,
|
||||
char ** aDesiredContentType,
|
||||
PRBool * aCanHandleContent)
|
||||
|
||||
{
|
||||
if (nsCRT::strcasecmp(aContentType, "message/rfc822") == 0)
|
||||
*aDesiredContentType = nsCRT::strdup("text/html");
|
||||
|
||||
// since we explicilty loaded the url, we always want to handle it!
|
||||
*aCanHandleContent = PR_TRUE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsURLFetcher::DoContent(const char * aContentType,
|
||||
nsURILoadCommand aCommand,
|
||||
const char * aWindowTarget,
|
||||
nsIChannel * aOpenedChannel,
|
||||
nsIStreamListener ** aContentHandler,
|
||||
PRBool * aAbortProcess)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
if (aAbortProcess)
|
||||
*aAbortProcess = PR_FALSE;
|
||||
QueryInterface(NS_GET_IID(nsIStreamListener), (void **) aContentHandler);
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsURLFetcher::StillRunning(PRBool *running)
|
||||
{
|
||||
|
@ -207,21 +260,18 @@ nsURLFetcher::FireURLRequest(nsIURI *aURL, nsOutputFileStream *fOut,
|
|||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_WITH_SERVICE(nsIIOService, service, kIOServiceCID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIChannel> channel;
|
||||
rv = service->NewChannelFromURI("load", aURL,
|
||||
nsnull, // loadGroup
|
||||
nsnull, // notificationCallbacks
|
||||
nsIChannel::LOAD_NORMAL,
|
||||
nsnull, // originalURI
|
||||
0, 0,
|
||||
getter_AddRefs(channel));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = channel->AsyncRead(0, -1, nsnull, this);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
// let's try uri dispatching...
|
||||
NS_WITH_SERVICE(nsIURILoader, pURILoader, NS_URI_LOADER_PROGID, &rv);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
{
|
||||
nsCOMPtr<nsISupports> openContext;
|
||||
nsCOMPtr<nsISupports> cntListener (do_QueryInterface(NS_STATIC_CAST(nsIStreamListener *, this)));
|
||||
rv = pURILoader->OpenURI(aURL, nsIURILoader::viewNormal, nsnull /* window target */,
|
||||
cntListener,
|
||||
nsnull /* refferring URI */,
|
||||
/* group */ nsnull,
|
||||
getter_AddRefs(openContext));
|
||||
}
|
||||
|
||||
mURL = dont_QueryInterface(aURL);
|
||||
mOutStream = fOut;
|
||||
|
|
|
@ -27,6 +27,10 @@
|
|||
#include "nsIStreamListener.h"
|
||||
#include "nsFileStream.h"
|
||||
|
||||
#include "nsIInterfaceRequestor.h"
|
||||
#include "nsCURILoader.h"
|
||||
#include "nsIURIContentListener.h"
|
||||
|
||||
//
|
||||
// Callback declarations for URL completion
|
||||
//
|
||||
|
@ -36,7 +40,7 @@ typedef nsresult (*nsAttachSaveCompletionCallback) (nsIURI* aURL, nsresult aStat
|
|||
PRInt32 totalSize, const PRUnichar* aMsg,
|
||||
void *tagData);
|
||||
|
||||
class nsURLFetcher : public nsIStreamListener {
|
||||
class nsURLFetcher : public nsIStreamListener, public nsIURIContentListener, public nsIInterfaceRequestor {
|
||||
public:
|
||||
nsURLFetcher();
|
||||
virtual ~nsURLFetcher();
|
||||
|
@ -59,9 +63,10 @@ public:
|
|||
|
||||
// Methods for nsIStreamListener
|
||||
NS_DECL_NSISTREAMLISTENER
|
||||
|
||||
// Methods for nsIStreamObserver
|
||||
NS_DECL_NSISTREAMOBSERVER
|
||||
NS_DECL_NSIURICONTENTLISTENER
|
||||
NS_DECL_NSIINTERFACEREQUESTOR
|
||||
|
||||
private:
|
||||
nsOutputFileStream *mOutStream; // the output file stream
|
||||
|
|
Загрузка…
Ссылка в новой задаче