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
authorshaver@mozilla.org
Tue, 25 Mar 2008 08:55:19 -0700
changeset 13535 ad2b60f9f80de0cb98651966c4720cedd909a8b6
parent 13534 80d9e8e6bfc0edfa74ac8844c3a7d43f7a435b45
child 13536 847345d7af8e94ba55636a755f9c43c7d2fbd616
push idunknown
push userunknown
push dateunknown
bugs235853
milestone1.9b5pre
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
netwerk/base/src/nsIOService.cpp
netwerk/base/src/nsProtocolProxyService.cpp
--- 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];