Fixing bug 488162. Disable prefetches on proxy config and pref, r+sr=bzbarsky@mit.edu

This commit is contained in:
Patrick McManus 2009-05-06 14:26:33 -07:00
parent cae63b32dc
commit 47f5a5ed6b
6 changed files with 29 additions and 10 deletions

View File

@ -183,7 +183,7 @@ nsHTMLDNSPrefetch::Prefetch(nsAString &hostname, PRUint16 flags)
return NS_ERROR_NOT_AVAILABLE;
nsCOMPtr<nsICancelable> tmpOutstanding;
return sDNSService->AsyncResolve(NS_ConvertUTF16toUTF8(hostname), flags,
return sDNSService->AsyncResolve(NS_ConvertUTF16toUTF8(hostname), flags | nsIDNSService::RESOLVE_SPECULATE,
sDNSListener, nsnull, getter_AddRefs(tmpOutstanding));
}
@ -293,7 +293,7 @@ nsHTMLDNSPrefetch::nsDeferrals::SubmitQueue()
nsCOMPtr<nsICancelable> tmpOutstanding;
sDNSService->AsyncResolve(hostName,
mEntries[mTail].mFlags,
mEntries[mTail].mFlags | nsIDNSService::RESOLVE_SPECULATE,
sDNSListener, nsnull, getter_AddRefs(tmpOutstanding));
}
}

View File

@ -82,8 +82,8 @@ nsDNSPrefetch::Prefetch(PRUint16 flags)
nsCOMPtr<nsICancelable> tmpOutstanding;
return sDNSService->AsyncResolve(mHostname, flags, this, nsnull,
getter_AddRefs(tmpOutstanding));
return sDNSService->AsyncResolve(mHostname, flags | nsIDNSService::RESOLVE_SPECULATE,
this, nsnull, getter_AddRefs(tmpOutstanding));
}
nsresult

View File

@ -306,8 +306,7 @@ public:
PRUint32 host_len;
};
protected:
// These values correspond to the integer network.proxy.type preference
enum ProxyConfig {
eProxyConfig_Direct,
eProxyConfig_Manual,
@ -318,6 +317,8 @@ protected:
eProxyConfig_Last
};
protected:
// simplified array of filters defined by this struct
struct HostInfo {
PRBool is_ipaddr;

View File

@ -46,7 +46,7 @@ interface nsIDNSListener;
/**
* nsIDNSService
*/
[scriptable, uuid(ee4d9f1d-4f99-4384-b547-29da735f8b6e)]
[scriptable, uuid(c1a56a45-8fa3-44e6-9f01-38c91c858cf9)]
interface nsIDNSService : nsISupports
{
/**
@ -114,4 +114,10 @@ interface nsIDNSService : nsISupports
*/
const unsigned long RESOLVE_PRIORITY_MEDIUM = (1 << 2);
const unsigned long RESOLVE_PRIORITY_LOW = (1 << 3);
/**
* if set, indicates request is speculative. Speculative requests
* return errors if prefetching is disabled by configuration.
*/
const unsigned long RESOLVE_SPECULATE = (1 << 4);
};

View File

@ -51,6 +51,7 @@
#include "nsNetCID.h"
#include "nsNetError.h"
#include "nsDNSPrefetch.h"
#include "nsProtocolProxyService.h"
#include "prsystem.h"
#include "prnetdb.h"
#include "prmon.h"
@ -328,6 +329,7 @@ nsDNSService::Init()
PRBool enableIDN = PR_TRUE;
PRBool disableIPv6 = PR_FALSE;
PRBool disablePrefetch = PR_FALSE;
int proxyType = nsProtocolProxyService::eProxyConfig_Direct;
nsAdoptingCString ipv4OnlyDomains;
@ -345,6 +347,9 @@ nsDNSService::Init()
prefs->GetBoolPref(kPrefDisableIPv6, &disableIPv6);
prefs->GetCharPref(kPrefIPv4OnlyDomains, getter_Copies(ipv4OnlyDomains));
prefs->GetBoolPref(kPrefDisablePrefetch, &disablePrefetch);
// If a manual proxy is in use, disable prefetch implicitly
prefs->GetIntPref("network.proxy.type", &proxyType);
}
if (firstTime) {
@ -360,6 +365,10 @@ nsDNSService::Init()
prefs->AddObserver(kPrefIPv4OnlyDomains, this, PR_FALSE);
prefs->AddObserver(kPrefDisableIPv6, this, PR_FALSE);
prefs->AddObserver(kPrefDisablePrefetch, this, PR_FALSE);
// Monitor these to see if there is a change in proxy configuration
// If a manual proxy is in use, disable prefetch implicitly
prefs->AddObserver("network.proxy.type", this, PR_FALSE);
}
}
@ -380,7 +389,9 @@ nsDNSService::Init()
mIDN = idn;
mIPv4OnlyDomains = ipv4OnlyDomains; // exchanges buffer ownership
mDisableIPv6 = disableIPv6;
mDisablePrefetch = disablePrefetch;
// Disable prefetching either by explicit preference or if a manual proxy is configured
mDisablePrefetch = disablePrefetch || (proxyType == nsProtocolProxyService::eProxyConfig_Manual);
}
nsDNSPrefetch::Initialize(this);
@ -415,7 +426,7 @@ nsDNSService::AsyncResolve(const nsACString &hostname,
{
nsAutoLock lock(mLock);
if (mDisablePrefetch && (flags & (RESOLVE_PRIORITY_LOW | RESOLVE_PRIORITY_MEDIUM)))
if (mDisablePrefetch && (flags & RESOLVE_SPECULATE))
return NS_ERROR_DNS_LOOKUP_QUEUE_FULL;
res = mResolver;

View File

@ -225,7 +225,8 @@ public:
RES_BYPASS_CACHE = 1 << 0,
RES_CANON_NAME = 1 << 1,
RES_PRIORITY_MEDIUM = 1 << 2,
RES_PRIORITY_LOW = 1 << 3
RES_PRIORITY_LOW = 1 << 3,
RES_SPECULATE = 1 << 4
};
private: