*didLoadBookmarks = PR_FALSE; if (!mBookmarksFile) { LoadBookmarks(); if (mBookmarksFile) { *didLoadBookmarks = PR_TRUE; nsCOMPtr<nsIPrefBranchInternal> prefBranchInt(do_GetService(NS_PREFSERVICE_CONTRACTID)); if (prefBranchInt) prefBranchInt->AddObserver("browser.bookmarks.file", this, true); } } return NS_OK;
nsresult 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	XP_WIN nsCOMPtr<nsIRDFResource>	ieFolder; char				*ieFavoritesURL = nsnull; #endif #ifdef	XP_BEOS nsCOMPtr<nsIRDFResource>	netPositiveFolder; char				*netPositiveURL = nsnull; #endif  { nsInputFileStream strm(bookmarksFile);  if (! strm.is_open()) { NS_ERROR("unable to open file"); return NS_ERROR_FAILURE; }  BookmarkParser parser; parser.Init(&strm, mInner);  #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);  parser.ParserFoundIEFavoritesRoot(&foundIERoot); }   nsAutoString	ieTitle("Imported IE Favorites"); #ifdef	XP_BEOS nsAutoString	netPositiveTitle("Imported NetPositive Bookmarks"); #endif  #ifdef	XP_MAC nsSpecialSystemDirectory ieFavoritesFile(nsSpecialSystemDirectory::Mac_PreferencesDirectory); ieFavoritesFile += "Explorer"; ieFavoritesFile += "Favorites.html";  nsInputFileStream	ieStream(ieFavoritesFile); if (ieStream.is_open()) { if (NS_SUCCEEDED(rv = gRDFC->MakeSeq(mInner, kNC_IEFavoritesRoot, nsnull))) { BookmarkParser parser; parser.Init(&ieStream, mInner); parser.Parse(kNC_IEFavoritesRoot, kNC_IEFavorite);  nsCOMPtr<nsIRDFLiteral>	ieTitleLiteral; rv = gRDF->GetLiteral(ieTitle.GetUnicode(), getter_AddRefs(ieTitleLiteral)); if (NS_SUCCEEDED(rv) && ieTitleLiteral) { rv = mInner->Assert(kNC_IEFavoritesRoot, kNC_Name, ieTitleLiteral, PR_TRUE); }   if (!foundIERoot) { nsCOMPtr<nsIRDFContainer> bookmarksRoot; rv = nsComponentManager::CreateInstance(kRDFContainerCID, nsnull, nsIRDFContainer::GetIID(), 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, nsIRDFContainer::GetIID(), 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, nsIRDFContainer::GetIID(), 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   return NS_OK;
nsBookmarksService::ReadBookmarks(PRBool *didLoadBookmarks){    *didLoadBookmarks = PR_FALSE;    if (!mBookmarksFile)    {        LoadBookmarks();        if (mBookmarksFile) {            *didLoadBookmarks = PR_TRUE;            nsCOMPtr<nsIPrefBranchInternal> prefBranchInt(do_GetService(NS_PREFSERVICE_CONTRACTID));            if (prefBranchInt)                prefBranchInt->AddObserver("browser.bookmarks.file", this, true);        }    }    return NS_OK;}