nsresult	rv;    mInner = nsnull; if (NS_FAILED(rv = nsComponentManager::CreateInstance(kRDFInMemoryDataSourceCID, nsnull, NS_GET_IID(nsIRDFDataSource), (void**) &mInner))) return(rv);  rv = mInner->AddObserver(this); if (NS_FAILED(rv)) return rv;  nsFileSpec	bookmarksFile; rv = GetBookmarksFile(&bookmarksFile);    if (NS_FAILED(rv)) return NS_OK;  rv = gRDFC->MakeSeq(mInner, kNC_BookmarksRoot, nsnull); NS_ASSERTION(NS_SUCCEEDED(rv), "Unable to make NC:BookmarksRoot a sequence"); if (NS_FAILED(rv)) return rv;  PRBool	foundIERoot = PR_FALSE;  #ifdef	DEBUG PRTime		now; #ifdef	XP_MAC Microseconds((UnsignedWide *)&now); #else now = PR_Now(); #endif printf("Start reading in bookmarks.html\n"); #endif  #ifdef	XP_WIN nsCOMPtr<nsIRDFResource>	ieFolder; char				*ieFavoritesURL = nsnull; #endif #ifdef	XP_BEOS nsCOMPtr<nsIRDFResource>	netPositiveFolder; char				*netPositiveURL = nsnull; #endif  { BookmarkParser parser; parser.Init(&bookmarksFile, mInner, mPersonalToolbarName);  #ifdef	XP_MAC parser.SetIEFavoritesRoot(kURINC_IEFavoritesRoot); #endif  #ifdef	XP_WIN nsSpecialSystemDirectory	ieFavoritesFile(nsSpecialSystemDirectory::Win_Favorites); nsFileURL			ieFavoritesURLSpec(ieFavoritesFile); const char			*favoritesURL = ieFavoritesURLSpec.GetAsString(); if (favoritesURL) { ieFavoritesURL = strdup(favoritesURL); } parser.SetIEFavoritesRoot(ieFavoritesURL); #endif  #ifdef	XP_BEOS nsSpecialSystemDirectory	netPositiveFile(nsSpecialSystemDirectory::BeOS_SettingsDirectory); nsFileURL			netPositiveURLSpec(netPositiveFile);    netPositiveURLSpec += "NetPositive/Bookmarks/";  const char			*constNetPositiveURL = netPositiveURLSpec.GetAsString(); if (constNetPositiveURL) { netPositiveURL = strdup(constNetPositiveURL); } parser.SetIEFavoritesRoot(netPositiveURL); #endif  parser.Parse(kNC_BookmarksRoot, kNC_Bookmark); mBookmarksAvailable = PR_TRUE;  parser.ParserFoundIEFavoritesRoot(&foundIERoot); }   nsAutoString	ieTitle; getLocaleString("ImportedIEFavorites", ieTitle);  #ifdef	XP_BEOS nsAutoString	netPositiveTitle; getLocaleString("ImportedNetPositiveBookmarks", ieTitle); #endif  #ifdef	XP_MAC  if (!foundIERoot) { nsCOMPtr<nsIRDFContainer> bookmarksRoot; rv = nsComponentManager::CreateInstance(kRDFContainerCID, nsnull, NS_GET_IID(nsIRDFContainer), getter_AddRefs(bookmarksRoot)); if (NS_FAILED(rv)) return rv;  rv = bookmarksRoot->Init(mInner, kNC_BookmarksRoot); if (NS_FAILED(rv)) return rv;  rv = bookmarksRoot->AppendElement(kNC_IEFavoritesRoot); if (NS_FAILED(rv)) return rv; } #endif  #ifdef	XP_WIN rv = gRDF->GetResource(ieFavoritesURL, getter_AddRefs(ieFolder)); if (NS_SUCCEEDED(rv)) { nsCOMPtr<nsIRDFLiteral>	ieTitleLiteral; rv = gRDF->GetLiteral(ieTitle.GetUnicode(), getter_AddRefs(ieTitleLiteral)); if (NS_SUCCEEDED(rv) && ieTitleLiteral) { rv = mInner->Assert(ieFolder, kNC_Name, ieTitleLiteral, PR_TRUE); }   if (!foundIERoot) { nsCOMPtr<nsIRDFContainer> container; rv = nsComponentManager::CreateInstance(kRDFContainerCID, nsnull, NS_GET_IID(nsIRDFContainer), getter_AddRefs(container)); if (NS_FAILED(rv)) return rv;  rv = container->Init(mInner, kNC_BookmarksRoot); if (NS_FAILED(rv)) return rv;  rv = container->AppendElement(ieFolder); if (NS_FAILED(rv)) return rv; } } if (ieFavoritesURL) { free(ieFavoritesURL); ieFavoritesURL = nsnull; } #endif  #ifdef	XP_BEOS rv = gRDF->GetResource(netPositiveURL, getter_AddRefs(netPositiveFolder)); if (NS_SUCCEEDED(rv)) { nsCOMPtr<nsIRDFLiteral>	netPositiveTitleLiteral; rv = gRDF->GetLiteral(netPositiveTitle.GetUnicode(), getter_AddRefs(netPositiveTitleLiteral)); if (NS_SUCCEEDED(rv) && netPositiveTitleLiteral) { rv = mInner->Assert(netPositiveFolder, kNC_Name, netPositiveTitleLiteral, PR_TRUE); }   if (!foundIERoot) { nsCOMPtr<nsIRDFContainer> container; rv = nsComponentManager::CreateInstance(kRDFContainerCID, nsnull, NS_GET_IID(nsIRDFContainer), getter_AddRefs(container)); if (NS_FAILED(rv)) return rv;  rv = container->Init(mInner, kNC_BookmarksRoot); if (NS_FAILED(rv)) return rv;  rv = container->AppendElement(netPositiveFolder); if (NS_FAILED(rv)) return rv; } } if (netPositiveURL) { free(netPositiveURL); netPositiveURL = nsnull; } #endif  #ifdef	DEBUG PRTime		now2; #ifdef	XP_MAC Microseconds((UnsignedWide *)&now2); #else now2 = PR_Now(); #endif PRUint64	loadTime64; LL_SUB(loadTime64, now2, now); PRUint32	loadTime32; LL_L2UI(loadTime32, loadTime64); printf("Finished reading in bookmarks.html  (%u microseconds)\n", loadTime32); #endif  return(NS_OK);
if (!gLoadedBookmarks) { LoadBookmarks(); gLoadedBookmarks = PR_TRUE; *didLoadBookmarks = PR_TRUE; } else { *didLoadBookmarks = PR_FALSE; } return(NS_OK);
nsBookmarksService::ReadBookmarks(){	nsresult	rv;	// the profile manager might call Readbookmarks() in certain circumstances	// so we need to forget about any previous bookmarks	mInner = nsnull;	if (NS_FAILED(rv = nsComponentManager::CreateInstance(kRDFInMemoryDataSourceCID,				nsnull, NS_GET_IID(nsIRDFDataSource), (void**) &mInner)))		return(rv);	rv = mInner->AddObserver(this);	if (NS_FAILED(rv)) return rv;	nsFileSpec	bookmarksFile;	rv = GetBookmarksFile(&bookmarksFile);	// Oh well, couldn't get the bookmarks file. Guess there	// aren't any bookmarks to read in.	if (NS_FAILED(rv))	    return NS_OK;	rv = gRDFC->MakeSeq(mInner, kNC_BookmarksRoot, nsnull);	NS_ASSERTION(NS_SUCCEEDED(rv), "Unable to make NC:BookmarksRoot a sequence");	if (NS_FAILED(rv)) return rv;	PRBool	foundIERoot = PR_FALSE;#ifdef	DEBUG	PRTime		now;#ifdef	XP_MAC	Microseconds((UnsignedWide *)&now);#else	now = PR_Now();#endif	printf("Start reading in bookmarks.html\n");#endif#ifdef	XP_WIN	nsCOMPtr<nsIRDFResource>	ieFolder;	char				*ieFavoritesURL = nsnull;#endif#ifdef	XP_BEOS	nsCOMPtr<nsIRDFResource>	netPositiveFolder;	char				*netPositiveURL = nsnull;#endif	{ // <-- scope the stream to get the open/close automatically.		BookmarkParser parser;		parser.Init(&bookmarksFile, mInner, mPersonalToolbarName);#ifdef	XP_MAC		parser.SetIEFavoritesRoot(kURINC_IEFavoritesRoot);#endif#ifdef	XP_WIN		nsSpecialSystemDirectory	ieFavoritesFile(nsSpecialSystemDirectory::Win_Favorites);		nsFileURL			ieFavoritesURLSpec(ieFavoritesFile);		const char			*favoritesURL = ieFavoritesURLSpec.GetAsString();		if (favoritesURL)		{			ieFavoritesURL = strdup(favoritesURL);		}		parser.SetIEFavoritesRoot(ieFavoritesURL);#endif#ifdef	XP_BEOS		nsSpecialSystemDirectory	netPositiveFile(nsSpecialSystemDirectory::BeOS_SettingsDirectory);		nsFileURL			netPositiveURLSpec(netPositiveFile);		// XXX Currently hard-coded; does the BeOS have anything like a		// system registry which we could use to get this instead?		netPositiveURLSpec += "NetPositive/Bookmarks/";		const char			*constNetPositiveURL = netPositiveURLSpec.GetAsString();		if (constNetPositiveURL)		{			netPositiveURL = strdup(constNetPositiveURL);		}		parser.SetIEFavoritesRoot(netPositiveURL);#endif		parser.Parse(kNC_BookmarksRoot, kNC_Bookmark);		mBookmarksAvailable = PR_TRUE;		parser.ParserFoundIEFavoritesRoot(&foundIERoot);	} // <-- scope the stream to get the open/close automatically.		// look for and import any IE Favorites	nsAutoString	ieTitle;	getLocaleString("ImportedIEFavorites", ieTitle);#ifdef	XP_BEOS	nsAutoString	netPositiveTitle;	getLocaleString("ImportedNetPositiveBookmarks", ieTitle);#endif#ifdef	XP_MAC	// if the IE Favorites root isn't somewhere in bookmarks.html, add it	if (!foundIERoot)	{		nsCOMPtr<nsIRDFContainer> bookmarksRoot;		rv = nsComponentManager::CreateInstance(kRDFContainerCID,							nsnull,							NS_GET_IID(nsIRDFContainer),							getter_AddRefs(bookmarksRoot));		if (NS_FAILED(rv)) return rv;		rv = bookmarksRoot->Init(mInner, kNC_BookmarksRoot);		if (NS_FAILED(rv)) return rv;		rv = bookmarksRoot->AppendElement(kNC_IEFavoritesRoot);		if (NS_FAILED(rv)) return rv;	}#endif#ifdef	XP_WIN	rv = gRDF->GetResource(ieFavoritesURL, getter_AddRefs(ieFolder));	if (NS_SUCCEEDED(rv))	{		nsCOMPtr<nsIRDFLiteral>	ieTitleLiteral;		rv = gRDF->GetLiteral(ieTitle.GetUnicode(), getter_AddRefs(ieTitleLiteral));		if (NS_SUCCEEDED(rv) && ieTitleLiteral)		{			rv = mInner->Assert(ieFolder, kNC_Name, ieTitleLiteral, PR_TRUE);		}		// if the IE Favorites root isn't somewhere in bookmarks.html, add it		if (!foundIERoot)		{			nsCOMPtr<nsIRDFContainer> container;			rv = nsComponentManager::CreateInstance(kRDFContainerCID,								nsnull,								NS_GET_IID(nsIRDFContainer),								getter_AddRefs(container));			if (NS_FAILED(rv)) return rv;			rv = container->Init(mInner, kNC_BookmarksRoot);			if (NS_FAILED(rv)) return rv;			rv = container->AppendElement(ieFolder);			if (NS_FAILED(rv)) return rv;		}	}	if (ieFavoritesURL)	{		free(ieFavoritesURL);		ieFavoritesURL = nsnull;	}#endif#ifdef	XP_BEOS	rv = gRDF->GetResource(netPositiveURL, getter_AddRefs(netPositiveFolder));	if (NS_SUCCEEDED(rv))	{		nsCOMPtr<nsIRDFLiteral>	netPositiveTitleLiteral;		rv = gRDF->GetLiteral(netPositiveTitle.GetUnicode(), getter_AddRefs(netPositiveTitleLiteral));		if (NS_SUCCEEDED(rv) && netPositiveTitleLiteral)		{			rv = mInner->Assert(netPositiveFolder, kNC_Name, netPositiveTitleLiteral, PR_TRUE);		}		// if the Favorites root isn't somewhere in bookmarks.html, add it		if (!foundIERoot)		{			nsCOMPtr<nsIRDFContainer> container;			rv = nsComponentManager::CreateInstance(kRDFContainerCID,								nsnull,								NS_GET_IID(nsIRDFContainer),								getter_AddRefs(container));			if (NS_FAILED(rv)) return rv;			rv = container->Init(mInner, kNC_BookmarksRoot);			if (NS_FAILED(rv)) return rv;			rv = container->AppendElement(netPositiveFolder);			if (NS_FAILED(rv)) return rv;		}	}	if (netPositiveURL)	{		free(netPositiveURL);		netPositiveURL = nsnull;	}#endif#ifdef	DEBUG	PRTime		now2;#ifdef	XP_MAC	Microseconds((UnsignedWide *)&now2);#else	now2 = PR_Now();#endif	PRUint64	loadTime64;	LL_SUB(loadTime64, now2, now);	PRUint32	loadTime32;	LL_L2UI(loadTime32, loadTime64);	printf("Finished reading in bookmarks.html  (%u microseconds)\n", loadTime32);#endif	return(NS_OK);}