nsCOMPtr<nsIWebShell> root; nsresult res = GetRootWebShell(*getter_AddRefs(root));  if (NS_SUCCEEDED(res) && root) root->GetDocLoaderObserver(*getter_AddRefs(dlObserver)); } else {  if (mSHist) CheckForTrailingSlash(aURL);
nsCOMPtr<nsIDocShellTreeItem> rootItem; GetSameTypeRootTreeItem(getter_AddRefs(rootItem)); nsCOMPtr<nsIDocShell> rootDocShell(do_QueryInterface(rootItem));  if(rootDocShell) rootDocShell->GetDocLoaderObserver(getter_AddRefs(dlObserver)); } else
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;}