sr=rpotts, r=gagan. 70743. switching over to new extensible URI::SchemeIs() api. and changing existing implementations over to new api. also modified nsHTTP and nsHTTPS handlers a bit to make things cleaner.

git-svn-id: svn://10.0.0.236/trunk@89421 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
valeski%netscape.com
2001-03-13 02:01:07 +00:00
parent 0cea9abfef
commit 3dcd14eede
18 changed files with 71 additions and 148 deletions

View File

@@ -30,8 +30,7 @@ static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
////////////////////////////////////////////////////////////////////////////////
nsJARURI::nsJARURI()
: mJAREntry(nsnull),
mSchemeType(nsIURI::JAR)
: mJAREntry(nsnull)
{
NS_INIT_REFCNT();
}
@@ -116,7 +115,6 @@ nsJARURI::SetSpec(const char * aSpec)
if (nsCRT::strncmp("jar", &aSpec[startPos], endPos - startPos - 1) != 0)
return NS_ERROR_MALFORMED_URI;
mSchemeType = nsIURI::JAR;
// Search backward from the end for the "!/" delimiter. Remember, jar URLs
// can nest, e.g.:
// jar:jar:http://www.foo.com/bar.jar!/a.jar!/b.html
@@ -277,12 +275,16 @@ nsJARURI::Equals(nsIURI *other, PRBool *result)
}
NS_IMETHODIMP
nsJARURI::SchemeIs(PRUint32 i_Scheme, PRBool *o_Equals)
nsJARURI::SchemeIs(const char *i_Scheme, PRBool *o_Equals)
{
NS_ENSURE_ARG_POINTER(o_Equals);
if (i_Scheme == nsIURI::UNKNOWN)
return NS_ERROR_INVALID_ARG;
*o_Equals = (mSchemeType == i_Scheme);
if (!i_Scheme) return NS_ERROR_INVALID_ARG;
if (*i_Scheme == 'j' || *i_Scheme == 'J') {
*o_Equals = PL_strcasecmp("jar", i_Scheme) ? PR_FALSE : PR_TRUE;
} else {
*o_Equals = PR_FALSE;
}
return NS_OK;
}

View File

@@ -50,7 +50,6 @@ public:
protected:
nsCOMPtr<nsIURI> mJARFile;
char *mJAREntry;
PRUint32 mSchemeType;
};
#endif // nsJARURI_h__

View File

@@ -65,25 +65,6 @@
[scriptable, uuid(07a22cc0-0ce5-11d3-9331-00104ba0fd40)]
interface nsIURI : nsISupports
{
/**
* List of standard/known URL scheme types for quicker lookups and
* comparisons. The UNKNOWN type applies for all other cases.
*/
const PRUint32 UNKNOWN = 0;
const PRUint32 ABOUT = 1;
const PRUint32 CHROME = 2;
const PRUint32 FILE = 3;
const PRUint32 FTP = 4;
const PRUint32 HTTP = 5;
const PRUint32 HTTPS = 6;
const PRUint32 IMAP = 7;
const PRUint32 JAR = 8;
const PRUint32 JAVASCRIPT = 9;
const PRUint32 MAILBOX = 10;
const PRUint32 MAILTO = 11;
const PRUint32 NEWS = 12;
const PRUint32 RESOURCE = 13;
const PRUint32 LDAP = 14;
/**
* Returns a string representation of the URI. Setting the spec
@@ -156,11 +137,10 @@ interface nsIURI : nsISupports
/**
* An optimization to do scheme checks without requiring the users of nsIURI
* to GetScheme thereby saving extra allocating and freeing. Returns true if
* the schemes match (case ignored) to one of the standard known types
* mentioned above. Note that for unknown cases this will always return
* false.
* the schemes match (case ignored). Note that for unknown cases this will
* always return false.
*/
boolean schemeIs(in PRUint32 scheme);
boolean schemeIs(in string scheme);
/**
* Clones the current URI. The newly created URI will be in a closed

View File

@@ -41,8 +41,7 @@ static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
nsSimpleURI::nsSimpleURI(nsISupports* outer)
: mScheme(nsnull),
mPath(nsnull),
mSchemeType(nsIURI::UNKNOWN)
mPath(nsnull)
{
NS_INIT_AGGREGATED(outer);
}
@@ -113,7 +112,6 @@ nsSimpleURI::SetSpec(const char* aSpec)
mScheme = scheme.ToNewCString();
if (mScheme == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
mSchemeType = SchemeTypeFor(mScheme);
if (mPath)
nsCRT::free(mPath);
mPath = path.ToNewCString();
@@ -134,6 +132,7 @@ nsSimpleURI::SetScheme(const char* scheme)
{
if (mScheme) nsCRT::free(mScheme);
mScheme = nsCRT::strdup(scheme);
ToLowerCase(mScheme);
return NS_OK;
}
@@ -250,12 +249,18 @@ nsSimpleURI::Equals(nsIURI* other, PRBool *result)
}
NS_IMETHODIMP
nsSimpleURI::SchemeIs(PRUint32 i_Scheme, PRBool *o_Equals)
nsSimpleURI::SchemeIs(const char *i_Scheme, PRBool *o_Equals)
{
NS_ENSURE_ARG_POINTER(o_Equals);
if (i_Scheme == nsIURI::UNKNOWN)
return NS_ERROR_INVALID_ARG;
*o_Equals = (mSchemeType == i_Scheme);
if (!i_Scheme) return NS_ERROR_NULL_POINTER;
// mScheme is guaranteed to be lower case.
if (*i_Scheme == *mScheme || *i_Scheme == (*mScheme - ('a' - 'A')) ) {
*o_Equals = PL_strcasecmp(mScheme, i_Scheme) ? PR_FALSE : PR_TRUE;
} else {
*o_Equals = PR_FALSE;
}
return NS_OK;
}

View File

@@ -51,7 +51,6 @@ public:
protected:
char* mScheme;
char* mPath;
PRUint32 mSchemeType;
};
#endif // nsSimpleURI_h__

View File

@@ -118,8 +118,7 @@ nsStdURL::nsStdURL(nsISupports* outer)
mParam(nsnull),
mQuery(nsnull),
mRef(nsnull),
mDefaultPort(-1),
mSchemeType(nsIURI::UNKNOWN)
mDefaultPort(-1)
{
NS_INIT_AGGREGATED(outer);
InitGlobalObjects();
@@ -176,7 +175,6 @@ nsStdURL::nsStdURL(const nsStdURL& otherURL)
mQuery = otherURL.mQuery ? nsCRT::strdup(otherURL.mQuery) : nsnull;
mRef= otherURL.mRef ? nsCRT::strdup(otherURL.mRef) : nsnull;
mURLParser = otherURL.mURLParser;
mSchemeType = otherURL.mSchemeType;
NS_INIT_AGGREGATED(nsnull); // Todo! How?
}
@@ -195,7 +193,6 @@ nsStdURL::operator=(const nsStdURL& otherURL)
mQuery = otherURL.mQuery ? nsCRT::strdup(otherURL.mQuery) : nsnull;
mRef= otherURL.mRef ? nsCRT::strdup(otherURL.mRef) : nsnull;
mURLParser = otherURL.mURLParser;
mSchemeType = otherURL.mSchemeType;
NS_INIT_AGGREGATED(nsnull); // Todo! How?
return *this;
@@ -306,12 +303,18 @@ nsStdURL::Equals(nsIURI *i_OtherURI, PRBool *o_Equals)
}
NS_IMETHODIMP
nsStdURL::SchemeIs(PRUint32 i_Scheme, PRBool *o_Equals)
nsStdURL::SchemeIs(const char *i_Scheme, PRBool *o_Equals)
{
NS_ENSURE_ARG_POINTER(o_Equals);
if (i_Scheme == nsIURI::UNKNOWN)
return NS_ERROR_INVALID_ARG;
*o_Equals = (mSchemeType == i_Scheme);
if (!i_Scheme) return NS_ERROR_NULL_POINTER;
// mScheme is guaranteed to be lower case.
if (*i_Scheme == *mScheme || *i_Scheme == (*mScheme - ('a' - 'A')) ) {
*o_Equals = PL_strcasecmp(mScheme, i_Scheme) ? PR_FALSE : PR_TRUE;
} else {
*o_Equals = PR_FALSE;
}
return NS_OK;
}
@@ -344,8 +347,6 @@ nsStdURL::Parse(const char* i_Spec)
nsresult rv = mURLParser->ParseAtScheme(i_Spec, &mScheme, &mUsername,
&mPassword, &mHost, &mPort,
&ePath);
mSchemeType = SchemeTypeFor(mScheme);
if (NS_SUCCEEDED(rv)) {
// Now parse the path
rv = mURLParser->ParseAtDirectory(ePath, &mDirectory, &mFileBaseName,

View File

@@ -100,7 +100,6 @@ protected:
nsCOMPtr<nsIURLParser> mURLParser;
PRInt32 mDefaultPort; // port for protocol (used for canonicalizing,
// and printing)
PRUint32 mSchemeType;
// Global objects. Dont use comptr as its destructor will cause

View File

@@ -395,42 +395,3 @@ NS_NET nsresult ExtractURLScheme(const char* inURI, PRUint32 *startPos,
}
return NS_ERROR_MALFORMED_URI;
}
/* Convert the URI string to a known case (or nsIURI::UNKNOWN) */
NS_NET PRUint32 SchemeTypeFor(const char* i_scheme)
{
// This order is a speculation on what gets used more (or needs more
// help in optimizing)
if (!i_scheme)
return nsIURI::UNKNOWN;
if (0 == PL_strcasecmp("chrome", i_scheme))
return nsIURI::CHROME;
else if (0 == PL_strcasecmp("resource", i_scheme))
return nsIURI::RESOURCE;
else if (0 == PL_strcasecmp("jar", i_scheme))
return nsIURI::JAR;
else if (0 == PL_strcasecmp("file", i_scheme))
return nsIURI::FILE;
else if (0 == PL_strcasecmp("http", i_scheme))
return nsIURI::HTTP;
else if (0 == PL_strcasecmp("ftp", i_scheme))
return nsIURI::FTP;
else if (0 == PL_strcasecmp("https", i_scheme))
return nsIURI::HTTPS;
else if (0 == PL_strcasecmp("mailbox", i_scheme))
return nsIURI::MAILBOX;
else if (0 == PL_strcasecmp("imap", i_scheme))
return nsIURI::IMAP;
else if (0 == PL_strcasecmp("javascript", i_scheme))
return nsIURI::JAVASCRIPT;
else if (0 == PL_strcasecmp("about", i_scheme))
return nsIURI::ABOUT;
else if (0 == PL_strcasecmp("mailto", i_scheme))
return nsIURI::MAILTO;
else if (0 == PL_strcasecmp("news", i_scheme))
return nsIURI::NEWS;
else if (0 == PL_strcasecmp("ldap", i_scheme))
return nsIURI::LDAP;
else
return nsIURI::UNKNOWN;
}

View File

@@ -81,9 +81,6 @@ NS_NET void ToLowerCase(char* str);
NS_NET nsresult ExtractURLScheme(const char* inURI, PRUint32 *startPos,
PRUint32 *endPos, char* *scheme);
/* Convert the URI string to a known case (or nsIURI::UNKNOWN) */
NS_NET PRUint32 SchemeTypeFor(const char* iScheme);
#ifdef __cplusplus
}
#endif

