Bug 235853: don't freeze the UI when resolving DNS for PAC, by using deferred resolution if we would otherwise block on DNS. r+madskills=biesi, a-b5=mconnor
--- a/netwerk/base/src/nsIOService.cpp
+++ b/netwerk/base/src/nsIOService.cpp
@@ -545,17 +545,27 @@ nsIOService::NewChannelFromURI(nsIURI *a
if (protoFlags & nsIProtocolHandler::ALLOWS_PROXY) {
nsCOMPtr<nsIProxyInfo> pi;
if (!mProxyService) {
mProxyService = do_GetService(NS_PROTOCOLPROXYSERVICE_CONTRACTID);
if (!mProxyService)
NS_WARNING("failed to get protocol proxy service");
}
if (mProxyService) {
- rv = mProxyService->Resolve(aURI, 0, getter_AddRefs(pi));
+ PRUint32 flags = 0;
+ if (scheme.EqualsLiteral("http") || scheme.EqualsLiteral("https"))
+ flags = nsIProtocolProxyService::RESOLVE_NON_BLOCKING;
+ rv = mProxyService->Resolve(aURI, flags, getter_AddRefs(pi));
+ if (rv == NS_BASE_STREAM_WOULD_BLOCK) {
+ // Use an UNKNOWN proxy to defer resolution and avoid blocking.
+ rv = mProxyService->NewProxyInfo(NS_LITERAL_CSTRING("unknown"),
+ NS_LITERAL_CSTRING(""),
+ -1, 0, 0, nsnull,
+ getter_AddRefs(pi));
+ }
if (NS_FAILED(rv))
pi = nsnull;
}
if (pi) {
nsCAutoString type;
if (NS_SUCCEEDED(pi->GetType(type)) && type.EqualsLiteral("http")) {
// we are going to proxy this channel using an http proxy
rv = GetProtocolHandler("http", getter_AddRefs(handler));
--- a/netwerk/base/src/nsProtocolProxyService.cpp
+++ b/netwerk/base/src/nsProtocolProxyService.cpp
@@ -918,17 +918,18 @@ nsProtocolProxyService::NewProxyInfo(con
PRUint32 aFailoverTimeout,
nsIProxyInfo *aFailoverProxy,
nsIProxyInfo **aResult)
{
static const char *types[] = {
kProxyType_HTTP,
kProxyType_SOCKS,
kProxyType_SOCKS4,
- kProxyType_DIRECT
+ kProxyType_DIRECT,
+ kProxyType_UNKNOWN
};
// resolve type; this allows us to avoid copying the type string into each
// proxy info instance. we just reference the string literals directly :)
const char *type = nsnull;
for (PRUint32 i=0; i<NS_ARRAY_LENGTH(types); ++i) {
if (aType.LowerCaseEqualsASCII(types[i])) {
type = types[i];