if (!uri) return rv;
nsWebShell::LoadURL(const PRUnichar *aURLSpec,                    const char* aCommand,                    nsIInputStream* aPostDataStream,                    PRBool aModifyHistory,                    nsLoadFlags aType,                    const PRUint32 aLocalIP,                    nsISupports * aHistoryState,                    const PRUnichar* aReferrer){  nsresult rv;  nsAutoString urlStr(aURLSpec);  // first things first. try to create a uri out of the string.  nsCOMPtr<nsIURI> uri;  nsXPIDLCString  spec;  rv = NS_NewURI(getter_AddRefs(uri), urlStr, nsnull);  if (NS_FAILED(rv)) {    // no dice.    nsAutoString urlSpec;    urlStr.Trim(" ", PR_TRUE, PR_TRUE);    // see if we've got a file url.    convertFileToURL(urlStr, urlSpec);    rv = NS_NewURI(getter_AddRefs(uri), urlSpec, nsnull);    if (NS_FAILED(rv)) {      // no dice, try more tricks      PRInt32 colon, fSlash = urlSpec.FindChar('/');      PRUnichar port;      // if no scheme (protocol) is found, assume http.      if ( ((colon=urlSpec.FindChar(':')) == -1) // no colon at all           || ( (fSlash > -1) && (colon > fSlash) ) // the only colon comes after the first slash           || ( (colon < urlSpec.Length()-1) // the first char after the first colon is a digit (i.e. a port)                && ((port=urlSpec.CharAt(colon+1)) <= '9')                && (port > '0') )) {        // find host name        PRInt32 hostPos = urlSpec.FindCharInSet("./:");        if (hostPos == -1) {          hostPos = urlSpec.Length();        }        // extract host name        nsAutoString hostSpec;        urlSpec.Left(hostSpec, hostPos);        // insert url spec corresponding to host name        if (hostSpec.EqualsIgnoreCase("ftp")) {          urlSpec.Insert("ftp://", 0, 6);        } else {          urlSpec.Insert("http://", 0, 7);        }      } // end if colon      rv = NS_NewURI(getter_AddRefs(uri), urlSpec, nsnull);	  nsAutoString  url(aURLSpec);	  if (((url.Find("mailto:", PR_TRUE))<0) && (NS_FAILED(rv))) {        // no dice, even more tricks?        return rv;      }    }  }    //Take care of mailto: url  PRBool  isMail= PR_FALSE;  rv = uri->GetSpec(getter_Copies(spec));  if (NS_FAILED(rv))	   return rv;  nsAutoString urlAStr(spec);  if ((urlAStr.Find("mailto", PR_TRUE)) >= 0) {     isMail = PR_TRUE;  }  // Get hold of Root webshell  nsCOMPtr<nsIWebShell>  root;  nsCOMPtr<nsISessionHistory> shist;  rv = GetRootWebShell(*getter_AddRefs(root));  // Get hold of session History  if (NS_SUCCEEDED(rv) && root) {        root->GetSessionHistory(*getter_AddRefs(shist));  }  /* Ask the URL dispatcher to take care of this URL only if it is a   * mailto: link clicked inside a browser. Note this mechanism s'd go    * away once we have URL dispatcher in place.   */  if (root && isMail) {      //Ask the url Dispatcher to load the appropriate component for the URL.      nsCOMPtr<nsIUrlDispatcher>  urlDispatcher;      rv = root->GetUrlDispatcher(*getter_AddRefs(urlDispatcher));      if (NS_SUCCEEDED(rv) && urlDispatcher) {        urlDispatcher->HandleUrl(LinkCommand.GetUnicode(),                                 urlAStr.GetUnicode(), aPostDataStream);        return NS_OK;      }  }  /*   * Before the new page is added to the session history,   * save the history information of the previous page in   * session history   */   nsCOMPtr<nsISupports>  historyState=nsnull;   rv = GetHistoryState(getter_AddRefs(historyState));   // Get the history object for the previous page.   if (NS_SUCCEEDED(rv) && shist) {        PRInt32 indix=0;        shist->getCurrentIndex(indix);        // Save it in session history        shist->SetHistoryObjectForIndex(indix, historyState);   }  /* Set the History state object for the current page in the   * presentation shell. If it is a new page being visited,   * aHistoryState is null. If the load is coming from   * session History, it will be set to the cached history object by   * session History.   */  SetHistoryState(aHistoryState);   /*   * Set mURL to spec so that session history can get    * hold of the url and change it if it has to.   * See comments below.   */  mURL = spec;  /* Add the page to session history */  if (aModifyHistory && shist)  {        PRInt32  ret;        ret = shist->add(this);  }  /* If  we are going "Back" from a non-frame page to a frame page,   * session history  will change the mURL to the right value   * for smoother redraw. So, create a new nsIURI based on mURL,   * so that it will work right in such situations.   */  nsAutoString urlstr(mURL);  nsCOMPtr<nsIURI>   newURI;  rv = NS_NewURI(getter_AddRefs(newURI), urlstr, nsnull);  if (NS_SUCCEEDED(rv)) {    // now that we have a uri, call the REAL LoadURI method which requires a nsIURI.    return LoadURI(newURI, aCommand, aPostDataStream, aModifyHistory, aType, aLocalIP, aHistoryState, aReferrer);  }  return rv;}