if (mPresShell) { mPresShell->FlushPendingNotifications(PR_TRUE); }
mDocument->FlushPendingNotifications(Flush_Display);
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...  if(NS_SUCCEEDED(aStatus)) {    nsEventStatus status = nsEventStatus_eIgnore;    nsEvent event(NS_PAGE_LOAD);    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.    if (mDocument) {      //printf("DEBUG: getting uri from document (%p)\n", mDocument.get());      nsIURI *uri = mDocument->GetDocumentURI();      if (uri) {        //printf("DEBUG: getting spec fro uri (%p)\n", uri.get());        nsCAutoString spec;        uri->GetSpec(spec);        if (!strcmp(spec.get(), "chrome://navigator/content/navigator.xul")) {          NS_TIMELINE_MARK("Navigator Window visible now");        }      }    }#endif /* MOZ_TIMELINE */  } else {    // XXX: Should fire error event to the document...  }  // 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;  if (forcePaint) {    if (mPresShell) {      mPresShell->FlushPendingNotifications(PR_TRUE);    }    nsIURI *uri = mDocument->GetDocumentURI();    nsCAutoString spec;    if (uri) {      uri->GetSpec(spec);    }    printf("GECKO: PAINT FORCED AFTER ONLOAD: %s\n", spec.get());    fflush(stdout);  }#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;}