View File

@@ -111,7 +111,7 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsStorageTransport)
#include "nsBasicAuth.h"
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsHTTPHandler, Init);
//NS_GENERIC_FACTORY_CONSTRUCTOR(nsHTTPSHandler);
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsHTTPSHandler, Init);
#define NS_HTTPS_HANDLER_FACTORY_CID { 0xd2771480, 0xcac4, 0x11d3, { 0x8c, 0xaf, 0x0, 0x0, 0x64, 0x65, 0x73, 0x74 } }
@@ -764,7 +764,7 @@ static nsModuleComponentInfo gNetModuleInfo[] = {
{ "HTTPS Handler",
NS_HTTPS_HANDLER_FACTORY_CID,
NS_NETWORK_PROTOCOL_CONTRACTID_PREFIX "https",
nsHTTPSHandler::Create },
nsHTTPSHandlerConstructor },
{ "Basic Auth Encoder",
NS_BASICAUTH_CID,
NS_BASICAUTH_CONTRACTID,

View File

@@ -127,7 +127,7 @@ nsHTTPChannel::nsHTTPChannel(nsIURI *aURL, nsHTTPHandler *aHandler)
#endif
PRBool isHTTPS = PR_FALSE;
if (NS_SUCCEEDED(mURI->SchemeIs(nsIURI::HTTPS, &isHTTPS)) && isHTTPS)
if (NS_SUCCEEDED(mURI->SchemeIs("https", &isHTTPS)) && isHTTPS)
mLoadAttributes |= nsIChannel::INHIBIT_PERSISTENT_CACHING;
}

