зеркало из https://github.com/mozilla/gecko-dev.git
use the new EventQueueService to obtain the event queue used for marshalling data over to the UI thread...
This commit is contained in:
Родитель
4ac04e8dae
Коммит
6037b8f2c5
|
@ -43,6 +43,8 @@ extern "C" {
|
||||||
#include "nsIProtocolURLFactory.h"
|
#include "nsIProtocolURLFactory.h"
|
||||||
#include "nsIProtocol.h"
|
#include "nsIProtocol.h"
|
||||||
#include "nsIServiceManager.h"
|
#include "nsIServiceManager.h"
|
||||||
|
#include "nsIEventQueueService.h"
|
||||||
|
#include "nsXPComCIID.h"
|
||||||
#include "nsCRT.h"
|
#include "nsCRT.h"
|
||||||
|
|
||||||
#ifdef XP_PC
|
#ifdef XP_PC
|
||||||
|
@ -99,7 +101,7 @@ nsresult PerformNastyWindowsAsyncDNSHack(URL_Struct* URL_s, nsIURL* aURL);
|
||||||
#endif /* XP_WIN && !NETLIB_THREAD */
|
#endif /* XP_WIN && !NETLIB_THREAD */
|
||||||
|
|
||||||
char *mangleResourceIntoFileURL(const char* aResourceFileName) ;
|
char *mangleResourceIntoFileURL(const char* aResourceFileName) ;
|
||||||
extern nsIStreamListener* ns_NewStreamListenerProxy(nsIStreamListener* aListener);
|
extern nsIStreamListener* ns_NewStreamListenerProxy(nsIStreamListener* aListener, PLEventQueue* aEventQ);
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#if defined(XP_WIN) || defined(XP_OS2)
|
#if defined(XP_WIN) || defined(XP_OS2)
|
||||||
|
@ -119,12 +121,24 @@ extern const char *XP_AppPlatform;
|
||||||
} /* end of extern "C" */
|
} /* end of extern "C" */
|
||||||
|
|
||||||
static NS_DEFINE_IID(kINetlibURLIID, NS_INETLIBURL_IID);
|
static NS_DEFINE_IID(kINetlibURLIID, NS_INETLIBURL_IID);
|
||||||
|
static NS_DEFINE_IID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID);
|
||||||
|
static NS_DEFINE_IID(kIEventQueueServiceIID, NS_IEVENTQUEUESERVICE_IID);
|
||||||
|
|
||||||
|
|
||||||
nsNetlibService::nsNetlibService()
|
nsNetlibService::nsNetlibService()
|
||||||
{
|
{
|
||||||
|
nsresult rv;
|
||||||
|
|
||||||
NS_INIT_REFCNT();
|
NS_INIT_REFCNT();
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Cache the EventQueueService...
|
||||||
|
*/
|
||||||
|
// XXX: What if this fails?
|
||||||
|
rv = nsServiceManager::GetService(kEventQueueServiceCID,
|
||||||
|
kIEventQueueServiceIID,
|
||||||
|
(nsISupports **)&mEventQService);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
m_stubContext = new_stub_context();
|
m_stubContext = new_stub_context();
|
||||||
*/
|
*/
|
||||||
|
@ -217,6 +231,11 @@ nsNetlibService::~nsNetlibService()
|
||||||
delete mNetlibThread;
|
delete mNetlibThread;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (nsnull != mEventQService) {
|
||||||
|
nsServiceManager::ReleaseService(kEventQueueServiceCID, mEventQService);
|
||||||
|
mEventQService = nsnull;
|
||||||
|
}
|
||||||
|
|
||||||
delete mProtocols;
|
delete mProtocols;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -295,13 +314,19 @@ nsresult nsNetlibService::OpenStream(nsIURL *aUrl,
|
||||||
nsINetlibURL *netlibURL;
|
nsINetlibURL *netlibURL;
|
||||||
nsresult result;
|
nsresult result;
|
||||||
nsIStreamListener* consumer;
|
nsIStreamListener* consumer;
|
||||||
|
PLEventQueue* evQueue = nsnull;
|
||||||
|
|
||||||
if ((NULL == aConsumer) || (NULL == aUrl)) {
|
if ((NULL == aConsumer) || (NULL == aUrl)) {
|
||||||
return NS_FALSE;
|
return NS_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(NETLIB_THREAD)
|
#if defined(NETLIB_THREAD)
|
||||||
consumer = ns_NewStreamListenerProxy(aConsumer);
|
mEventQService->GetThreadEventQueue(PR_GetCurrentThread(), &evQueue);
|
||||||
|
if (nsnull == evQueue) {
|
||||||
|
return NS_FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
consumer = ns_NewStreamListenerProxy(aConsumer, evQueue);
|
||||||
if (nsnull == consumer) {
|
if (nsnull == consumer) {
|
||||||
return NS_FALSE;
|
return NS_FALSE;
|
||||||
}
|
}
|
||||||
|
@ -355,6 +380,15 @@ nsresult nsNetlibService::OpenStream(nsIURL *aUrl,
|
||||||
*/
|
*/
|
||||||
URL_s->fe_data = pConn;
|
URL_s->fe_data = pConn;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Attach the Event Queue to use when proxying data back to the thread
|
||||||
|
* which initiated the URL load...
|
||||||
|
*
|
||||||
|
* Currently, this information is needed to marshall the call to the URL
|
||||||
|
* exit_routine(...) on the correct thread...
|
||||||
|
*/
|
||||||
|
URL_s->owner_data = evQueue;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Give the protocol a chance to initialize any URL_Struct fields...
|
* Give the protocol a chance to initialize any URL_Struct fields...
|
||||||
*
|
*
|
||||||
|
@ -402,6 +436,7 @@ nsresult nsNetlibService::OpenBlockingStream(nsIURL *aUrl,
|
||||||
nsNetlibStream *pBlockingStream;
|
nsNetlibStream *pBlockingStream;
|
||||||
nsINetlibURL *netlibURL;
|
nsINetlibURL *netlibURL;
|
||||||
nsIStreamListener* consumer = nsnull;
|
nsIStreamListener* consumer = nsnull;
|
||||||
|
PLEventQueue* evQueue = nsnull;
|
||||||
nsresult result;
|
nsresult result;
|
||||||
|
|
||||||
if (NULL == aNewStream) {
|
if (NULL == aNewStream) {
|
||||||
|
@ -410,8 +445,13 @@ nsresult nsNetlibService::OpenBlockingStream(nsIURL *aUrl,
|
||||||
|
|
||||||
if (NULL != aUrl) {
|
if (NULL != aUrl) {
|
||||||
#if defined(NETLIB_THREAD)
|
#if defined(NETLIB_THREAD)
|
||||||
|
mEventQService->GetThreadEventQueue(PR_GetCurrentThread(), &evQueue);
|
||||||
|
if (nsnull == evQueue) {
|
||||||
|
goto loser;
|
||||||
|
}
|
||||||
|
|
||||||
if (nsnull != aConsumer) {
|
if (nsnull != aConsumer) {
|
||||||
consumer = ns_NewStreamListenerProxy(aConsumer);
|
consumer = ns_NewStreamListenerProxy(aConsumer, evQueue);
|
||||||
if (nsnull == consumer) {
|
if (nsnull == consumer) {
|
||||||
goto loser;
|
goto loser;
|
||||||
}
|
}
|
||||||
|
@ -495,6 +535,15 @@ nsresult nsNetlibService::OpenBlockingStream(nsIURL *aUrl,
|
||||||
*/
|
*/
|
||||||
URL_s->fe_data = pConn;
|
URL_s->fe_data = pConn;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Attach the Event Queue to use when proxying data back to the thread
|
||||||
|
* which initiated the URL load...
|
||||||
|
*
|
||||||
|
* Currently, this information is needed to marshall the call to the URL
|
||||||
|
* exit_routine(...) on the correct thread...
|
||||||
|
*/
|
||||||
|
URL_s->owner_data = evQueue;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Give the protocol a chance to initialize any URL_Struct fields...
|
* Give the protocol a chance to initialize any URL_Struct fields...
|
||||||
*
|
*
|
||||||
|
|
|
@ -21,8 +21,8 @@
|
||||||
#define nsNetService_h___
|
#define nsNetService_h___
|
||||||
|
|
||||||
#include "nspr.h"
|
#include "nspr.h"
|
||||||
#include "plevent.h"
|
|
||||||
#include "nsIPref.h"
|
#include "nsIPref.h"
|
||||||
|
#include "nsIEventQueueService.h"
|
||||||
#include "nsINetService.h"
|
#include "nsINetService.h"
|
||||||
#include "nsNetThread.h"
|
#include "nsNetThread.h"
|
||||||
#include "nsHashtable.h"
|
#include "nsHashtable.h"
|
||||||
|
@ -119,6 +119,7 @@ private:
|
||||||
nsITimer* mPollingTimer;
|
nsITimer* mPollingTimer;
|
||||||
|
|
||||||
nsNetlibThread* mNetlibThread;
|
nsNetlibThread* mNetlibThread;
|
||||||
|
nsIEventQueueService* mEventQService;
|
||||||
|
|
||||||
nsHashtable* mProtocols;
|
nsHashtable* mProtocols;
|
||||||
};
|
};
|
||||||
|
|
|
@ -312,7 +312,7 @@ void nsNetlibThread::NetlibMainLoop()
|
||||||
class nsStreamListenerProxy : public nsIStreamListener
|
class nsStreamListenerProxy : public nsIStreamListener
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
nsStreamListenerProxy(nsIStreamListener* aListener);
|
nsStreamListenerProxy(nsIStreamListener* aListener, PLEventQueue* aEventQ);
|
||||||
|
|
||||||
NS_DECL_ISUPPORTS
|
NS_DECL_ISUPPORTS
|
||||||
|
|
||||||
|
@ -334,6 +334,7 @@ protected:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
nsresult mStatus;
|
nsresult mStatus;
|
||||||
|
PLEventQueue* mEventQ;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -344,7 +345,7 @@ struct ProxyEvent : public PLEvent
|
||||||
virtual ~ProxyEvent();
|
virtual ~ProxyEvent();
|
||||||
virtual void InitEvent();
|
virtual void InitEvent();
|
||||||
NS_IMETHOD HandleEvent() = 0;
|
NS_IMETHOD HandleEvent() = 0;
|
||||||
void Fire(void);
|
void Fire(PLEventQueue* aEventQ);
|
||||||
|
|
||||||
static void PR_CALLBACK HandlePLEvent(PLEvent* aEvent);
|
static void PR_CALLBACK HandlePLEvent(PLEvent* aEvent);
|
||||||
static void PR_CALLBACK DestroyPLEvent(PLEvent* aEvent);
|
static void PR_CALLBACK DestroyPLEvent(PLEvent* aEvent);
|
||||||
|
@ -387,13 +388,14 @@ void PR_CALLBACK ProxyEvent::DestroyPLEvent(PLEvent* aEvent)
|
||||||
extern PLEventQueue* gWebShell_UnixEventQueue;
|
extern PLEventQueue* gWebShell_UnixEventQueue;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void ProxyEvent::Fire()
|
void ProxyEvent::Fire(PLEventQueue* aEventQ)
|
||||||
{
|
{
|
||||||
PLEventQueue* eventQueue;
|
PLEventQueue* eventQueue;
|
||||||
InitEvent();
|
InitEvent();
|
||||||
|
|
||||||
#if defined(XP_PC)
|
#if defined(XP_PC)
|
||||||
eventQueue = PL_GetMainEventQueue();
|
NS_PRECONDITION(nsnull != aEventQ, "PLEventQueue for thread is null");
|
||||||
|
eventQueue = aEventQ;
|
||||||
#elif defined(XP_UNIX)
|
#elif defined(XP_UNIX)
|
||||||
eventQueue = gWebShell_UnixEventQueue;
|
eventQueue = gWebShell_UnixEventQueue;
|
||||||
#endif
|
#endif
|
||||||
|
@ -615,13 +617,15 @@ OnDataAvailableProxyEvent::HandleEvent()
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
||||||
nsStreamListenerProxy::nsStreamListenerProxy(nsIStreamListener* aListener)
|
nsStreamListenerProxy::nsStreamListenerProxy(nsIStreamListener* aListener,
|
||||||
|
PLEventQueue* aEventQ)
|
||||||
{
|
{
|
||||||
NS_INIT_REFCNT();
|
NS_INIT_REFCNT();
|
||||||
|
|
||||||
mRealListener = aListener;
|
mRealListener = aListener;
|
||||||
NS_ADDREF(mRealListener);
|
NS_ADDREF(mRealListener);
|
||||||
|
|
||||||
|
mEventQ = aEventQ;
|
||||||
mStatus = NS_OK;
|
mStatus = NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -665,7 +669,7 @@ nsStreamListenerProxy::OnStartBinding(nsIURL* aURL, const char *aContentType)
|
||||||
if (nsnull == ev) {
|
if (nsnull == ev) {
|
||||||
rv = NS_ERROR_OUT_OF_MEMORY;
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
||||||
} else {
|
} else {
|
||||||
ev->Fire();
|
ev->Fire(mEventQ);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -689,7 +693,7 @@ nsStreamListenerProxy::OnProgress(nsIURL* aURL, PRUint32 aProgress,
|
||||||
if (nsnull == ev) {
|
if (nsnull == ev) {
|
||||||
rv = NS_ERROR_OUT_OF_MEMORY;
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
||||||
} else {
|
} else {
|
||||||
ev->Fire();
|
ev->Fire(mEventQ);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -712,7 +716,7 @@ nsStreamListenerProxy::OnStatus(nsIURL* aURL, const PRUnichar* aMsg)
|
||||||
if (nsnull == ev) {
|
if (nsnull == ev) {
|
||||||
rv = NS_ERROR_OUT_OF_MEMORY;
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
||||||
} else {
|
} else {
|
||||||
ev->Fire();
|
ev->Fire(mEventQ);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -736,7 +740,7 @@ nsStreamListenerProxy::OnStopBinding(nsIURL* aURL, nsresult aStatus,
|
||||||
if (nsnull == ev) {
|
if (nsnull == ev) {
|
||||||
rv = NS_ERROR_OUT_OF_MEMORY;
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
||||||
} else {
|
} else {
|
||||||
ev->Fire();
|
ev->Fire(mEventQ);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -776,7 +780,7 @@ nsStreamListenerProxy::OnDataAvailable(nsIURL* aURL, nsIInputStream *aIStream,
|
||||||
if (nsnull == ev) {
|
if (nsnull == ev) {
|
||||||
rv = NS_ERROR_OUT_OF_MEMORY;
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
||||||
} else {
|
} else {
|
||||||
ev->Fire();
|
ev->Fire(mEventQ);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -793,9 +797,10 @@ nsStreamListenerProxy::~nsStreamListenerProxy()
|
||||||
NS_RELEASE(mRealListener);
|
NS_RELEASE(mRealListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
nsIStreamListener* ns_NewStreamListenerProxy(nsIStreamListener* aListener)
|
nsIStreamListener* ns_NewStreamListenerProxy(nsIStreamListener* aListener,
|
||||||
|
PLEventQueue* aEventQ)
|
||||||
{
|
{
|
||||||
return new nsStreamListenerProxy(aListener);
|
return new nsStreamListenerProxy(aListener, aEventQ);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -866,6 +871,11 @@ net_CallExitRoutineProxy(Net_GetUrlExitFunc* exit_routine,
|
||||||
{
|
{
|
||||||
CallExitRoutineProxyEvent* ev;
|
CallExitRoutineProxyEvent* ev;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Make sure that the URL_Struct was opened by the nsINetService...
|
||||||
|
* Otherwise, we cannot look at the URL_s->owner_data
|
||||||
|
*/
|
||||||
|
if (NULL != window_id->modular_data) {
|
||||||
/*
|
/*
|
||||||
* Always use a PLEvent to call the exit_routine(...). This is necessary
|
* Always use a PLEvent to call the exit_routine(...). This is necessary
|
||||||
* because when a connection is interrupted, the exit_routine(...) is called
|
* because when a connection is interrupted, the exit_routine(...) is called
|
||||||
|
@ -877,6 +887,9 @@ net_CallExitRoutineProxy(Net_GetUrlExitFunc* exit_routine,
|
||||||
ev = new CallExitRoutineProxyEvent(exit_routine, URL_s, status,
|
ev = new CallExitRoutineProxyEvent(exit_routine, URL_s, status,
|
||||||
format_out, window_id);
|
format_out, window_id);
|
||||||
if (nsnull != ev) {
|
if (nsnull != ev) {
|
||||||
ev->Fire();
|
ev->Fire((PLEventQueue*)URL_s->owner_data);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
net_CallExitRoutine(exit_routine, URL_s, status, format_out, window_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче