nsIDocShell *docShell = global->GetDocShell();
nsIDocShell *docShell = window->GetDocShell();
DocumentViewerImpl::LoadComplete(nsresult aStatus){  nsresult rv = NS_OK;  NS_ENSURE_TRUE(mDocument, NS_ERROR_NOT_AVAILABLE);  // First, get the script global object from the document...  nsIScriptGlobalObject *global = mDocument->GetScriptGlobalObject();  // Fail if no ScriptGlobalObject is available...  NS_ENSURE_TRUE(global, NS_ERROR_NULL_POINTER);  mLoaded = PR_TRUE;  /* We need to protect ourself against auto-destruction in case the     window is closed while processing the OnLoad event.  See bug     http://bugzilla.mozilla.org/show_bug.cgi?id=78445 for more     explanation.  */  nsCOMPtr<nsIDocumentViewer> kungFuDeathGrip(this);  // Now, fire either an OnLoad or OnError event to the document...  PRBool restoring = PR_FALSE;  if(NS_SUCCEEDED(aStatus)) {    nsEventStatus status = nsEventStatus_eIgnore;    nsEvent event(PR_TRUE, NS_PAGE_LOAD);    // If the document presentation is being restored, we don't want to fire    // onload to the document content since that would likely confuse scripts    // on the page.    nsIDocShell *docShell = global->GetDocShell();    NS_ENSURE_TRUE(docShell, NS_ERROR_UNEXPECTED);    docShell->GetRestoringDocument(&restoring);    if (!restoring) {      rv = global->HandleDOMEvent(mPresContext, &event, nsnull,                                  NS_EVENT_FLAG_INIT, &status);#ifdef MOZ_TIMELINE      // if navigator.xul's load is complete, the main nav window is visible      // mark that point.      //printf("DEBUG: getting uri from document (%p)\n", mDocument.get());      nsIURI *uri = mDocument ? mDocument->GetDocumentURI() : nsnull;      if (uri) {        //printf("DEBUG: getting spec for uri (%p)\n", uri.get());        nsCAutoString spec;        uri->GetSpec(spec);        if (spec.EqualsLiteral("chrome://navigator/content/navigator.xul") ||            spec.EqualsLiteral("chrome://browser/content/browser.xul")) {          NS_TIMELINE_MARK("Navigator Window visible now");        }      }#endif /* MOZ_TIMELINE */    }  } else {    // XXX: Should fire error event to the document...  }  // Notify the document that it has been shown (regardless of whether  // it was just loaded). Note: mDocument may be null now if the above  // firing of onload caused the document to unload.  if (mDocument)    mDocument->OnPageShow(restoring);  // Now that the document has loaded, we can tell the presshell  // to unsuppress painting.  if (mPresShell && !mStopped) {    mPresShell->UnsuppressPainting();  }  static PRBool forcePaint    = PR_GetEnv("MOZ_FORCE_PAINT_AFTER_ONLOAD") != nsnull;  static PRUint32 index = 0;  if (forcePaint) {    nsCAutoString name(PR_GetEnv("MOZ_FORCE_PAINT_AFTER_ONLOAD"));    name.AppendLiteral("-");    ++index;    name.AppendInt(index);    DumpContentToPPM(name.get());  }#ifdef NS_PRINTING  // Check to see if someone tried to print during the load  if (mPrintIsPending) {    mPrintIsPending        = PR_FALSE;    mPrintDocIsFullyLoaded = PR_TRUE;    Print(mCachedPrintSettings, mCachedPrintWebProgressListner);    mCachedPrintSettings           = nsnull;    mCachedPrintWebProgressListner = nsnull;  }#endif  return rv;}