}   if (dlObserver && (nsnull != aURL)) { dlObserver->OnEndDocumentLoad(mDocLoader, channel, aStatus, aWebShell); }  if ( (mDocLoader == loader) && (aStatus == NS_ERROR_UNKNOWN_HOST) ) {         char *host = nsnull; nsString2 hostStr; rv = aURL->GetHost(&host); if (NS_FAILED(rv)) return rv;  hostStr.SetString(host); nsAllocator::Free(host); PRInt32 dotLoc = -1; dotLoc = hostStr.FindChar('.'); PRBool retry = PR_FALSE; if (-1 == dotLoc) { hostStr.Insert("www.", 0, 4); hostStr.Append(".com"); retry = PR_TRUE; } else if ( (hostStr.Length() - dotLoc) == 3) { hostStr.Insert("www.", 0, 4); retry = PR_TRUE; }  if (retry) { char *modHost = hostStr.ToNewCString(); if (!modHost) return NS_ERROR_OUT_OF_MEMORY; rv = aURL->SetHost(modHost); nsAllocator::Free(modHost); modHost = nsnull; if (NS_FAILED(rv)) return rv; char *aSpec = nsnull; rv = aURL->GetSpec(&aSpec); if (NS_FAILED(rv)) return rv; nsString2 newURL(aSpec);
if(dlObserver && aURL) dlObserver->OnEndDocumentLoad(mDocLoader, channel, aStatus);  if(mDocLoader == loader && NS_FAILED(aStatus)) { nsXPIDLCString host; nsresult hostResult = NS_ERROR_FAILURE; if (aURL) { hostResult = aURL->GetHost(getter_Copies(host)); } if (NS_SUCCEEDED(hostResult) && host) { CBufDescriptor buf((const char *)host, PR_TRUE, PL_strlen(host) + 1); nsCAutoString hostStr(buf); PRInt32 dotLoc = hostStr.FindChar('.');  nsXPIDLCString scheme; aURL->GetScheme(getter_Copies(scheme));  PRUint32 schemeLen = PL_strlen((const char*)scheme); CBufDescriptor schemeBuf((const char*)scheme, PR_TRUE, schemeLen+1, schemeLen); nsCAutoString schemeStr(schemeBuf);   if(aStatus == NS_ERROR_UNKNOWN_HOST || aStatus == NS_ERROR_CONNECTION_REFUSED || aStatus == NS_ERROR_NET_TIMEOUT) { PRBool keywordsEnabled = PR_FALSE; if(mPrefs) { NS_ENSURE_SUCCESS(mPrefs->GetBoolPref("keyword.enabled", &keywordsEnabled), NS_ERROR_FAILURE); }           static const char httpSchemeName[] = "http";  if (keywordsEnabled) { if (!schemeStr.IsEmpty() && ((schemeStr.Find(httpSchemeName)) != 0)) keywordsEnabled = PR_FALSE; }  if(keywordsEnabled && (-1 == dotLoc)) {  nsAutoString keywordSpec; keywordSpec.AssignWithConversion("keyword:"); keywordSpec.Append(NS_ConvertUTF8toUCS2(host)); return LoadURI(keywordSpec.GetUnicode(), LOAD_FLAGS_NONE); } }   if(aStatus == NS_ERROR_UNKNOWN_HOST) {  nsCAutoString retryHost;   if(schemeStr.Find("http") == 0) { if(-1 == dotLoc) { retryHost = "www."; retryHost += hostStr; retryHost += ".com"; } else { PRInt32 hostLen = hostStr.Length(); if(((hostLen - dotLoc) == 3) || ((hostLen - dotLoc) == 4)) { retryHost = "www."; retryHost += hostStr; } } }  if(!retryHost.IsEmpty()) { NS_ENSURE_SUCCESS(aURL->SetHost(retryHost.GetBuffer()), NS_ERROR_FAILURE); nsXPIDLCString aSpec; NS_ENSURE_SUCCESS(aURL->GetSpec(getter_Copies(aSpec)), NS_ERROR_FAILURE);
nsWebShell::OnEndDocumentLoad(nsIDocumentLoader* loader,                              nsIChannel* channel,                              nsresult aStatus,                              nsIDocumentLoaderObserver * aWebShell){#ifdef RAPTOR_PERF_METRICS  NS_STOP_STOPWATCH(mTotalTime)  RAPTOR_STOPWATCH_TRACE(("Total (Layout + Page Load) Time: "));  mTotalTime.Print();  RAPTOR_STOPWATCH_TRACE(("\n"));#endif  nsresult rv = NS_ERROR_FAILURE;  if (!channel) {    return NS_ERROR_NULL_POINTER;  }  nsCOMPtr<nsIURI> aURL;  rv = channel->GetURI(getter_AddRefs(aURL));  if (NS_FAILED(rv)) return rv;//if (!mProcessedEndDocumentLoad) {  if (loader == mDocLoader) {    mProcessedEndDocumentLoad = PR_TRUE;    if (nsnull != mScriptGlobal) {      nsIDocumentViewer* docViewer;      if (nsnull != mContentViewer &&          NS_OK == mContentViewer->QueryInterface(kIDocumentViewerIID, (void**)&docViewer)) {        nsIPresContext *presContext;        if (NS_OK == docViewer->GetPresContext(presContext)) {          nsEventStatus status = nsEventStatus_eIgnore;          nsMouseEvent event;          event.eventStructType = NS_EVENT;          event.message = NS_PAGE_LOAD;          rv = mScriptGlobal->HandleDOMEvent(*presContext, &event, nsnull, NS_EVENT_FLAG_INIT, status);          NS_RELEASE(presContext);        }        NS_RELEASE(docViewer);      }    }    // Fire the EndLoadURL of the web shell container    if (nsnull != aURL) {       nsAutoString urlString;       char* spec;       rv = aURL->GetSpec(&spec);       if (NS_SUCCEEDED(rv)) {         urlString = spec;         if (nsnull != mContainer) {            rv = mContainer->EndLoadURL(this, urlString.GetUnicode(), 0);         }         nsCRT::free(spec);       }    }    nsCOMPtr<nsIDocumentLoaderObserver> dlObserver;    if (!mDocLoaderObserver && mParent) {      /* If this is a frame (in which case it would have a parent && doesn't       * have a documentloaderObserver, get it from the rootWebShell       */      nsCOMPtr<nsIWebShell> root;      nsresult res = GetRootWebShell(*getter_AddRefs(root));      if (NS_SUCCEEDED(res) && root)        root->GetDocLoaderObserver(*getter_AddRefs(dlObserver));    }    else    {      /* Take care of the Trailing slash situation */      if (mSHist)        CheckForTrailingSlash(aURL);      dlObserver = do_QueryInterface(mDocLoaderObserver);  // we need this to addref    }    /*     * Fire the OnEndDocumentLoad of the DocLoaderobserver     */    if (dlObserver && (nsnull != aURL)) {       dlObserver->OnEndDocumentLoad(mDocLoader, channel, aStatus, aWebShell);    }    if ( (mDocLoader == loader) && (aStatus == NS_ERROR_UNKNOWN_HOST) ) {        // We need to check for a dns failure in aStatus, but dns failure codes        // aren't proliferated yet. This checks for failure for a host lacking        // "www." and/or ".com" and munges the url acordingly, then fires off        // a new request.        //        // XXX This code may or may not have mem leaks depending on the version        // XXX stdurl that is in the tree at a given point in time. This needs to        // XXX be fixed once we have a solid version of std url in.        char *host = nsnull;        nsString2 hostStr;        rv = aURL->GetHost(&host);        if (NS_FAILED(rv)) return rv;        hostStr.SetString(host);        nsAllocator::Free(host);        PRInt32 dotLoc = -1;        dotLoc = hostStr.FindChar('.');        PRBool retry = PR_FALSE;        if (-1 == dotLoc) {            hostStr.Insert("www.", 0, 4);            hostStr.Append(".com");            retry = PR_TRUE;        } else if ( (hostStr.Length() - dotLoc) == 3) {            hostStr.Insert("www.", 0, 4);            retry = PR_TRUE;        }        if (retry) {            char *modHost = hostStr.ToNewCString();            if (!modHost)                return NS_ERROR_OUT_OF_MEMORY;            rv = aURL->SetHost(modHost);            nsAllocator::Free(modHost);            modHost = nsnull;            if (NS_FAILED(rv)) return rv;            char *aSpec = nsnull;            rv = aURL->GetSpec(&aSpec);            if (NS_FAILED(rv)) return rv;            nsString2 newURL(aSpec);            // reload the url            const PRUnichar *spec = newURL.GetUnicode();            if (spec) {                rv = LoadURL(spec, "view");            }        } // retry    } // unknown host  } //!mProcessedEndDocumentLoad  else {    rv = NS_OK;  }  return rv;}