зеркало из https://github.com/mozilla/gecko-dev.git
nsIHTTPConnection.h - extended the nsIHTTPConnection interface so the internal streamlistener is accessible.
nsHTTPConnection.cpp - GetInputStream now uses a syncStream listener. nsHTTPConnection.h - api update to support new nsIHTTPConnection interface and added nsIStreamListener member. nsHTTPResponseListener.cpp - added code to push data through the pipe
This commit is contained in:
Родитель
ee93afddb8
Коммит
9da8d67122
|
@ -21,6 +21,8 @@
|
|||
|
||||
#include "nsIProtocolConnection.h"
|
||||
#include "nsHTTPEnums.h"
|
||||
#include "nsIStreamListener.h"
|
||||
|
||||
class nsIHTTPEventSink;
|
||||
/*
|
||||
The nsIHTTPConnection class is the interface to an intance
|
||||
|
@ -68,6 +70,8 @@ public:
|
|||
return NS_IHTTPConnection_IID;
|
||||
};
|
||||
|
||||
NS_IMETHOD GetResponseDataListener(nsIStreamListener* *aListener) = 0;
|
||||
|
||||
};
|
||||
|
||||
//Possible errors
|
||||
|
|
|
@ -36,7 +36,8 @@ nsHTTPConnection::nsHTTPConnection(
|
|||
m_pHandler(dont_QueryInterface(i_Handler)),
|
||||
m_pEventSink(dont_QueryInterface(i_HTTPEventSink)),
|
||||
m_pResponse(nsnull),
|
||||
m_pEventQ(dont_QueryInterface(i_EQ))
|
||||
m_pEventQ(dont_QueryInterface(i_EQ)),
|
||||
m_pResponseDataListener(nsnull)
|
||||
|
||||
{
|
||||
//TODO think if we need to make a copy of the URL and keep it here
|
||||
|
@ -67,6 +68,8 @@ nsHTTPConnection::~nsHTTPConnection()
|
|||
delete m_pResponse;
|
||||
m_pResponse = 0;
|
||||
}
|
||||
|
||||
NS_IF_RELEASE(m_pResponseDataListener);
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(nsHTTPConnection);
|
||||
|
@ -92,12 +95,26 @@ nsHTTPConnection::Resume(void)
|
|||
NS_METHOD
|
||||
nsHTTPConnection::GetInputStream(nsIInputStream* *o_Stream)
|
||||
{
|
||||
#if 0
|
||||
nsresult rv;
|
||||
|
||||
if (!m_bConnected)
|
||||
Open();
|
||||
|
||||
nsIInputStream* inStr; // this guy gets passed out to the user
|
||||
rv = NS_NewSyncStreamListener(&m_pResponseDataListener, &inStr);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
*o_Stream = inStr;
|
||||
return NS_OK;
|
||||
|
||||
#else
|
||||
|
||||
if (m_pResponse)
|
||||
return m_pResponse->GetInputStream(o_Stream);
|
||||
NS_ERROR("No response!");
|
||||
return NS_OK; // change to error ? or block till response is set up?
|
||||
#endif // if 0
|
||||
|
||||
}
|
||||
|
||||
|
@ -212,7 +229,7 @@ nsHTTPConnection::Open(void)
|
|||
#endif // jud
|
||||
|
||||
rv = m_pHandler->GetTransport(host, unsignedPort, &temp);
|
||||
if (temp)
|
||||
if (NS_SUCCEEDED(rv) && temp)
|
||||
{
|
||||
m_pRequest->SetTransport(temp);
|
||||
|
||||
|
@ -291,3 +308,13 @@ nsHTTPConnection::GetURL(nsIURL* *o_URL) const
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsHTTPConnection::GetResponseDataListener(nsIStreamListener* *aListener)
|
||||
{
|
||||
if (m_pResponseDataListener) {
|
||||
*aListener = m_pResponseDataListener;
|
||||
NS_ADDREF(m_pResponseDataListener);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -99,6 +99,9 @@ public:
|
|||
|
||||
NS_IMETHOD SetResponse(nsHTTPResponse* i_pResp) { if (i_pResp) m_pResponse = i_pResp; return NS_OK;};
|
||||
|
||||
NS_IMETHOD GetResponseDataListener(nsIStreamListener* *aListener);
|
||||
|
||||
|
||||
private:
|
||||
nsCOMPtr<nsIURL> m_pURL;
|
||||
PRBool m_bConnected;
|
||||
|
@ -108,6 +111,8 @@ private:
|
|||
nsCOMPtr<nsIHTTPEventSink> m_pEventSink;
|
||||
nsHTTPRequest* m_pRequest;
|
||||
nsHTTPResponse* m_pResponse;
|
||||
|
||||
nsIStreamListener* m_pResponseDataListener;
|
||||
};
|
||||
|
||||
#endif /* _nsHTTPConnection_h_ */
|
||||
|
|
|
@ -55,16 +55,7 @@ nsHTTPResponseListener::OnDataAvailable(nsISupports* context,
|
|||
PRUint32 i_SourceOffset,
|
||||
PRUint32 i_Length)
|
||||
{
|
||||
// we should probably construct the stream only when we get the data...
|
||||
// but for now...
|
||||
nsIStreamListener* syncListener;
|
||||
nsIInputStream* inStr;
|
||||
|
||||
/* Jud... getting some unresolved stuff here... noticed that
|
||||
nsSyncStreamListener isn't being exported!?! */
|
||||
//nsresult rv = NS_NewSyncStreamListener(&syncListener, &inStr);
|
||||
//if (NS_FAILED(rv))
|
||||
// return rv;
|
||||
nsIInputStream* inStr = nsnull;
|
||||
|
||||
// Should I save this as a member variable? yes... todo
|
||||
nsIHTTPEventSink* pSink= nsnull;
|
||||
|
@ -179,8 +170,21 @@ nsHTTPResponseListener::OnDataAvailable(nsISupports* context,
|
|||
|
||||
if (bHeadersDone)
|
||||
{
|
||||
// TODO push extrabuffer up the stream too.. How? JUD?
|
||||
nsresult rv;
|
||||
nsIStreamListener* internalListener = nsnull;
|
||||
|
||||
// Get our end of the pipe between us and the user's GetInputStream()
|
||||
rv = m_pConnection->GetResponseDataListener(&internalListener);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
// post the data to the stream listener
|
||||
// XXX this is the wrong data and offsets I think.
|
||||
rv = internalListener->OnDataAvailable(context, i_pStream, i_SourceOffset, i_Length);
|
||||
NS_RELEASE(internalListener);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
}
|
||||
|
||||
// do whatever we want for the event sink
|
||||
return pSink->OnDataAvailable(context, inStr, i_SourceOffset, i_Length);
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче