*outWindow = NULL; PRInt32 lastTimeStamp = -1; PRInt32 count = mWindowList.Count(); nsIWebShellWindow* mostRecentWindow; nsString typeString( inType );  for ( int32 i = 0; i< count; i++ ) { nsWindowInfo* windowInfo = (nsWindowInfo*) mWindowList[i]; if ( ( inType == NULL || windowInfo->GetType() == typeString ) && windowInfo->mTimeStamp >= lastTimeStamp ) { mostRecentWindow = windowInfo->mWindow; lastTimeStamp = windowInfo->mTimeStamp; } }  if( mostRecentWindow ) { nsCOMPtr <nsIDOMWindow> DOMWindow; if( NS_SUCCEEDED ( GetDOMWindow( mostRecentWindow, DOMWindow  ) ) ) { *outWindow = DOMWindow; return NS_OK; } else { return NS_ERROR_FAILURE; } } else { return NS_ERROR_FAILURE; }
NS_ENSURE_ARG_POINTER(outWindow); *outWindow = NULL;     nsAutoLock lock(mListLock); nsWindowInfo *info = MostRecentWindowInfo(inType);  if (info && info->mWindow) { nsCOMPtr <nsIDOMWindowInternal> DOMWindow; if(NS_SUCCEEDED(GetDOMWindow(info->mWindow, DOMWindow))) { *outWindow = DOMWindow; NS_ADDREF(*outWindow); return NS_OK; } return NS_ERROR_FAILURE; }  return NS_OK;
NS_IMETHODIMP nsWindowMediator::GetMostRecentWindow( const PRUnichar* inType, nsIDOMWindow** outWindow ){	*outWindow = NULL;	PRInt32 lastTimeStamp = -1;	PRInt32 count = mWindowList.Count();	nsIWebShellWindow* mostRecentWindow;	nsString typeString( inType );	// Find the most window with the highest time stamp that matches the requested type	for ( int32 i = 0; i< count; i++ )	{			nsWindowInfo* windowInfo = (nsWindowInfo*) mWindowList[i];		if ( ( inType == NULL || windowInfo->GetType() == typeString ) && windowInfo->mTimeStamp >= lastTimeStamp )		{			mostRecentWindow = windowInfo->mWindow;			lastTimeStamp = windowInfo->mTimeStamp;		}	}		if( mostRecentWindow )	{			nsCOMPtr <nsIDOMWindow> DOMWindow;			if( NS_SUCCEEDED ( GetDOMWindow( mostRecentWindow, DOMWindow  ) ) )			{					*outWindow = DOMWindow;				return NS_OK;			}			else			{				return NS_ERROR_FAILURE;			}	}	else	{		return NS_ERROR_FAILURE;	}}