if(dlObserver && aURL) dlObserver->OnEndDocumentLoad(mDocLoader, channel, aStatus);
if (dlObserver && (nsnull != aURL)) { dlObserver->OnEndDocumentLoad(mDocLoader, channel, aStatus, aWebShell); }
nsWebShell::OnEndDocumentLoad(nsIDocumentLoader* loader,                              nsIChannel* channel,                              nsresult aStatus){   if(loader != mDocLoader)      return NS_OK;   nsresult rv = NS_OK;   if(!channel)      return NS_ERROR_NULL_POINTER;   nsCOMPtr<nsIURI> aURL;   NS_ENSURE_SUCCESS(channel->GetURI(getter_AddRefs(aURL)), NS_ERROR_FAILURE);     // clean up reload state for meta charset   if(eCharsetReloadRequested == mCharsetReloadState)      mCharsetReloadState = eCharsetReloadStopOrigional;   else       mCharsetReloadState = eCharsetReloadInit;   // Clear the LSHE reference in docshell to indicate document loading   // is done one way or another.   LSHE = nsnull;   /* one of many safeguards that prevent death and destruction if      someone is so very very rude as to bring this window down      during this load handler. */   nsCOMPtr<nsIWebShell> kungFuDeathGrip(this);   // Notify the ContentViewer that the Document has finished loading...   if (!mEODForCurrentDocument && mContentViewer) {     mContentViewer->LoadComplete(aStatus);   }   mEODForCurrentDocument = PR_TRUE;   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<nsIDocShellTreeItem> rootItem;      GetSameTypeRootTreeItem(getter_AddRefs(rootItem));      nsCOMPtr<nsIDocShell> rootDocShell(do_QueryInterface(rootItem));      if(rootDocShell)         rootDocShell->GetDocLoaderObserver(getter_AddRefs(dlObserver));      }   else      dlObserver = do_QueryInterface(mDocLoaderObserver);  // we need this to addref   /*    * Fire the OnEndDocumentLoad of the DocLoaderobserver    */   if(dlObserver && aURL)      dlObserver->OnEndDocumentLoad(mDocLoader, channel, aStatus);   if(mDocLoader == loader && NS_FAILED(aStatus))      {      nsXPIDLCString host;      nsresult 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;         NS_ENSURE_SUCCESS(mPrefs->GetBoolPref("keyword.enabled", &keywordsEnabled),            NS_ERROR_FAILURE);                  // we should only perform a keyword search under the following conditions:         // (1) the url scheme is http (or https)         // (2) the url does not have a protocol scheme         // If we don't enforce such a policy, then we end up doing keyword searchs on urls         // we don't intend like imap, file, mailbox, etc. This could lead to a security         // problem where we send data to the keyword server that we shouldn't be.          // Someone needs to clean up keywords in general so we can determine on a per url basis         // if we want keywords enabled...this is just a bandaid...         static const char httpSchemeName[] = "http";         if (schemeStr.IsEmpty()  || !schemeStr.Find(httpSchemeName) )           keywordsEnabled = PR_TRUE; // keep keywors enabled for this url         else           keywordsEnabled = PR_FALSE; // all other cases, disable keywords for this url.         if(keywordsEnabled && (-1 == dotLoc))            {            // only send non-qualified hosts to the keyword server            nsAutoString keywordSpec; keywordSpec.AssignWithConversion("keyword:");            keywordSpec.Append(NS_ConvertUTF8toUCS2(host));            return LoadURI(keywordSpec.GetUnicode());            } // end keywordsEnabled         }      // Doc failed to load because the host was not found.      if(aStatus == NS_ERROR_UNKNOWN_HOST)         {         // Try our www.*.com trick.         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);            // reload the url            return LoadURI(NS_ConvertASCIItoUCS2(aSpec).GetUnicode());            } // retry         // throw a DNS failure dialog         nsCOMPtr<nsIPrompt> prompter;         nsCOMPtr<nsIStringBundle> stringBundle;         GetPromptAndStringBundle(getter_AddRefs(prompter),             getter_AddRefs(stringBundle));         NS_ENSURE_TRUE(stringBundle, NS_ERROR_FAILURE);         nsXPIDLString messageStr;         NS_ENSURE_SUCCESS(stringBundle->GetStringFromName(            NS_ConvertASCIItoUCS2("dnsNotFound").GetUnicode(),             getter_Copies(messageStr)), NS_ERROR_FAILURE);         if (host) {             PRUnichar *msg = nsTextFormatter::smprintf(messageStr, (const char*)host);             if (!msg) return NS_ERROR_OUT_OF_MEMORY;             prompter->Alert(nsnull, msg);             nsTextFormatter::smprintf_free(msg);             }         }       else if(aStatus == NS_ERROR_CONNECTION_REFUSED)         {// Doc failed to load because we couldn't connect to the server.         // throw a connection failure dialog         PRInt32 port = -1;         NS_ENSURE_SUCCESS(aURL->GetPort(&port), NS_ERROR_FAILURE);                    nsCOMPtr<nsIPrompt> prompter;           nsCOMPtr<nsIStringBundle> stringBundle;           GetPromptAndStringBundle(getter_AddRefs(prompter),               getter_AddRefs(stringBundle));           NS_ENSURE_TRUE(stringBundle, NS_ERROR_FAILURE);           nsXPIDLString messageStr;           NS_ENSURE_SUCCESS(stringBundle->GetStringFromName(              NS_ConvertASCIItoUCS2("connectionFailure").GetUnicode(),               getter_Copies(messageStr)), NS_ERROR_FAILURE);           // build up the host:port string.           nsCAutoString combo(host);           if (port > 0) {               combo.Append(':');               combo.AppendInt(port);           }           PRUnichar *msg = nsTextFormatter::smprintf(messageStr, combo.GetBuffer());           if (!msg) return NS_ERROR_OUT_OF_MEMORY;           prompter->Alert(nsnull, msg);           nsTextFormatter::smprintf_free(msg);           }         else if(aStatus == NS_ERROR_NET_TIMEOUT)           {// Doc failed to load because the socket function timed out.           // throw a timeout dialog           nsCOMPtr<nsIPrompt> prompter;           nsCOMPtr<nsIStringBundle> stringBundle;           GetPromptAndStringBundle(getter_AddRefs(prompter),               getter_AddRefs(stringBundle));           NS_ENSURE_TRUE(stringBundle, NS_ERROR_FAILURE);           nsXPIDLString messageStr;           NS_ENSURE_SUCCESS(stringBundle->GetStringFromName(              NS_ConvertASCIItoUCS2("netTimeout").GetUnicode(),               getter_Copies(messageStr)), NS_ERROR_FAILURE);           PRUnichar *msg = nsTextFormatter::smprintf(messageStr, (const char*)host);           if (!msg) return NS_ERROR_OUT_OF_MEMORY;           prompter->Alert(nsnull, msg);                       nsTextFormatter::smprintf_free(msg);           } // end NS_ERROR_NET_TIMEOUT        } // if we have a host      } // end mDocLoader == loader      return rv;}