convertFileToURL(urlStr, urlSpec); rv = NS_NewURI(getter_AddRefs(uri), urlSpec, nsnull); if (NS_FAILED(rv)) { NS_ASSERTION(mPrefs, "the webshell's pref service wasn't initialized");  rv = mPrefs->GetBoolPref("keyword.enabled", &keywordsEnabled); if (NS_FAILED(rv)) return rv;  PRInt32 qMarkLoc = -1, spaceLoc = -1;  if (keywordsEnabled) {              if (urlStr.FindChar('.') == -1 && urlStr.FindChar(':') == -1) { qMarkLoc = urlStr.FindChar('?'); spaceLoc = urlStr.FindChar(' ');  PRBool keyword = PR_FALSE; if (qMarkLoc == 0) { keyword = PR_TRUE; } else if ( (spaceLoc > 0) && ( (qMarkLoc == -1) || (spaceLoc < qMarkLoc) )) { keyword = PR_TRUE; }  if (keyword) { nsAutoString keywordSpec("keyword:"); keywordSpec.Append(aURLSpec); rv = NS_NewURI(getter_AddRefs(uri), keywordSpec, nsnull); } else { rv = NS_ERROR_FAILURE; } } else { rv = NS_ERROR_FAILURE; } } else { rv = NS_ERROR_FAILURE; }  PRInt32 colon = -1; if (NS_FAILED(rv)) { PRInt32 fSlash = urlSpec.FindChar('/'); PRUnichar port;  if ( ((colon=urlSpec.FindChar(':')) == -1) || ( (fSlash > -1) && (colon > fSlash) ) || ( (colon < urlSpec.Length()-1) && ((port=urlSpec.CharAt(colon+1)) <= '9') && (port > '0') )) {  PRInt32 hostPos = urlSpec.FindCharInSet("./:"); if (hostPos == -1) { hostPos = urlSpec.Length(); }   nsAutoString hostSpec; urlSpec.Left(hostSpec, hostPos);   if (hostSpec.EqualsIgnoreCase("ftp")) { urlSpec.Insert("ftp: } else { urlSpec.Insert("http: } }   if ((urlSpec.Find("mailto:", PR_TRUE)) >= 0) isMail = PR_TRUE;  if (!isMail) { rv = NS_NewURI(getter_AddRefs(uri), urlSpec, nsnull); if (NS_ERROR_UNKNOWN_PROTOCOL == rv) {  rv = InitDialogVars(); if (NS_FAILED(rv)) return rv;  nsXPIDLString messageStr; nsAutoString name("protocolNotFound"); rv = mStringBundle->GetStringFromName(name.GetUnicode(), getter_Copies(messageStr)); if (NS_FAILED(rv)) return rv;  NS_ASSERTION(colon != -1, "we shouldn't have gotten this far if we didn't have a colon");   nsAutoString scheme; urlSpec.Left(scheme, colon);  nsAutoString dnsMsg(scheme); dnsMsg.Append(' '); dnsMsg.Append(messageStr);  (void)mPrompter->Alert(dnsMsg.GetUnicode()); } } } } }  if (!uri) return rv;  rv = uri->GetSpec(getter_Copies(spec)); if (NS_FAILED(rv)) return rv;   nsCOMPtr<nsIWebShell>  root; nsCOMPtr<nsISessionHistory> shist; PRBool  isLoadingHistory=PR_FALSE; rv = GetRootWebShell(*getter_AddRefs(root));  if (NS_SUCCEEDED(rv) && root) { root->GetSessionHistory(*getter_AddRefs(shist)); } if (shist) shist->GetLoadingFlag(&isLoadingHistory);    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); } }  SetHistoryState(aHistoryState);   if (aModifyHistory && shist && (!isMail))  { PRInt32  ret; nsCAutoString referrer(aReferrer); ret = shist->Add(spec, referrer, this); }  nsCOMPtr<nsIWebShell> parent; nsresult res = GetParent(*getter_AddRefs(parent)); nsAutoString urlstr;  if ((isLoadingHistory)) {  urlstr = mURL; } else{  urlstr=spec; }  nsCOMPtr<nsIURI>   newURI; res = NS_NewURI(getter_AddRefs(newURI), urlstr, nsnull);  if (NS_SUCCEEDED(res)) {  return LoadURI(newURI, aCommand, aPostDataStream, aModifyHistory, aType, aLocalIP, aHistoryState, aReferrer, aWindowTarget); } return rv;
const char *cmd = mViewSource ? "view-source" : "view" ; mViewSource = PR_FALSE; return LoadURL(aURLSpec, cmd, aPostDataStream, aModifyHistory,aType, aLocalIP, aHistoryState, aReferrer);
nsWebShell::LoadURL(const PRUnichar *aURLSpec,                    const char* aCommand,                    nsIInputStream* aPostDataStream,                    PRBool aModifyHistory,                    nsLoadFlags aType,                    const PRUint32 aLocalIP,                    nsISupports * aHistoryState,                    const PRUnichar* aReferrer,                    const char * aWindowTarget){  nsresult rv = NS_OK;  PRBool isMail= PR_FALSE; // XXX mailto: hack  PRBool keywordsEnabled = PR_FALSE;  /*      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(" ");    // see if we've got a file url.    convertFileToURL(urlStr, urlSpec);    rv = NS_NewURI(getter_AddRefs(uri), urlSpec, nsnull);    if (NS_FAILED(rv)) {      NS_ASSERTION(mPrefs, "the webshell's pref service wasn't initialized");      rv = mPrefs->GetBoolPref("keyword.enabled", &keywordsEnabled);      if (NS_FAILED(rv)) return rv;      PRInt32 qMarkLoc = -1, spaceLoc = -1;      if (keywordsEnabled) {          // These are keyword formatted strings          // "what is mozilla"          // "what is mozilla?"          // "?mozilla"          // "?What is mozilla"          // These are not keyword formatted strings          // "www.blah.com" - anything with a dot in it           // "nonQualifiedHost:80" - anything with a colon in it          // "nonQualifiedHost?"          // "nonQualifiedHost?args"          // "nonQualifiedHost?some args"          if (urlStr.FindChar('.') == -1 && urlStr.FindChar(':') == -1) {              qMarkLoc = urlStr.FindChar('?');              spaceLoc = urlStr.FindChar(' ');              PRBool keyword = PR_FALSE;              if (qMarkLoc == 0) {                  keyword = PR_TRUE;              } else if ( (spaceLoc > 0) &&                           ( (qMarkLoc == -1) || (spaceLoc < qMarkLoc) )) {                    keyword = PR_TRUE;              }              if (keyword) {                  nsAutoString keywordSpec("keyword:");                  keywordSpec.Append(aURLSpec);                  rv = NS_NewURI(getter_AddRefs(uri), keywordSpec, nsnull);              } else {                  rv = NS_ERROR_FAILURE;              }          } else {              rv = NS_ERROR_FAILURE;          }      } else {          rv = NS_ERROR_FAILURE;      }      PRInt32 colon = -1;      if (NS_FAILED(rv)) {          PRInt32 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          // XXX mailto: hack          if ((urlSpec.Find("mailto:", PR_TRUE)) >= 0)              isMail = PR_TRUE;          if (!isMail) {              rv = NS_NewURI(getter_AddRefs(uri), urlSpec, nsnull);              if (NS_ERROR_UNKNOWN_PROTOCOL == rv) {                  // we weren't able to find a protocol handler                  rv = InitDialogVars();                  if (NS_FAILED(rv)) return rv;                  nsXPIDLString messageStr;                  nsAutoString name("protocolNotFound");                  rv = mStringBundle->GetStringFromName(name.GetUnicode(), getter_Copies(messageStr));                  if (NS_FAILED(rv)) return rv;                  NS_ASSERTION(colon != -1, "we shouldn't have gotten this far if we didn't have a colon");                  // extract the scheme                  nsAutoString scheme;                  urlSpec.Left(scheme, colon);                  nsAutoString dnsMsg(scheme);                  dnsMsg.Append(' ');                  dnsMsg.Append(messageStr);                  (void)mPrompter->Alert(dnsMsg.GetUnicode());              } // end unknown protocol          } // end !isMail      }   }  }  if (!uri) return rv;   rv = uri->GetSpec(getter_Copies(spec));   if (NS_FAILED(rv)) return rv;    // 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 && (!isMail))  {        PRInt32  ret;        nsCAutoString referrer(aReferrer);        ret = shist->Add(spec, referrer, 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, aWindowTarget);  }  return rv;}