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

This commit is contained in:
Patrick McManus 2012-09-14 16:27:46 -04:00
Родитель d70af841f6
Коммит 35346a740a
5 изменённых файлов: 60 добавлений и 1 удалений

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

@ -1121,6 +1121,9 @@ pref("network.dns.disableIPv6", false);
// Default to 30 days. (basically forever)
pref("network.dnsCacheExpirationGracePeriod", 2592000);
// 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);

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

@ -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)

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

@ -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();

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

@ -496,6 +496,20 @@ nsDNSService::SetOffline(bool offline)
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

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

@ -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(26bd9b9e-90c3-11e1-981c-001fbc092072)]
[scriptable, uuid(6b16fb1f-5709-4c94-a89f-a22be873c54d)]
interface nsPIDNSService : nsIDNSService
{
/**
@ -27,6 +27,11 @@ interface nsPIDNSService : nsIDNSService
*/
void shutdown();
/**
* Whether or not DNS prefetching (aka RESOLVE_SPECULATE) is enabled
*/
attribute boolean prefetchEnabled;
/**
* @return whether the DNS service is offline.
*/