NS_ASSERTION(0, "nsSessionHistory::add, Couldn't get root webshell"); return NS_OK;
nsSessionHistory::add(nsIWebShell * aWebShell){  //nsresult  rv = NS_OK;   nsHistoryEntry * hEntry = nsnull;   nsIWebShell * parent = nsnull;   if (!aWebShell) {      return NS_ERROR_NULL_POINTER;   }   aWebShell->GetParent(parent);   if (!parent) {     if(mIsLoadingDoc) {        /* We are currently loading a history entry */                nsresult ret = mHistoryEntryInLoad->Load(aWebShell);        if (!ret) {          /* The interim page matches exactly with the one in history.           * So, don't need to keep it around. Clear all flags and           * return.           */             mIsLoadingDoc =  PR_FALSE;                mHistoryEntryInLoad = (nsHistoryEntry *)nsnull;        }        return NS_OK;           }  // mIsLoadingDoc      hEntry = new nsHistoryEntry();      if (!hEntry) {         NS_ASSERTION(PR_FALSE, "nsSessionHistory::add Low memory");         return NS_ERROR_OUT_OF_MEMORY;      }      hEntry->Create(aWebShell, nsnull, this);      /* Set the flag in webshell that indicates that it has been       * added to session History        */      aWebShell->SetIsInSHist(PR_TRUE);      // Add the URL  to the history      if ((mHistoryLength - (mHistoryCurrentIndex+1)) > 0) {      /* We are somewhere in the middle of the history and a       * new page was visited. Purge all entries from the current index       * till the end of the list and append the current page to the       * list       */       for(int i=mHistoryLength-1; i>mHistoryCurrentIndex; i--) {          nsHistoryEntry * hEntry2 = (nsHistoryEntry *)mHistoryEntries.ElementAt(i);          //NS_IF_RELEASE(hEntry2);          delete hEntry2;          mHistoryEntries.RemoveElementAt(i);          mHistoryLength--;       }     }     mHistoryEntries.AppendElement((void *)hEntry);     mHistoryLength++;     mHistoryCurrentIndex++;             return NS_OK;   }   // (!mParent)   else {       /* This is a frame webshell. Check if it is a new frame. If so,       * append to the existing history entry. Else, create a        * new tree to record the change in URL        */           PRBool inSHist = PR_TRUE;         aWebShell->GetIsInSHist(inSHist);      if (!inSHist) {         nsHistoryEntry * curEntry=nsnull, * newEntry=nsnull,                         * parentEntry=nsnull;         if (!mIsLoadingDoc) {           /*This is a newly created frame. Just add it to the current entry */           // Get a handle to the parent of the new frame WS;           nsIWebShell * parentWS = nsnull;           aWebShell->GetParent(parentWS);           curEntry = (nsHistoryEntry *) mHistoryEntries.ElementAt(mHistoryCurrentIndex);              // Get the history entry corresponding to the parentWS           if (curEntry)              parentEntry = curEntry->GetHistoryForWS(parentWS);           // Create a new HistoryEntry for the frame & init values           newEntry = new nsHistoryEntry();           if (!newEntry) {             NS_ASSERTION(PR_FALSE, "nsSessionHistory::add Low memory");             return NS_ERROR_OUT_OF_MEMORY;           }           newEntry->Create(aWebShell, parentEntry, this);           aWebShell->SetIsInSHist(PR_TRUE);         }  // !mIsLoadingDoc         else {          /* We are in the middle of loading a page. Pass it on to Load           * to  check if we are loading the right page           */          PRBool ret=PR_TRUE;                    nsIWebShell * root=nsnull;          aWebShell->GetRootWebShell(root);          if (!root) {			  NS_ASSERTION(0,"fix me");#ifdef DEBUG			printf("fix me\n");#endif            return NS_OK;          }		  ret = mHistoryEntryInLoad->Load(root);          if (!ret) {            /* The interim page matches exactly with the one in history.             * Clear all flags and return.             */                           mIsLoadingDoc =  PR_FALSE;                     mHistoryEntryInLoad = (nsHistoryEntry *)nsnull;            }  //!ret            aWebShell->SetIsInSHist(PR_TRUE);          }          }  // !InSHist       else  {          /* THis page is in history. May be the frame page changed. */          if (!mIsLoadingDoc) {             /* We are not in the middle of loading a history entry. Add this              * to the history entry              */             nsIWebShell * root = nsnull;             nsHistoryEntry * newEntry = nsnull;             aWebShell->GetRootWebShell(root);               if (root)                   newEntry = GenerateTree(root, nsnull, this);             if (newEntry) {                if ((mHistoryLength - (mHistoryCurrentIndex+1)) > 0) {                /* We are somewhere in the middle of the history and a                 *  new page was visited. Purge all entries from the current                  * index till the end of the list and append the current                  * page to the list                 */                for(int i=mHistoryLength-1; i>mHistoryCurrentIndex; i--) {                   nsHistoryEntry * hEntry = (nsHistoryEntry *)mHistoryEntries.ElementAt(i);                   //NS_IF_RELEASE(hEntry);                   delete hEntry;                   mHistoryEntries.RemoveElementAt(i);                   mHistoryLength--;                 }              }              mHistoryEntries.AppendElement((void *)newEntry);              mHistoryLength++;              mHistoryCurrentIndex++;                      return NS_OK;             }  //newEntry           }  // (!mIsLoadingDoc)           else   {                      /* We are in the middle of loading a history entry.               * Send it to Load() for Comparison purposes               */              nsIWebShell * root=nsnull;              aWebShell->GetRootWebShell(root);              if (!root) {#ifdef DEBUG 	       printf("fix build bustage.  someone needs to look at this.\n");#endif               return NS_OK;                 }              nsresult ret = mHistoryEntryInLoad->Load(root);              if (!ret) {               /* The interim page matches exactly with the one in history.                * Clear all flags and return.                */                              mIsLoadingDoc =  PR_FALSE;                        mHistoryEntryInLoad = (nsHistoryEntry *)nsnull;               }  //!ret            }  //else  for (!mIsloadingDoc)      }  // else  for (!InSHist)   }   return NS_OK;}