Skip to content

Commit

Permalink
Http branch landing: changes to netwerk/ (bug 76866) r=gagan,sr=dougt…
Browse files Browse the repository at this point in the history
…,a=chofmann
  • Loading branch information
darin%netscape.com committed May 11, 2001
1 parent 8a508be commit 265c2b5
Show file tree
Hide file tree
Showing 68 changed files with 8,835 additions and 857 deletions.
4 changes: 2 additions & 2 deletions netwerk/base/public/nsIProtocolProxyService.idl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

#include "nsISupports.idl"
#include "nsIURI.idl"
#include "nsIProxy.idl"

%{C++
#define NS_PROTOCOLPROXYSERVICE_CID \
Expand All @@ -35,7 +34,8 @@ interface nsIProtocolProxyService : nsISupports
{
readonly attribute PRBool proxyEnabled;

void examineForProxy(in nsIURI aURI, in nsIProxy aProxy);
void examineForProxy(in nsIURI aURI, out string host, out long port, out string type);

/**
* Add additional items in the "No proxy for" list. This is above
* the list specified the user-pref.
Expand Down
8 changes: 2 additions & 6 deletions netwerk/base/public/nsIProxy.idl
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@
[scriptable, uuid(0492D011-CD2F-11d2-B013-006097BFC036)]
interface nsIProxy : nsISupports
{
attribute string proxyHost;

/* -1 on Set call indicates switch to default port */
attribute long proxyPort;

attribute string proxyType;

};

22 changes: 17 additions & 5 deletions netwerk/base/public/nsITransport.idl
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,21 @@ interface nsITransport : nsISupports
/**
* Get/set notificationCallbacks for this transport.
*/
readonly attribute nsIInterfaceRequestor notificationCallbacks;
nsIInterfaceRequestor getNotificationCallbacks();
void setNotificationCallbacks(in nsIInterfaceRequestor callbacks,
in boolean isBackground);
in unsigned long flags);

/**
* If the notificationCallbacks provide a nsIProgressEventSink
* implementation, then progress is by default reported to the thread
* that called setNotificationCallbacks. The following flags provide
* finer control over progress notifications:
*
* DONT_REPORT_PROGRESS - progress notifications are not sent.
* DONT_PROXY_PROGRESS - progress notifications can occur on any thread.
*/
const unsigned long DONT_REPORT_PROGRESS = 1;
const unsigned long DONT_PROXY_PROGRESS = 2;

/**
* Open an input stream on this transport.
Expand Down Expand Up @@ -104,9 +116,9 @@ interface nsITransport : nsISupports
* ask the transport to not proxy the callback. The caller must then
* be prepared to handle callbacks on any thread.
*/
const unsigned long DONT_PROXY_STREAM_OBSERVER = 1 << 0;
const unsigned long DONT_PROXY_STREAM_LISTENER = 1 << 1;
const unsigned long DONT_PROXY_STREAM_PROVIDER = 1 << 1;
const unsigned long DONT_PROXY_OBSERVER = 1 << 0;
const unsigned long DONT_PROXY_LISTENER = 1 << 1;
const unsigned long DONT_PROXY_PROVIDER = 1 << 1;

};

Expand Down
27 changes: 15 additions & 12 deletions netwerk/base/public/nsNetUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,14 @@
#include "nsITransport.h"
#include "nsMemory.h"
#include "nsCOMPtr.h"
#include "nsIHTTPProtocolHandler.h"
#include "nsIDownloader.h"
#include "nsIStreamLoader.h"
#include "nsIStreamIO.h"
#include "nsIPipe.h"
#include "nsIProtocolHandler.h"
#include "nsIStringStream.h"
#include "nsILocalFile.h"
#include "nsIFileStreams.h"
#include "nsXPIDLString.h"
#include "prio.h" // for read/write flags, permissions, etc.

