bug 507578 - disable dns prefetch in presence of active proxy r=jduell

This commit is contained in:
Patrick McManus 2012-09-13 15:22:56 -04:00
parent 22205a5249
commit 3d38be24d9
5 changed files with 60 additions and 1 deletions

View File

@ -1122,6 +1122,9 @@ pref("network.dns.ipv4OnlyDomains", "");
// This preference can be used to turn off IPv6 name lookups. See bug 68796.
pref("network.dns.disableIPv6", false);
// This preference can be used to turn off DNS prefetch.
pref("network.dns.disablePrefetch", false);
// This preference controls whether or not URLs with UTF-8 characters are
// escaped. Set this preference to TRUE for strict RFC2396 conformance.
pref("network.standard-url.escape-utf8", true);

View File

@ -18,6 +18,7 @@
#include "nsIProtocolProxyCallback.h"
#include "nsICancelable.h"
#include "nsIDNSService.h"
#include "nsPIDNSService.h"
#include "nsIPrefService.h"
#include "nsIPrefBranch.h"
#include "nsReadableUtils.h"
@ -200,6 +201,8 @@ private:
mProxyInfo = nullptr;
LOG(("pac thread callback %s\n", mPACString.get()));
if (NS_SUCCEEDED(mStatus))
mPPS->MaybeDisableDNSPrefetch(mProxyInfo);
mCallback->OnProxyAvailable(this, mURI, mProxyInfo, mStatus);
}
else if (NS_SUCCEEDED(mStatus) && !mPACURL.IsEmpty()) {
@ -222,6 +225,8 @@ private:
}
else {
LOG(("pac thread callback did not provide information %X\n", mStatus));
if (NS_SUCCEEDED(mStatus))
mPPS->MaybeDisableDNSPrefetch(mProxyInfo);
mCallback->OnProxyAvailable(this, mURI, mProxyInfo, mStatus);
}
@ -1604,6 +1609,30 @@ nsProtocolProxyService::Resolve_Internal(nsIURI *uri,
return NS_OK;
}
void
nsProtocolProxyService::MaybeDisableDNSPrefetch(nsIProxyInfo *aProxy)
{
// Disable Prefetch in the DNS service if a proxy is in use.
if (!aProxy)
return;
nsCOMPtr<nsProxyInfo> pi = do_QueryInterface(aProxy);
if (!pi ||
!pi->mType ||
pi->mType == kProxyType_DIRECT)
return;
nsCOMPtr<nsIDNSService> dns = do_GetService(NS_DNSSERVICE_CONTRACTID);
if (!dns)
return;
nsCOMPtr<nsPIDNSService> pdns = do_QueryInterface(dns);
if (!pdns)
return;
// We lose the prefetch optimization for the life of the dns service.
pdns->SetPrefetchEnabled(false);
}
void
nsProtocolProxyService::ApplyFilters(nsIURI *uri, const nsProtocolInfo &info,
nsIProxyInfo **list)

View File

@ -271,6 +271,14 @@ protected:
*/
NS_HIDDEN_(bool) CanUseProxy(nsIURI *uri, int32_t defaultPort);
/**
* Disable Prefetch in the DNS service if a proxy is in use.
*
* @param aProxy
* The proxy information
*/
NS_HIDDEN_(void) MaybeDisableDNSPrefetch(nsIProxyInfo *aProxy);
private:
nsresult SetupPACThread();
nsresult ResetPACThread();

View File

@ -482,6 +482,20 @@ nsDNSService::Shutdown()
return NS_OK;
}
NS_IMETHODIMP
nsDNSService::GetPrefetchEnabled(bool *outVal)
{
*outVal = !mDisablePrefetch;
return NS_OK;
}
NS_IMETHODIMP
nsDNSService::SetPrefetchEnabled(bool inVal)
{
mDisablePrefetch = !inVal;
return NS_OK;
}
namespace {
class DNSListenerProxy MOZ_FINAL : public nsIDNSListener

View File

@ -10,7 +10,7 @@
* This is a private interface used by the internals of the networking library.
* It will never be frozen. Do not use it in external code.
*/
[scriptable, uuid(a26c5b45-7707-4412-bbc1-2462b890848d)]
[scriptable, uuid(6b16fb1f-5709-4c94-a89f-a22be873c54d)]
interface nsPIDNSService : nsIDNSService
{
/**
@ -26,4 +26,9 @@ interface nsPIDNSService : nsIDNSService
* this method.
*/
void shutdown();
/**
* Whether or not DNS prefetching (aka RESOLVE_SPECULATE) is enabled
*/
attribute boolean prefetchEnabled;
};