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); } }
nsWebShell::OnEndDocumentLoad(nsIDocumentLoader* loader,                              nsIChannel* channel,                              nsresult aStatus){#ifdef MOZ_PERF_METRICS  MOZ_TIMER_DEBUGLOG(("Stop: nsWebShell::OnEndDocumentLoad(), this=%p\n", this));  MOZ_TIMER_STOP(mTotalTime);  MOZ_TIMER_LOG(("Total (Layout + Page Load) Time (webshell=%p): ", this));  MOZ_TIMER_PRINT(mTotalTime);#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;    // clean up reload state for meta charset  if(eCharsetReloadRequested == mCharsetReloadState)      mCharsetReloadState = eCharsetReloadStopOrigional;  else       mCharsetReloadState = eCharsetReloadInit;  /* 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);//if (!mProcessedEndDocumentLoad) {  if (loader == mDocLoader) {    mProcessedEndDocumentLoad = PR_TRUE;    if (mScriptGlobal && !mEODForCurrentDocument) {      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);      }    }    mEODForCurrentDocument = PR_TRUE;    // 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<nsIDocShellTreeItem> rootItem;      GetSameTypeRootTreeItem(getter_AddRefs(rootItem));      nsCOMPtr<nsIDocShell> rootDocShell(do_QueryInterface(rootItem));      if (rootDocShell)        rootDocShell->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);    }    if (mDocLoader == loader && NS_FAILED(aStatus)) {        nsAutoString errorMsg;        nsXPIDLCString host;        rv = aURL->GetHost(getter_Copies(host));        if (NS_FAILED(rv)) return rv;        CBufDescriptor buf((const char *)host, PR_TRUE, PL_strlen(host) + 1);        nsCAutoString hostStr(buf);        PRInt32 dotLoc = hostStr.FindChar('.');        if (aStatus == NS_ERROR_UNKNOWN_HOST            || aStatus == NS_ERROR_CONNECTION_REFUSED            || aStatus == NS_ERROR_NET_TIMEOUT) {            // First see if we should throw it to the keyword server.            NS_ASSERTION(mPrefs, "the webshell's pref service wasn't initialized");            PRBool keywordsEnabled = PR_FALSE;            rv = mPrefs->GetBoolPref("keyword.enabled", &keywordsEnabled);            if (NS_FAILED(rv)) return rv;            if (keywordsEnabled && (-1 == dotLoc)) {                // only send non-qualified hosts to the keyword server                nsAutoString keywordSpec("keyword:");                keywordSpec.Append(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;            nsXPIDLCString scheme;            rv = aURL->GetScheme(getter_Copies(scheme));            if (NS_FAILED(rv)) return rv;            PRUint32 schemeLen = PL_strlen((const char*)scheme);            CBufDescriptor schemeBuf((const char*)scheme, PR_TRUE, schemeLen+1, schemeLen);            nsCAutoString schemeStr(schemeBuf);            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()) {                rv = aURL->SetHost(retryHost.GetBuffer());                if (NS_FAILED(rv)) return rv;                nsXPIDLCString aSpec;                rv = aURL->GetSpec(getter_Copies(aSpec));                if (NS_FAILED(rv)) return rv;                nsAutoString newURL(aSpec);                // reload the url                return LoadURI(newURL.GetUnicode());            } // retry            // throw a DNS failure dialog            rv = InitDialogVars();            if (NS_FAILED(rv)) return rv;            nsXPIDLString messageStr;            nsAutoString name("dnsNotFound");            rv = mStringBundle->GetStringFromName(name.GetUnicode(), getter_Copies(messageStr));            if (NS_FAILED(rv)) return rv;            errorMsg.Assign(host);            errorMsg.Append(' ');            errorMsg.Append(messageStr);            (void)mPrompter->Alert(errorMsg.GetUnicode());        } else // unknown host        // Doc failed to load because we couldn't connect to the server.        if (aStatus == NS_ERROR_CONNECTION_REFUSED) {            // throw a connection failure dialog            PRInt32 port = -1;            rv = aURL->GetPort(&port);            if (NS_FAILED(rv)) return rv;                        rv = InitDialogVars();            if (NS_FAILED(rv)) return rv;            nsXPIDLString messageStr;            nsAutoString name("connectionFailure");            rv = mStringBundle->GetStringFromName(name.GetUnicode(), getter_Copies(messageStr));            if (NS_FAILED(rv)) return rv;            errorMsg.Assign(messageStr);            errorMsg.Append(' ');            errorMsg.Append(host);            if (port > 0) {                errorMsg.Append(':');                errorMsg.Append(port);            }            errorMsg.Append('.');            (void)mPrompter->Alert(errorMsg.GetUnicode());        } else // end NS_ERROR_CONNECTION_REFUSED        // Doc failed to load because the socket function timed out.        if (aStatus == NS_ERROR_NET_TIMEOUT) {            // throw a timeout dialog            rv = InitDialogVars();            if (NS_FAILED(rv)) return rv;            nsXPIDLString messageStr;            nsAutoString name("netTimeout");            rv = mStringBundle->GetStringFromName(name.GetUnicode(), getter_Copies(messageStr));            if (NS_FAILED(rv)) return rv;            errorMsg.Assign(messageStr);            errorMsg.Append(' ');            errorMsg.Append(host);            errorMsg.Append('.');            (void)mPrompter->Alert(errorMsg.GetUnicode());                    } // end NS_ERROR_NET_TIMEOUT    } // end mDocLoader == loader  } //!mProcessedEndDocumentLoad  else {    rv = NS_OK;  }  return rv;}