Added a load type and reload type to the nsILoadAttribs interface and underlying implementation...

This commit is contained in:
rpotts%netscape.com 1998-10-10 04:32:18 +00:00
Родитель f5d46b23b8
Коммит ccacaec81f
5 изменённых файлов: 193 добавлений и 298 удалений

Просмотреть файл

@ -1,51 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS"
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
* the License for the specific language governing rights and limitations
* under the License.
*
* The Original Code is Mozilla Communicator client code.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are Copyright (C) 1998
* Netscape Communications Corporation. All Rights Reserved.
*/
#ifndef nsILoadAttribs_h___
#define nsILoadAttribs_h___
#include "nscore.h"
#include "prtypes.h"
#include "nsISupports.h"
// Class ID for an implementation of nsILoadAttribs
// {8942D321-48D3-11d2-9E7A-006008BF092E}
#define NS_ILOAD_ATTRIBS_IID \
{ 0x8942d321, 0x48d3, 0x11d2,{0x9e, 0x7a, 0x00, 0x60, 0x08, 0xbf, 0x09, 0x2e}}
// Defining attributes of a url's load behavior.
class nsILoadAttribs : public nsISupports {
public:
// Copy the state of another nsILoadAttribs instance.
NS_IMETHOD Clone(nsILoadAttribs* aLoadAttribs) = 0;
// Bypass Proxy.
NS_IMETHOD SetBypassProxy(PRBool aBypass) = 0;
NS_IMETHOD GetBypassProxy(PRBool *aBypass) = 0;
// Local IP address.
NS_IMETHOD SetLocalIP(const PRUint32 aLocalIP) = 0;
NS_IMETHOD GetLocalIP(PRUint32 *aLocalIP) = 0;
};
/* Creation routines. */
extern NS_NET nsresult NS_NewLoadAttribs(nsILoadAttribs** aInstancePtrResult);
#endif // nsILoadAttribs_h___

Просмотреть файл

@ -1,118 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef nsIURL_h___
#define nsIURL_h___
#include "nscore.h"
#include "nsISupports.h"
#include "nsILoadAttribs.h"
class nsIInputStream;
class nsIStreamListener;
class nsString;
class nsIURLGroup;
#define NS_IURL_IID \
{ 0x6ecb2900, 0x93b5, 0x11d1, \
{0x89, 0x5b, 0x00, 0x60, 0x08, 0x91, 0x1b, 0x81} }
/**
* TEMPORARY INTERFACE; this <B><EM><STRONG>will</STRONG></EM></B> will be
* going away
*/
class nsIURL : public nsISupports {
public:
/** Open the url for reading and return a new input stream for the
* url. The caller must release the input stream when done with it.
*/
virtual nsIInputStream* Open(PRInt32* aErrorCode) = 0;
virtual nsresult Open(nsIStreamListener *) = 0;
/** Equality operator */
virtual PRBool operator==(const nsIURL& aURL) const = 0;
virtual nsresult Set(const char *aNewSpec) = 0;
virtual nsresult SetReloadType(const PRInt32 type) = 0;
virtual nsresult SetLoadAttribs(nsILoadAttribs *aLoadAttrib) = 0;
/** Accessors */
//@{
/**
@return protocol part of the URL */
virtual const char* GetProtocol() const = 0;
/** @return host part of the URL */
virtual const char* GetHost() const = 0;
/** @return file part of the URL */
virtual const char* GetFile() const = 0;
/** @return ref part of the URL */
virtual const char* GetRef() const = 0;
/** @return search part of the URL */
virtual const char* GetSearch() const = 0;
/** @return string originally used to construct the URL */
virtual const char* GetSpec() const = 0;
/** @return ref part of the URL */
virtual PRInt32 GetPort() const = 0;
/** @return the nsISupports pointer to a container */
virtual nsISupports* GetContainer() const = 0;
/** @return the reload type for this url */
virtual PRInt32 GetReloadType() const = 0;
/** @return the loadAttributes pointer */
virtual nsILoadAttribs* GetLoadAttribs() const = 0;
/** @return the nsIURLGroup associated with the URL (if any) */
virtual nsIURLGroup* GetURLGroup() const = 0;
//@}
/** Write the URL to aString, overwriting previous contents. */
virtual void ToString(nsString& aString) const = 0;
};
/** Create a new URL from aSpec. */
extern NS_NET nsresult NS_NewURL(nsIURL** aInstancePtrResult,
const nsString& aSpec);
/** Create a new URL, interpreting aSpec as relative to aURL (if non-null). */
extern NS_NET nsresult NS_NewURL(nsIURL** aInstancePtrResult,
const nsIURL* aURL,
const nsString& aSpec,
nsISupports* container = nsnull,
nsIURLGroup* aGroup = nsnull);
/**
* Utility routine to take a url (may be nsnull) and a base url (may
* be empty), and a url spec and combine them properly into a new
* absolute url.
*/
extern NS_NET nsresult NS_MakeAbsoluteURL(nsIURL* aURL,
const nsString& aBaseURL,
const nsString& aSpec,
nsString& aResult);
#endif /* nsIURL_h___ */