Expand Down Expand Up @@ -221,22 +224,22 @@ NS_NewPostDataStream(nsIInputStream **result,
nsIIOService* ioService = nsnull) // pass in nsIIOService to optimize callers
{
nsresult rv;
nsCOMPtr<nsIIOService> serv;

if (ioService == nsnull) {
serv = do_GetIOService(&rv);
if (isFile) {
nsCOMPtr<nsILocalFile> file;

rv = NS_NewLocalFile(data, PR_FALSE, getter_AddRefs(file));
if (NS_FAILED(rv)) return rv;
ioService = serv.get();

return NS_NewLocalFileInputStream(result, file);
}

nsCOMPtr<nsIProtocolHandler> handler;
rv = ioService->GetProtocolHandler("http", getter_AddRefs(handler));
// otherwise, create a string stream for the data
nsCOMPtr<nsISupports> sup;
rv = NS_NewCStringInputStream(getter_AddRefs(sup), nsCAutoString(data));
if (NS_FAILED(rv)) return rv;

nsCOMPtr<nsIHTTPProtocolHandler> http = do_QueryInterface(handler, &rv);
if (NS_FAILED(rv)) return rv;

return http->NewPostDataStream(isFile, data, encodeFlags, result);
return CallQueryInterface(sup, result);
}

inline nsresult
Expand Down Expand Up @@ -583,7 +586,7 @@ NS_AsyncWriteFromStream(nsIRequest **aRequest,
//
// So, let's always make this optimization.
//
aFlags |= nsITransport::DONT_PROXY_STREAM_PROVIDER;
aFlags |= nsITransport::DONT_PROXY_PROVIDER;

return aTransport->AsyncWrite(provider, aContext,
aOffset,
Expand Down
52 changes: 31 additions & 21 deletions netwerk/base/src/nsFileTransport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -770,9 +770,9 @@ nsFileTransport::Process(void)
LOG(("nsFileTransport: READING [this=%x %s] read %u bytes [offset=%u]\n",
this, mStreamName.get(), total, mOffset));

if (mProgress)
mProgress->OnProgress(this, mContext, offset,
PR_MAX(mTotalAmount, 0));
if (mProgressSink)
mProgressSink->OnProgress(this, mContext, offset,
PR_MAX(mTotalAmount, 0));
}
break;
}
Expand Down Expand Up @@ -813,12 +813,12 @@ nsFileTransport::Process(void)
saveListener->OnStopRequest(this, saveContext, mStatus);
saveListener = 0;
}
if (mProgress) {
if (mProgressSink) {
nsAutoString fileName;
fileName.AssignWithConversion(mStreamName);
mProgress->OnStatus(this, saveContext,
NS_NET_STATUS_READ_FROM,
fileName.GetUnicode());
mProgressSink->OnStatus(this, saveContext,
NS_NET_STATUS_READ_FROM,
fileName.GetUnicode());
}

break;
Expand Down Expand Up @@ -947,9 +947,9 @@ nsFileTransport::Process(void)
LOG(("nsFileTransport: WRITING [this=%x %s] wrote %u bytes [offset=%u]\n",
this, mStreamName.get(), total, mOffset));

if (mProgress)
mProgress->OnProgress(this, mContext, offset,
PR_MAX(mTotalAmount, 0));
if (mProgressSink)
mProgressSink->OnProgress(this, mContext, offset,
PR_MAX(mTotalAmount, 0));
}
break;
}
Expand Down Expand Up @@ -980,10 +980,10 @@ nsFileTransport::Process(void)
mProvider->OnStopRequest(this, mContext, mStatus);
mProvider = 0;
}
if (mProgress) {
if (mProgressSink) {
nsAutoString fileName; fileName.AssignWithConversion(mStreamName);
nsresult rv = mProgress->OnStatus(this, mContext,
NS_NET_STATUS_WROTE_TO,
nsresult rv = mProgressSink->OnStatus(this, mContext,
NS_NET_STATUS_WROTE_TO,
fileName.GetUnicode());
NS_ASSERTION(NS_SUCCEEDED(rv), "unexpected OnStatus failure");
}
Expand Down Expand Up @@ -1037,33 +1037,43 @@ nsFileTransport::GetSecurityInfo(nsISupports * *aSecurityInfo)
}

NS_IMETHODIMP
nsFileTransport::GetNotificationCallbacks(nsIInterfaceRequestor** aCallbacks) {
nsFileTransport::GetNotificationCallbacks(nsIInterfaceRequestor **aCallbacks)
{
NS_ENSURE_ARG_POINTER(aCallbacks);
*aCallbacks = mNotificationCallbacks;
NS_IF_ADDREF(*aCallbacks);
return NS_OK;
}

NS_IMETHODIMP
nsFileTransport::SetNotificationCallbacks(nsIInterfaceRequestor* aCallbacks,
PRBool isBackground) {
nsFileTransport::SetNotificationCallbacks(nsIInterfaceRequestor *aCallbacks,
PRUint32 aFlags)
{
mNotificationCallbacks = aCallbacks;
mProgress = 0;
if (!mNotificationCallbacks || isBackground) return NS_OK;
mProgressSink = 0;

if (!mNotificationCallbacks || (aFlags & DONT_REPORT_PROGRESS))
return NS_OK;

nsCOMPtr<nsIProgressEventSink> sink(do_GetInterface(mNotificationCallbacks));
if (!sink) return NS_ERROR_FAILURE;
if (!sink) return NS_OK;

if (aFlags & DONT_PROXY_PROGRESS) {
mProgressSink = sink;
return NS_OK;
}

// Otherwise, generate a proxied event sink
nsresult rv;
NS_WITH_SERVICE(nsIProxyObjectManager,
proxyMgr, kProxyObjectManagerCID, &rv);
if (NS_FAILED(rv)) return rv;

return proxyMgr->GetProxyForObject(NS_UI_THREAD_EVENTQ, // primordial thread - should change?
return proxyMgr->GetProxyForObject(NS_CURRENT_EVENTQ, // calling thread
NS_GET_IID(nsIProgressEventSink),
sink,
PROXY_ASYNC | PROXY_ALWAYS,
getter_AddRefs(mProgress));
getter_AddRefs(mProgressSink));
}

////////////////////////////////////////////////////////////////////////////////
6 changes: 3 additions & 3 deletions netwerk/base/src/nsFileTransport.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class nsFileTransport : public nsITransport,
};

protected:
nsCOMPtr<nsIProgressEventSink> mProgress;
nsCOMPtr<nsIProgressEventSink> mProgressSink;
nsCOMPtr<nsIInterfaceRequestor> mNotificationCallbacks;
nsCOMPtr<nsIStreamIO> mStreamIO;
char *mContentType;
Expand Down Expand Up @@ -150,7 +150,7 @@ class nsFileTransport : public nsITransport,
#endif
};

#define NS_FILE_TRANSPORT_DEFAULT_SEGMENT_SIZE (2*1024)
#define NS_FILE_TRANSPORT_DEFAULT_BUFFER_SIZE (8*1024)
#define NS_FILE_TRANSPORT_DEFAULT_SEGMENT_SIZE (4096)
#define NS_FILE_TRANSPORT_DEFAULT_BUFFER_SIZE (4*4096) // 16k max

#endif // nsFileTransport_h__
54 changes: 37 additions & 17 deletions netwerk/base/src/nsIOService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,14 @@
#include "nsIErrorService.h"
#include "netCore.h"
#include "nsIObserverService.h"
#include "nsIHttpProtocolHandler.h"

static NS_DEFINE_CID(kFileTransportService, NS_FILETRANSPORTSERVICE_CID);
static NS_DEFINE_CID(kEventQueueService, NS_EVENTQUEUESERVICE_CID);
static NS_DEFINE_CID(kSocketTransportServiceCID, NS_SOCKETTRANSPORTSERVICE_CID);
static NS_DEFINE_CID(kDNSServiceCID, NS_DNSSERVICE_CID);
static NS_DEFINE_CID(kErrorServiceCID, NS_ERRORSERVICE_CID);
static NS_DEFINE_CID(kProtocolProxyServiceCID, NS_PROTOCOLPROXYSERVICE_CID);

////////////////////////////////////////////////////////////////////////////////

Expand Down Expand Up @@ -75,9 +77,16 @@ nsIOService::Init()
NS_GET_IID(nsIFileTransportService),
getter_AddRefs(mFileTransportService));
if (NS_FAILED(rv)) return rv;

