mProcessedEndDocumentLoad = PR_FALSE;
mProcessedEndDocumentLoad = PR_FALSE;  if (NS_SUCCEEDED(rv)) { mURL = urlSpec; mReferrer = aReferrer; }
nsWebShell::DoLoadURL(nsIURI * aUri,                      const char* aCommand,                      nsIInputStream* aPostDataStream,                      nsLoadFlags aType,                      const PRUint32 aLocalIP,                      const PRUnichar* aReferrer,                      PRBool aKickOffLoad){  if (!aUri)    return NS_ERROR_NULL_POINTER;  // This should probably get saved in mHistoryService or something...   // Ugh. It sucks that we have to hack webshell like this. Forgive me, Father.  do {    nsresult rv;    NS_WITH_SERVICE(nsIGlobalHistory, history, "component://netscape/browser/global-history", &rv);    if (NS_FAILED(rv)) break;    rv = history->AddPage(nsCAutoString(mURL), nsnull /* referrer */, PR_Now());    if (NS_FAILED(rv)) break;  } while (0);  nsXPIDLCString urlSpec;  nsresult rv = NS_OK;  rv = aUri->GetSpec(getter_Copies(urlSpec));  if (NS_FAILED(rv)) return rv;  // If it's a normal reload that uses the cache, look at the destination anchor  // and see if it's an element within the current document  // We don't have a reload loadtype yet in necko. So, check for just history  // loadtype  if ((aType == nsISessionHistory::LOAD_HISTORY || aType == nsIChannel::LOAD_NORMAL) && (nsnull != mContentViewer) &&      (nsnull == aPostDataStream))  {    nsCOMPtr<nsIDocumentViewer> docViewer;    if (NS_SUCCEEDED(mContentViewer->QueryInterface(kIDocumentViewerIID,                                                    getter_AddRefs(docViewer)))) {      // Get the document object      nsCOMPtr<nsIDocument> doc;      docViewer->GetDocument(*getter_AddRefs(doc));      // Get the URL for the document      nsCOMPtr<nsIURI>  docURL = nsDontAddRef<nsIURI>(doc->GetDocumentURL());      if (aUri && docURL && EqualBaseURLs(docURL, aUri)) {        // See if there's a destination anchor        nsXPIDLCString ref;        nsCOMPtr<nsIURL> aUrl = do_QueryInterface(aUri);        if (aUrl)          rv = aUrl->GetRef(getter_Copies(ref));        nsCOMPtr<nsIPresShell> presShell;        rv = docViewer->GetPresShell(*getter_AddRefs(presShell));        if (NS_SUCCEEDED(rv) && presShell) {           /* Pass OnStartDocument notifications to the docloaderobserver            * so that urlbar, forward/back buttons will            * behave properly when going to named anchors            */           nsCOMPtr<nsIChannel> dummyChannel;           rv = NS_OpenURI(getter_AddRefs(dummyChannel), aUri, nsnull);           if (NS_FAILED(rv)) return rv;           if (nsnull != (const char *) ref) {              rv = OnStartDocumentLoad(mDocLoader, aUri, "load");              // Go to the anchor in the current document              rv = presShell->GoToAnchor(nsAutoString(ref));            		          mProcessedEndDocumentLoad = PR_FALSE;		          // Pass on status of scrolling/anchor visit to docloaderobserver              rv = OnEndDocumentLoad(mDocLoader, dummyChannel, rv, this);		          return rv;		              }           else if (aType == nsISessionHistory::LOAD_HISTORY)           {              rv = OnStartDocumentLoad(mDocLoader, aUri, "load");              // Go to the top of the current document              nsCOMPtr<nsIViewManager> viewMgr;              rv = presShell->GetViewManager(getter_AddRefs(viewMgr));              if (NS_SUCCEEDED(rv) && viewMgr) {                nsIScrollableView* view;                rv = viewMgr->GetRootScrollableView(&view);				        if (NS_SUCCEEDED(rv) && view)                  rv = view->ScrollTo(0, 0, NS_VMREFRESH_IMMEDIATE);                mProcessedEndDocumentLoad = PR_FALSE;		            // Pass on status of scrolling/anchor visit to docloaderobserver                rv = OnEndDocumentLoad(mDocLoader, dummyChannel, rv, this);		            return rv;		                 }           }#if 0        		   		   mProcessedEndDocumentLoad = PR_FALSE;		   // Pass on status of scrolling/anchor visit to docloaderobserver           rv = OnEndDocumentLoad(mDocLoader, dummyChannel, rv, this);		   return rv;		   #endif /* 0 */        }  // NS_SUCCEEDED(rv) && presShell      } // EqualBaseURLs(docURL, url)    }  }  // Stop loading the current document (if any...).  This call may result in  // firing an EndLoadURL notification for the old document...  StopBeforeRequestingURL();    // Tell web-shell-container we are loading a new url  if (nsnull != mContainer) {    nsAutoString uniSpec (urlSpec);    rv = mContainer->BeginLoadURL(this, uniSpec.GetUnicode());    if (NS_FAILED(rv)) {      return rv;    }  }  mProcessedEndDocumentLoad = PR_FALSE;#ifdef MOZ_PERF_METRICS  {     char* url;     nsresult rv = NS_OK;     rv = aUri->GetSpec(&url);     if (NS_SUCCEEDED(rv)) {       MOZ_TIMER_LOG(("*** Timing layout processes on url: '%s', webshell: %p\n", url, this));       delete [] url;     }  }    MOZ_TIMER_DEBUGLOG(("Reset and start: nsWebShell::DoLoadURL(), this=%p\n", this));  MOZ_TIMER_RESET(mTotalTime);  MOZ_TIMER_START(mTotalTime);#endif /* WebShell was primarily passing the buck when it came to streamObserver.  * So, pass on the observer which is already a streamObserver to DocLoder.  */  if (aKickOffLoad)    rv = mDocLoader->LoadDocument(aUri,        // URL string                                  aCommand,        // Command                                  NS_STATIC_CAST(nsIContentViewerContainer*, this),// Container                                  aPostDataStream, // Post Data                                  nsnull,          // Extra Info...                                  aType,           // reload type                                  aLocalIP,        // load attributes.                                  aReferrer);      // referrer    // Fix for bug 1646.  Change the notion of current url and referrer only after  // the document load succeeds.  if (NS_SUCCEEDED(rv)) {    mURL = urlSpec;    mReferrer = aReferrer;  }  return rv;}