Просмотреть файл

@ -29,24 +29,34 @@
// nsLoadAttribs definition.
class nsLoadAttribs : public nsILoadAttribs {
public:
nsLoadAttribs();
nsLoadAttribs();
// nsISupports
NS_DECL_ISUPPORTS
// nsISupports
NS_DECL_ISUPPORTS
// nsILoadAttribs
NS_IMETHOD Clone(nsILoadAttribs* aLoadAttribs);
NS_IMETHOD SetBypassProxy(PRBool aBypass);
NS_IMETHOD GetBypassProxy(PRBool *aBypass);
NS_IMETHOD SetLocalIP(const PRUint32 aIP);
NS_IMETHOD GetLocalIP(PRUint32 *aIP);
// nsILoadAttribs
NS_IMETHOD Clone(nsILoadAttribs* aLoadAttribs);
NS_IMETHOD SetBypassProxy(PRBool aBypass);
NS_IMETHOD GetBypassProxy(PRBool *aBypass);
NS_IMETHOD SetLocalIP(const PRUint32 aIP);
NS_IMETHOD GetLocalIP(PRUint32 *aIP);
NS_IMETHOD SetReloadType(nsURLReloadType aType);
NS_IMETHOD GetReloadType(nsURLReloadType* aResult);
NS_IMETHOD SetLoadType(nsURLLoadType aType);
NS_IMETHOD GetLoadType(nsURLLoadType* aResult);
protected:
virtual ~nsLoadAttribs();
private:
PRBool mBypass;
PRUint32 mLocalIP;
PRBool mBypass;
PRUint32 mLocalIP;
nsURLLoadType mLoadType;
nsURLReloadType mReloadType;
};
// nsLoadAttribs Implementation
@ -54,80 +64,146 @@ private:
static NS_DEFINE_IID(kILoadAttribsIID, NS_ILOAD_ATTRIBS_IID);
NS_IMPL_THREADSAFE_ISUPPORTS(nsLoadAttribs, kILoadAttribsIID);
nsLoadAttribs::nsLoadAttribs() {
nsLoadAttribs::nsLoadAttribs()
{
NS_INIT_REFCNT();
mBypass = PR_FALSE;
mLocalIP = 0;
mBypass = PR_FALSE;
mLocalIP = 0;
mLoadType = nsURLLoadNormal;
mReloadType = nsURLReload;
}
nsLoadAttribs::~nsLoadAttribs() {
nsLoadAttribs::~nsLoadAttribs()
{
}
NS_IMETHODIMP
nsLoadAttribs::Clone(nsILoadAttribs* aLoadAttribs)
{
nsresult rv = NS_OK;
nsresult rv = NS_OK;
if (nsnull == aLoadAttribs) {
rv = NS_ERROR_NULL_POINTER;
} else {
PRBool bypass;
PRUint32 ip;
NS_LOCK_INSTANCE();
aLoadAttribs->GetBypassProxy(&bypass);
SetBypassProxy(bypass);
aLoadAttribs->GetLocalIP(&ip);
SetLocalIP(ip);
NS_UNLOCK_INSTANCE();
}
return rv;
}
NS_IMETHODIMP
nsLoadAttribs::SetBypassProxy(PRBool aBypass) {
if (nsnull == aLoadAttribs) {
rv = NS_ERROR_NULL_POINTER;
} else {
NS_LOCK_INSTANCE();
mBypass = aBypass;
aLoadAttribs->GetBypassProxy(&mBypass);
aLoadAttribs->GetLocalIP(&mLocalIP);
aLoadAttribs->GetReloadType(&mReloadType);
NS_UNLOCK_INSTANCE();
return NS_OK;
}
return rv;
}
NS_IMETHODIMP
nsLoadAttribs::GetBypassProxy(PRBool *aBypass) {
nsresult rv = NS_OK;
if (nsnull == aBypass) {
rv = NS_ERROR_NULL_POINTER;
} else {
NS_LOCK_INSTANCE();
*aBypass = mBypass;
NS_UNLOCK_INSTANCE();
}
return rv;
nsLoadAttribs::SetBypassProxy(PRBool aBypass)
{
NS_LOCK_INSTANCE();
mBypass = aBypass;
NS_UNLOCK_INSTANCE();
return NS_OK;
}
NS_IMETHODIMP
nsLoadAttribs::SetLocalIP(const PRUint32 aLocalIP) {
nsLoadAttribs::GetBypassProxy(PRBool *aBypass)
{
nsresult rv = NS_OK;
if (nsnull == aBypass) {
rv = NS_ERROR_NULL_POINTER;
} else {
NS_LOCK_INSTANCE();
mLocalIP = aLocalIP;
*aBypass = mBypass;
NS_UNLOCK_INSTANCE();
return NS_OK;
}
return rv;
}
NS_IMETHODIMP
nsLoadAttribs::GetLocalIP(PRUint32 *aLocalIP) {
nsresult rv = NS_OK;
nsLoadAttribs::SetLocalIP(const PRUint32 aLocalIP)
{
NS_LOCK_INSTANCE();
mLocalIP = aLocalIP;
NS_UNLOCK_INSTANCE();
return NS_OK;
}
if (nsnull == aLocalIP) {
rv = NS_ERROR_NULL_POINTER;
} else {
NS_LOCK_INSTANCE();
*aLocalIP = mLocalIP;
NS_UNLOCK_INSTANCE();
}
return rv;
NS_IMETHODIMP
nsLoadAttribs::GetLocalIP(PRUint32 *aLocalIP)
{
nsresult rv = NS_OK;
if (nsnull == aLocalIP) {
rv = NS_ERROR_NULL_POINTER;
} else {
NS_LOCK_INSTANCE();
*aLocalIP = mLocalIP;
NS_UNLOCK_INSTANCE();
}
return rv;
}
NS_IMETHODIMP
nsLoadAttribs::SetReloadType(nsURLReloadType aType)
{
nsresult rv = NS_OK;
if ((aType < nsURLReload) || (aType >= nsURLReloadMax)) {
rv = NS_ERROR_ILLEGAL_VALUE;
} else {
NS_LOCK_INSTANCE();
mReloadType = aType;
NS_UNLOCK_INSTANCE();
}
return rv;
}
NS_IMETHODIMP
nsLoadAttribs::GetReloadType(nsURLReloadType* aResult)
{
nsresult rv = NS_OK;
if (nsnull == aResult) {
rv = NS_ERROR_NULL_POINTER;
} else {
NS_LOCK_INSTANCE();
*aResult = mReloadType;
NS_UNLOCK_INSTANCE();
}
return rv;
}
NS_IMETHODIMP
nsLoadAttribs::SetLoadType(nsURLLoadType aType)
{
nsresult rv = NS_OK;
if ((aType < nsURLLoadNormal) || (aType >= nsURLLoadMax)) {
rv = NS_ERROR_ILLEGAL_VALUE;
} else {
NS_LOCK_INSTANCE();
mLoadType = aType;
NS_UNLOCK_INSTANCE();
}
return rv;
}
NS_IMETHODIMP
nsLoadAttribs::GetLoadType(nsURLLoadType* aResult)
{
nsresult rv = NS_OK;
if (nsnull == aResult) {
rv = NS_ERROR_NULL_POINTER;
} else {
NS_LOCK_INSTANCE();
*aResult = mLoadType;
NS_UNLOCK_INSTANCE();
}
return rv;
}
// Creation routines

Просмотреть файл

@ -189,45 +189,68 @@ nsNetlibService::~nsNetlibService()
void nsNetlibService::SetupURLStruct(nsIURL *aUrl, URL_Struct *aURL_s) {
nsresult result;
NET_ReloadMethod reloadType;
nsILoadAttribs* loadAttribs = aUrl->GetLoadAttribs();
PRInt32 type = aUrl->GetReloadType();
void nsNetlibService::SetupURLStruct(nsIURL *aUrl, URL_Struct *aURL_s)
{
nsresult rv;
nsILoadAttribs* loadAttribs = aUrl->GetLoadAttribs();
/* If this url has load attributes, setup the underlying url struct
* accordingly. */
if (loadAttribs) {
nsURLLoadType loadType;
nsURLReloadType reloadType;
PRUint32 localIP;
NS_VERIFY_THREADSAFE_INTERFACE(loadAttribs);
rv = loadAttribs->GetReloadType(&reloadType);
if (NS_FAILED(rv)) {
reloadType = nsURLReload;
}
if ((reloadType == nsURLReloadBypassProxy) ||
(reloadType == nsURLReloadBypassCacheAndProxy)) {
PRBool bBypassProxy;
rv = loadAttribs->GetBypassProxy(&bBypassProxy);
if (NS_FAILED(rv)) {
bBypassProxy = PR_FALSE;
}
aURL_s->bypassProxy = bBypassProxy;
}
/* Set the NET_ReloadMethod to correspond with what we've
* been asked to do.
*
* 0 = nsReload (normal)
* 1 = nsReloadBypassCache
* 2 = nsReloadBypassProxy
* 3 = nsReloadBypassCacheAndProxy
* 0 = nsURLReload (normal)
* 1 = nsURLReloadBypassCache
* 2 = nsURLReloadBypassProxy
* 3 = nsURLReloadBypassCacheAndProxy
*/
if (type == 1 || type == 3) {
reloadType = NET_SUPER_RELOAD;
if ((reloadType == nsURLReloadBypassCache) ||
(reloadType == nsURLReloadBypassCacheAndProxy)) {
aURL_s->force_reload = NET_SUPER_RELOAD;
} else {
reloadType = NET_NORMAL_RELOAD;
aURL_s->force_reload = NET_NORMAL_RELOAD;
}
/* If this url has load attributes, setup the underlying url struct
* accordingly. */
if (loadAttribs) {
PRUint32 localIP = 0;
NS_VERIFY_THREADSAFE_INTERFACE(loadAttribs);
if (type == 2 || type == 3) {
result = loadAttribs->GetBypassProxy((int *)&(aURL_s->bypassProxy));
if (result != NS_OK)
aURL_s->bypassProxy = FALSE;
}
result = loadAttribs->GetLocalIP(&localIP);
if (result != NS_OK)
localIP = 0;
aURL_s->localIP = localIP;
NS_RELEASE(loadAttribs);
rv = loadAttribs->GetLoadType(&loadType);
if (NS_FAILED(rv)) {
loadType = nsURLLoadNormal;
}
if (loadType == nsURLLoadBackground) {
aURL_s->load_background = PR_TRUE;
} else {
aURL_s->load_background = PR_FALSE;
}
rv = loadAttribs->GetLocalIP(&localIP);
if (NS_FAILED(rv)) {
localIP = 0;
}
aURL_s->localIP = localIP;
NS_RELEASE(loadAttribs);
}
}
nsresult nsNetlibService::OpenStream(nsIURL *aUrl,
@ -237,7 +260,6 @@ nsresult nsNetlibService::OpenStream(nsIURL *aUrl,
nsConnectionInfo *pConn;
nsIProtocolConnection *pProtocol;
nsresult result;
NET_ReloadMethod reloadType;
nsIStreamListener* consumer;
if ((NULL == aConsumer) || (NULL == aUrl)) {
@ -280,7 +302,7 @@ nsresult nsNetlibService::OpenStream(nsIURL *aUrl,
/* Create the URLStruct... */
URL_s = NET_CreateURLStruct(aUrl->GetSpec(), reloadType);
URL_s = NET_CreateURLStruct(aUrl->GetSpec(), NET_NORMAL_RELOAD);
if (NULL == URL_s) {
NS_RELEASE(pConn);
return NS_FALSE;
@ -366,7 +388,6 @@ nsresult nsNetlibService::OpenBlockingStream(nsIURL *aUrl,
/* Create the blocking stream... */
pBlockingStream = new nsBlockingStream();
NET_ReloadMethod reloadType;
if (NULL == pBlockingStream) {
goto loser;
@ -404,7 +425,7 @@ nsresult nsNetlibService::OpenBlockingStream(nsIURL *aUrl,
/* Create the URLStruct... */
URL_s = NET_CreateURLStruct(aUrl->GetSpec(), reloadType);
URL_s = NET_CreateURLStruct(aUrl->GetSpec(), NET_NORMAL_RELOAD);
if (NULL == URL_s) {
NS_RELEASE(pBlockingStream);
NS_RELEASE(pConn);

Просмотреть файл

@ -52,7 +52,6 @@ public:
virtual PRBool operator==(const nsIURL& aURL) const;
virtual nsresult Set(const char *aNewSpec);
virtual nsresult SetReloadType(const PRInt32 type);
virtual nsresult SetLoadAttribs(nsILoadAttribs *aLoadAttrib);
virtual const char* GetProtocol() const;
@ -63,7 +62,6 @@ public:
virtual const char* GetSpec() const;
virtual PRInt32 GetPort() const;
virtual nsISupports* GetContainer() const;
virtual PRInt32 GetReloadType() const;
virtual nsILoadAttribs* GetLoadAttribs() const;
virtual nsIURLGroup* GetURLGroup() const;
@ -79,11 +77,6 @@ public:
nsILoadAttribs* mLoadAttribs;
nsIURLGroup* mURLGroup;
// The reload type can be set to one of the following.
// 0 - normal reload (uses cache) (defined as nsReload in nsIWebShell.h)
// 1 - bypass the cache (defined as nsReloadBypassCache)
// 2 - bypass the proxy (not yet implemented) (defined as nsReloadBypassProxy)
PRInt32 mReloadType;
PRInt32 mPort;
nsISupports* mProtocolUrl;
@ -114,7 +107,6 @@ void URLImpl::Init(nsISupports* aContainer, nsIURLGroup* aGroup)
mSearch = nsnull;
mPort = -1;
mSpec = nsnull;
mReloadType = 0;
mLoadAttribs = nsnull;
mURLGroup = aGroup;
@ -194,20 +186,6 @@ nsresult URLImpl::Set(const char *aNewSpec)
return ParseURL(nsnull, aNewSpec);
}
nsresult URLImpl::SetReloadType(const PRInt32 type)
{
nsresult rv = NS_OK;
if ( !((type >= 0) && (type <= 2)) ) {
rv = NS_ERROR_ILLEGAL_VALUE;
} else {
NS_LOCK_INSTANCE();
mReloadType = type;
NS_UNLOCK_INSTANCE();
}
return rv;
}
nsresult URLImpl::SetLoadAttribs(nsILoadAttribs *aLoadAttrib)
{
NS_LOCK_INSTANCE();
@ -322,17 +300,6 @@ nsISupports* URLImpl::GetContainer() const
return container;
}
PRInt32 URLImpl::GetReloadType() const
{
PRInt32 reloadType;
NS_LOCK_INSTANCE();
reloadType = mReloadType;
NS_UNLOCK_INSTANCE();
return reloadType;
}
nsILoadAttribs* URLImpl::GetLoadAttribs() const
{
nsILoadAttribs* loadAttribs;