View File

@@ -117,8 +117,7 @@ nsHTTPHandler::GetDefaultPort(PRInt32 *result)
NS_IMETHODIMP
nsHTTPHandler::GetScheme(char * *o_Scheme)
{
static const char* scheme = "http";
*o_Scheme = nsCRT::strdup(scheme);
*o_Scheme = nsCRT::strdup(mScheme);
return NS_OK;
}
@@ -612,10 +611,10 @@ nsHTTPHandler::nsHTTPHandler():
mPipelineFirstRequest(PR_FALSE),
mPipelineMaxRequests(DEFAULT_PIPELINE_MAX_REQUESTS),
mReferrerLevel(0),
mScheme(nsIURI::HTTP),
mRequestTimeout(DEFAULT_HTTP_REQUEST_TIMEOUT),
mConnectTimeout(DEFAULT_HTTP_CONNECT_TIMEOUT),
mProxySSLConnectAllowed(PR_FALSE)
mProxySSLConnectAllowed(PR_FALSE),
mScheme(nsnull)
{
NS_INIT_REFCNT();
SetAcceptEncodings(DEFAULT_ACCEPT_ENCODINGS);
@@ -838,6 +837,9 @@ nsHTTPHandler::Init()
NS_WITH_SERVICE(nsIObserverService, observerService, NS_OBSERVERSERVICE_CONTRACTID, &rv);
if (NS_SUCCEEDED(rv))
observerService->AddObserver(this, NS_LITERAL_STRING("profile-before-change").get());
mScheme = nsCRT::strdup("http");
if (!mScheme) return NS_ERROR_OUT_OF_MEMORY;
return NS_OK;
}
@@ -872,6 +874,7 @@ nsHTTPHandler::~nsHTTPHandler()
CRTFREEIF (mAcceptLanguages);
CRTFREEIF (mAcceptEncodings);
CRTFREEIF (mScheme);
}
nsresult nsHTTPHandler::RequestTransport(nsIURI* i_Uri,

View File

@@ -202,7 +202,7 @@ protected:
nsCString mProductComment;
nsCString mAppUserAgentOverride;
PRInt32 mScheme;
char * mScheme; // used by nsHTTPHandler and nsHTTPSHandler
private:

View File

@@ -32,40 +32,27 @@ static NS_DEFINE_CID(kSocketTransportServiceCID, NS_SOCKETTRANSPORTSERVICE_CID);
nsHTTPSHandler::nsHTTPSHandler()
: nsHTTPHandler()
{
nsresult rv;
nsISupports *psm = nsnull;
//
// Initialize the PSM component.
// This is to ensure that PSM is initialized on the main UI thread.
//
rv = nsServiceManager::GetService( PSM_COMPONENT_CONTRACTID,
NS_GET_IID(nsISecurityManagerComponent),
(nsISupports**)&psm);
NS_IF_RELEASE(psm);
mScheme = nsIURI::HTTPS;
}
nsHTTPSHandler::~nsHTTPSHandler()
{
}
NS_METHOD
nsHTTPSHandler::Create(nsISupports *aOuter, REFNSIID aIID, void **aResult)
{
nsresult rv;
if (aOuter) return NS_ERROR_NO_AGGREGATION;
nsresult
nsHTTPSHandler::Init() {
nsresult rv = NS_OK;
nsHTTPSHandler* handler = new nsHTTPSHandler();
if (!handler) return NS_ERROR_OUT_OF_MEMORY;
NS_ADDREF(handler);
rv = handler->Init();
if (NS_FAILED(rv)) {
delete handler;
return rv;
}
rv = handler->QueryInterface(aIID, aResult);
NS_RELEASE(handler);
// init nsHTTPHandler *first*
rv = nsHTTPHandler::Init();
if (NS_FAILED(rv)) return rv;
// done to "init" psm.
nsCOMPtr<nsISupports> psm(do_GetService(PSM_COMPONENT_CONTRACTID, &rv));
if (NS_FAILED(rv)) return rv;
if (mScheme) nsCRT::free(mScheme);
mScheme = nsCRT::strdup("https");
if (!mScheme) return NS_ERROR_OUT_OF_MEMORY;
return rv;
}

View File

@@ -40,7 +40,7 @@ public:
nsHTTPSHandler(void);
virtual ~nsHTTPSHandler();
static NS_METHOD Create(nsISupports* aOuter, const nsIID& aIID, void* *aResult);
nsresult Init();
//Functions from nsIProtocolHandler
/*
@@ -54,17 +54,6 @@ public:
return NS_OK;
};
/*
The GetScheme function uniquely identifies the scheme this handler
is associated with.
*/
NS_IMETHOD GetScheme(char * *o_Scheme)
{
static const char* scheme = "https";
*o_Scheme = nsCRT::strdup(scheme);
return NS_OK;
};
/**
* Called to create a transport from RequestTransport to accually
* make a new channel.

View File

@@ -30,8 +30,7 @@ static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
////////////////////////////////////////////////////////////////////////////////
nsJARURI::nsJARURI()
: mJAREntry(nsnull),
mSchemeType(nsIURI::JAR)
: mJAREntry(nsnull)
{
NS_INIT_REFCNT();
}
@@ -116,7 +115,6 @@ nsJARURI::SetSpec(const char * aSpec)
if (nsCRT::strncmp("jar", &aSpec[startPos], endPos - startPos - 1) != 0)
return NS_ERROR_MALFORMED_URI;
mSchemeType = nsIURI::JAR;
// Search backward from the end for the "!/" delimiter. Remember, jar URLs
// can nest, e.g.:
// jar:jar:http://www.foo.com/bar.jar!/a.jar!/b.html
@@ -277,12 +275,16 @@ nsJARURI::Equals(nsIURI *other, PRBool *result)
}
NS_IMETHODIMP
nsJARURI::SchemeIs(PRUint32 i_Scheme, PRBool *o_Equals)
nsJARURI::SchemeIs(const char *i_Scheme, PRBool *o_Equals)
{
NS_ENSURE_ARG_POINTER(o_Equals);
if (i_Scheme == nsIURI::UNKNOWN)
return NS_ERROR_INVALID_ARG;
*o_Equals = (mSchemeType == i_Scheme);
if (!i_Scheme) return NS_ERROR_INVALID_ARG;
if (*i_Scheme == 'j' || *i_Scheme == 'J') {
*o_Equals = PL_strcasecmp("jar", i_Scheme) ? PR_FALSE : PR_TRUE;
} else {
*o_Equals = PR_FALSE;
}
return NS_OK;
}

View File

@@ -50,7 +50,6 @@ public:
protected:
nsCOMPtr<nsIURI> mJARFile;
char *mJAREntry;
PRUint32 mSchemeType;
};
#endif // nsJARURI_h__

View File

@@ -281,7 +281,7 @@ void nsUnknownDecoder::DetermineContentType(nsIRequest* request)
nsCOMPtr<nsIURI> pURL;
if (NS_SUCCEEDED(aChannel->GetURI(getter_AddRefs(pURL))))
pURL->SchemeIs(nsIURI::FILE, &isLocalFile);
pURL->SchemeIs("file", &isLocalFile);
}
if (!mRequireHTMLsuffix || !isLocalFile) {