nsISupports * historyState=nsnull;
nsCOMPtr<nsISupports> historyState;
nsWebShell::LoadURI(nsIURI * aUri,                    const char * aCommand,                    nsIInputStream* aPostDataStream,                    PRBool aModifyHistory,                    nsLoadFlags aType,                    const PRUint32 aLocalIP,					          nsISupports * aHistoryState,                    const PRUnichar* aReferrer){  nsresult rv;  CancelRefreshURITimers();  nsXPIDLCString scheme, CUriSpec;  rv = aUri->GetScheme(getter_Copies(scheme));  if (NS_FAILED(rv)) return rv;  rv = aUri->GetSpec(getter_Copies(CUriSpec));  if (NS_FAILED(rv)) return rv;  nsAutoString uriSpec(CUriSpec);  nsXPIDLCString spec;  rv = aUri->GetSpec(getter_Copies(spec));  if (NS_FAILED(rv)) return rv;  /*   * Before the new page is added to the session history,   * save the history information of the previous page in   * session history   */   nsISupports * historyState=nsnull;   // Get the history object for the previous page.   rv = GetHistoryState(&historyState);   nsCOMPtr<nsIWebShell> rootWebShell;   rv = GetRootWebShell(*getter_AddRefs(rootWebShell));   if (NS_SUCCEEDED(rv) && rootWebShell) {      nsCOMPtr<nsISessionHistory> shist;      rv = rootWebShell->GetSessionHistory(*getter_AddRefs(shist));      if (NS_SUCCEEDED(rv) && shist) {        PRInt32 indix=0;        shist->getCurrentIndex(indix);        // Save it in session history        shist->SetHistoryObjectForIndex(indix, historyState);      }   }  /* If this is one of the frames, get it from the top level shell */  if (aModifyHistory) {    if (rootWebShell) {      nsCOMPtr<nsISessionHistory> shist;      rootWebShell->GetSessionHistory(*getter_AddRefs(shist));      /* Add yourself to the Session History */      if (shist) {        PRInt32  ret=0;        ret = shist->add(this);      }    }  }  /* 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);  nsString* url = new nsString(uriSpec);  if (aModifyHistory) {    // Discard part of history that is no longer reachable    PRInt32 i, n = mHistory.Count();    i = mHistoryIndex + 1;    while (--n >= i) {      nsString* u = (nsString*) mHistory.ElementAt(n);      delete u;      mHistory.RemoveElementAt(n);    }    // Tack on new url    mHistory.AppendElement(url);    mHistoryIndex++;  }  else {    // Replace the current history index with this URL    nsString* u = (nsString*) mHistory.ElementAt(mHistoryIndex);    if (nsnull != u) {      delete u;    }    mHistory.ReplaceElementAt(url, mHistoryIndex);  }  ShowHistory();  /* The session History may have changed the URL. So pass on the   * right one for loading   */  // Give web-shell-container right of refusal  if (nsnull != mContainer) {    nsAutoString str(spec);    rv = mContainer->WillLoadURL(this, str.GetUnicode(), nsLoadURL);    if (NS_FAILED(rv)) {      return rv;    }  }  return DoLoadURL(aUri, aCommand, aPostDataStream, aType, aLocalIP, aReferrer);}