rv = nsServiceManager::GetService(kDNSServiceCID,
NS_GET_IID(nsIDNSService),
getter_AddRefs(mDNSService));
if (NS_FAILED(rv)) return rv;

rv = nsServiceManager::GetService(kProtocolProxyServiceCID,
NS_GET_IID(nsIProtocolProxyService),
getter_AddRefs(mProxyService));
if (NS_FAILED(rv)) return rv;

// XXX hack until xpidl supports error info directly (http://bugzilla.mozilla.org/show_bug.cgi?id=13423)
nsCOMPtr<nsIErrorService> errorService = do_GetService(kErrorServiceCID, &rv);
Expand Down Expand Up @@ -254,8 +263,7 @@ nsIOService::ExtractScheme(const char* inURI, PRUint32 *startPos,
}

nsresult
nsIOService::NewURI(const char* aSpec, nsIURI* aBaseURI,
nsIURI* *result, nsIProtocolHandler* *hdlrResult)
nsIOService::NewURI(const char* aSpec, nsIURI* aBaseURI, nsIURI* *result)
{
nsresult rv;
nsIURI* base;
Expand All @@ -281,20 +289,9 @@ nsIOService::NewURI(const char* aSpec, nsIURI* aBaseURI,
nsCRT::free(scheme);
if (NS_FAILED(rv)) return rv;

if (hdlrResult) {
*hdlrResult = handler;
NS_ADDREF(*hdlrResult);
}
return handler->NewURI(aSpec, base, result);
}

NS_IMETHODIMP
nsIOService::NewURI(const char* aSpec, nsIURI* aBaseURI,
nsIURI* *result)
{
return NewURI(aSpec, aBaseURI, result, nsnull);
}

NS_IMETHODIMP
nsIOService::NewChannelFromURI(nsIURI *aURI, nsIChannel **result)
{
Expand All @@ -309,6 +306,31 @@ nsIOService::NewChannelFromURI(nsIURI *aURI, nsIChannel **result)
rv = GetProtocolHandler((const char*)scheme, getter_AddRefs(handler));
if (NS_FAILED(rv)) return rv;

PRBool useProxy = PR_FALSE;
if (mProxyService) {
mProxyService->GetProxyEnabled(&useProxy);
if (useProxy) {
nsXPIDLCString host, type;
PRInt32 port;
rv = mProxyService->ExamineForProxy(aURI, getter_Copies(host), &port, getter_Copies(type));
if (NS_SUCCEEDED(rv) && type.get())
{
// we are going to proxy this channel and the only protocol that can do proxying is http
rv = GetProtocolHandler("http", getter_AddRefs(handler));
if (NS_FAILED(rv)) return rv;

nsCOMPtr<nsIHttpProtocolHandler> httpHandler = do_QueryInterface(handler, &rv);
if (NS_FAILED(rv))
return rv;

if (!httpHandler)
return NS_ERROR_NULL_POINTER;

return httpHandler->NewProxyChannel(aURI, host, port, type, result);
}
}
}

rv = handler->NewChannel(aURI, result);
return rv;
}
Expand All @@ -318,12 +340,10 @@ nsIOService::NewChannel(const char *aSpec, nsIURI *aBaseURI, nsIChannel **result
{
nsresult rv;
nsCOMPtr<nsIURI> uri;
nsCOMPtr<nsIProtocolHandler> handler;
rv = NewURI(aSpec, aBaseURI, getter_AddRefs(uri), getter_AddRefs(handler));
rv = NewURI(aSpec, aBaseURI, getter_AddRefs(uri));
if (NS_FAILED(rv)) return rv;

rv = handler->NewChannel(uri, result);
return rv;
return NewChannelFromURI(uri, result);
}

NS_IMETHODIMP
Expand Down
4 changes: 3 additions & 1 deletion netwerk/base/src/nsIOService.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "nsISocketTransportService.h"
#include "nsIFileTransportService.h"
#include "nsIDNSService.h"
#include "nsIProtocolProxyService.h"
#include "nsCOMPtr.h"
#include "nsURLHelper.h"
#include "nsWeakPtr.h"
Expand Down Expand Up @@ -67,8 +68,9 @@ class nsIOService : public nsIIOService
nsCOMPtr<nsISocketTransportService> mSocketTransportService;
nsCOMPtr<nsIFileTransportService> mFileTransportService;
nsCOMPtr<nsIDNSService> mDNSService;
nsCOMPtr<nsIProtocolProxyService> mProxyService;
nsCOMPtr<nsIEventQueueService> mEventQueueService;

// Cached protocol handlers
nsWeakPtr mWeakHandler[NS_N(gScheme)];
};
Expand Down

0 comments on commit 265c2b5

Please sign in to comment.