if (aModifyHistory && shist)  {
if (aModifyHistory && shist && (!isMail))  {
nsWebShell::LoadURL(const PRUnichar *aURLSpec,                    const char* aCommand,                    nsIInputStream* aPostDataStream,                    PRBool aModifyHistory,                    nsLoadFlags aType,                    const PRUint32 aLocalIP,                    nsISupports * aHistoryState,                    const PRUnichar* aReferrer){  nsresult rv;  /*      TODO This doesnt belong here... The app should be doing all this     URL play. The webshell should not have a clue about whats "mailto"      If you insist that this should be here, then put in URL parsing      optimizations here. -Gagan  */  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)) {      // KEYWORDS      // keyword failover      // we kick the following cases to the keyword server:      //   * starts with a '?'      //   * contains a space      //   * (windows only) is a single word (contains no dots or scheme) XXX: this breaks      //     intranet host lookups. This latter case needs to be handled by      //     dns notifications rather than string interrogation.      if (#ifdef XP_PC          // This is windows only because windows is the only platform that utilizes          // WINS resolution (a DNS fallback) which can take several minutes to          // fail a resolve call if the host does not exist. Thus, this forces us          // to bypass DNS/WINS altogether on windows.          (urlStr.FindChar('.') == -1) || #endif // XP_PC          (urlStr.First() == '?') || (urlStr.FindChar(' ') > -1) ) {          nsAutoString keywordSpec("keyword:");          keywordSpec.Append(aURLSpec);          rv = NS_NewURI(getter_AddRefs(uri), keywordSpec, nsnull);      }      if (NS_FAILED(rv)) {          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;          }      }    }  }  if (!uri) // we were unable to create a uri      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;  PRBool  isLoadingHistory=PR_FALSE; // Is SH currently loading an entry from history?  rv = GetRootWebShell(*getter_AddRefs(root));  // Get hold of session History  if (NS_SUCCEEDED(rv) && root) {        root->GetSessionHistory(*getter_AddRefs(shist));  }  if (shist)	  shist->GetLoadingFlag(&isLoadingHistory);  /*    * Save the history state for the current index iff this loadurl() request   * is not from SH. When the request comes from SH, aModifyHistory will   * be false and nsSessionHistory.cpp takes of this.   */  if (shist) {	 PRInt32  indix;     shist->GetCurrentIndex(&indix);     if (indix >= 0 && (aModifyHistory)) {       nsCOMPtr<nsISupports>  historyState;       rv = GetHistoryState(getter_AddRefs(historyState));	   if (NS_SUCCEEDED(rv) && historyState)          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);  /* Add the page to session history */  if (aModifyHistory && shist)  {        PRInt32  ret;        ret = shist->Add(spec, this);  }  nsCOMPtr<nsIWebShell> parent;  nsresult res = GetParent(*getter_AddRefs(parent));  nsAutoString urlstr;  if ((isLoadingHistory)) {	/* if LoadURL() got called from SH, AND If we are going "Back/Forward" 	 * to a frame page,SH  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.	 */     urlstr = mURL;  }  else{	/* If the call is not from SH, use the url passed by the caller	 * so that things like JS will work right. This is for bug # 1646.	 * May regress in other situations.	 * What a hack	 */     urlstr=spec;  }    nsCOMPtr<nsIURI>   newURI;  res = NS_NewURI(getter_AddRefs(newURI), urlstr, nsnull);  if (NS_SUCCEEDED(res)) {    // 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;}