diff --git a/mozilla/network/module/nsILoadAttribs.h b/mozilla/network/module/nsILoadAttribs.h index ec3a94aedb3..2463875708f 100644 --- a/mozilla/network/module/nsILoadAttribs.h +++ b/mozilla/network/module/nsILoadAttribs.h @@ -29,19 +29,52 @@ #define NS_ILOAD_ATTRIBS_IID \ { 0x8942d321, 0x48d3, 0x11d2,{0x9e, 0x7a, 0x00, 0x60, 0x08, 0xbf, 0x09, 0x2e}} +/* + * The nsReloadType represents the following: + * nsURLReload - normal reload (uses cache) + * nsURLReloadBypassCache - bypass the cache + * nsURLReloadBypassCacheAndProxy - bypass the proxy (not yet implemented) + */ +typedef enum { + nsURLReload = 0, + nsURLReloadBypassCache, + nsURLReloadBypassProxy, + nsURLReloadBypassCacheAndProxy, + nsURLReloadMax +} nsURLReloadType; + +/* + * The nsLoadType represents the following: + * nsURLLoadNormal - Load the URL normally. + * nsURLLoadBackground - Supress all notifications when loading the URL. + */ +typedef enum { + nsURLLoadNormal = 0, + nsURLLoadBackground, + nsURLLoadMax +} nsURLLoadType; + // 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; + NS_IMETHOD Clone(nsILoadAttribs* aLoadAttribs) = 0; - // Bypass Proxy. - NS_IMETHOD SetBypassProxy(PRBool aBypass) = 0; - NS_IMETHOD GetBypassProxy(PRBool *aBypass) = 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; + // Local IP address. + NS_IMETHOD SetLocalIP(const PRUint32 aLocalIP) = 0; + NS_IMETHOD GetLocalIP(PRUint32 *aLocalIP) = 0; + + // Reload method. + NS_IMETHOD SetReloadType(nsURLReloadType aType) = 0; + NS_IMETHOD GetReloadType(nsURLReloadType* aResult) = 0; + + // Load method + NS_IMETHOD SetLoadType(nsURLLoadType aType) = 0; + NS_IMETHOD GetLoadType(nsURLLoadType* aResult) = 0; }; /* Creation routines. */ diff --git a/mozilla/network/module/nsIURL.h b/mozilla/network/module/nsIURL.h index c1418331cda..76f1d70df80 100644 --- a/mozilla/network/module/nsIURL.h +++ b/mozilla/network/module/nsIURL.h @@ -49,8 +49,6 @@ public: virtual nsresult Set(const char *aNewSpec) = 0; - virtual nsresult SetReloadType(const PRInt32 type) = 0; - virtual nsresult SetLoadAttribs(nsILoadAttribs *aLoadAttrib) = 0; /** Accessors */ @@ -80,9 +78,6 @@ public: /** @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; diff --git a/mozilla/network/module/nsLoadAttribs.cpp b/mozilla/network/module/nsLoadAttribs.cpp index 22d94cf948d..7ac30b911d2 100644 --- a/mozilla/network/module/nsLoadAttribs.cpp +++ b/mozilla/network/module/nsLoadAttribs.cpp @@ -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 diff --git a/mozilla/network/module/nsNetService.cpp b/mozilla/network/module/nsNetService.cpp index 61a57cdfc98..a282ae0ecaf 100644 --- a/mozilla/network/module/nsNetService.cpp +++ b/mozilla/network/module/nsNetService.cpp @@ -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); diff --git a/mozilla/network/module/nsURL.cpp b/mozilla/network/module/nsURL.cpp index a89fefbd376..77e636290cf 100644 --- a/mozilla/network/module/nsURL.cpp +++ b/mozilla/network/module/nsURL.cpp @@ -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;