зеркало из https://github.com/mozilla/pjs.git
Fix for 128815 - numerous bookmarks improvements, including fixes for bugs: 77411, 114142, 126748, 128571.
r=blake, sr=hyatt, a=asa
This commit is contained in:
Родитель
2715df8383
Коммит
dc0de3e526
|
@ -57,11 +57,12 @@ interface nsIBookmarksService : nsISupports
|
|||
void addBookmarkImmediately(in string aURI, in wstring aTitle, in long bmType, in wstring docCharset);
|
||||
|
||||
nsIRDFResource createFolder(in wstring aName, in nsIRDFResource aParentFolder);
|
||||
nsIRDFResource createFolderEx(in wstring aName, in nsIRDFResource aParentFolder, in long aIndex);
|
||||
nsIRDFResource createFolderWithDetails(in wstring aName, in nsIRDFResource aParentFolder,
|
||||
in long aIndex);
|
||||
|
||||
nsIRDFResource createBookmark(in wstring aName, in string aURL, in nsIRDFResource aParentFolder);
|
||||
nsIRDFResource createBookmarkEx(in wstring aName, in string aURI, in wstring docCharSet,
|
||||
in nsIRDFResource aFolder, in long aIndex);
|
||||
nsIRDFResource createBookmarkWithDetails(in wstring aName, in string aURI, in wstring docCharSet,
|
||||
in nsIRDFResource aFolder, in long aIndex);
|
||||
|
||||
void updateBookmarkIcon(in string aURL, in wstring iconURL);
|
||||
void removeBookmarkIcon(in string aURL, in wstring iconURL);
|
||||
|
|
|
@ -182,11 +182,12 @@ static const char kBookmarkCommand[] = "http://home.netscape.co
|
|||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
PRInt32 gRefCnt=0;
|
||||
nsIRDFService *gRDF;
|
||||
nsIRDFContainerUtils *gRDFC;
|
||||
nsICharsetAlias *gCharsetAlias;
|
||||
PRBool gLoadedBookmarks=PR_FALSE;
|
||||
PRInt32 gRefCnt=0;
|
||||
nsIRDFService *gRDF;
|
||||
nsIRDFContainerUtils *gRDFC;
|
||||
nsICharsetAlias *gCharsetAlias;
|
||||
PRBool gLoadedBookmarks = PR_FALSE;
|
||||
PRBool gImportedSystemBookmarks = PR_FALSE;
|
||||
|
||||
static nsresult
|
||||
bm_AddRefGlobals()
|
||||
|
@ -2604,13 +2605,13 @@ nsBookmarksService::CreateFolder(const PRUnichar* aName,
|
|||
nsIRDFResource* aParentFolder,
|
||||
nsIRDFResource** aResult)
|
||||
{
|
||||
return CreateFolderEx(aName, aParentFolder, -1, aResult);
|
||||
return CreateFolderWithDetails(aName, aParentFolder, -1, aResult);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsBookmarksService::CreateFolderEx(const PRUnichar* aName,
|
||||
nsIRDFResource* aParentFolder, PRInt32 aIndex,
|
||||
nsIRDFResource** aResult)
|
||||
nsBookmarksService::CreateFolderWithDetails(const PRUnichar* aName,
|
||||
nsIRDFResource* aParentFolder, PRInt32 aIndex,
|
||||
nsIRDFResource** aResult)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
|
@ -2680,14 +2681,14 @@ nsBookmarksService::CreateBookmark(const PRUnichar* aName, const char* aURL,
|
|||
nsIRDFResource* aParentFolder,
|
||||
nsIRDFResource** aResult)
|
||||
{
|
||||
return CreateBookmarkEx(aName, aURL, nsnull, aParentFolder, -1, aResult);
|
||||
return CreateBookmarkWithDetails(aName, aURL, nsnull, aParentFolder, -1, aResult);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsBookmarksService::CreateBookmarkEx(const PRUnichar* aName, const char* aURL,
|
||||
const PRUnichar* aDocCharSet,
|
||||
nsIRDFResource* aParentFolder, PRInt32 aIndex,
|
||||
nsIRDFResource** aResult)
|
||||
nsBookmarksService::CreateBookmarkWithDetails(const PRUnichar* aName, const char* aURL,
|
||||
const PRUnichar* aDocCharSet,
|
||||
nsIRDFResource* aParentFolder, PRInt32 aIndex,
|
||||
nsIRDFResource** aResult)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
|
@ -2792,7 +2793,8 @@ nsBookmarksService::AddBookmarkImmediately(const char *aURI,
|
|||
return rv;
|
||||
|
||||
nsCOMPtr<nsIRDFResource> bookmark;
|
||||
return CreateBookmarkEx(aTitle, aURI, aCharset, destinationFolder, -1, getter_AddRefs(bookmark));
|
||||
return CreateBookmarkWithDetails(aTitle, aURI, aCharset, destinationFolder, -1,
|
||||
getter_AddRefs(bookmark));
|
||||
}
|
||||
|
||||
|
||||
|
@ -3250,6 +3252,8 @@ nsBookmarksService::ImportSystemBookmarks(nsIRDFResource* aParentFolder)
|
|||
{
|
||||
nsresult rv;
|
||||
|
||||
gImportedSystemBookmarks = PR_TRUE;
|
||||
|
||||
#ifdef XP_WIN
|
||||
nsCOMPtr<nsIProperties> fileLocator(do_GetService("@mozilla.org/file/directory_service;1", &rv));
|
||||
if (NS_FAILED(rv))
|
||||
|
@ -3280,7 +3284,7 @@ nsBookmarksService::ImportSystemBookmarks(nsIRDFResource* aParentFolder)
|
|||
void
|
||||
nsBookmarksService::HandleSystemBookmarks(nsIRDFNode* aNode)
|
||||
{
|
||||
if (aNode == kNC_SystemBookmarksStaticRoot) {
|
||||
if (!gImportedSystemBookmarks && aNode == kNC_SystemBookmarksStaticRoot) {
|
||||
PRBool isSeq = PR_TRUE;
|
||||
gRDFC->IsSeq(mInner, kNC_SystemBookmarksStaticRoot, &isSeq);
|
||||
|
||||
|
@ -4771,13 +4775,9 @@ nsBookmarksService::LoadBookmarks()
|
|||
if (bookmarksPrefs)
|
||||
bookmarksPrefs->GetBoolPref("import_system_favorites", &useDynamicSystemBookmarks);
|
||||
|
||||
#ifdef XP_WIN
|
||||
nsCOMPtr<nsIRDFResource> ieFolder;
|
||||
char *ieFavoritesURL = nsnull;
|
||||
#endif
|
||||
#ifdef XP_BEOS
|
||||
nsCOMPtr<nsIRDFResource> netPositiveFolder;
|
||||
char *netPositiveURL = nsnull;
|
||||
#if defined(XP_WIN) || defined(XP_BEOS)
|
||||
nsCOMPtr<nsIRDFResource> systemFavoritesFolder;
|
||||
char* systemBookmarksURL = nsnull;
|
||||
#endif
|
||||
|
||||
{
|
||||
|
@ -4785,176 +4785,77 @@ nsBookmarksService::LoadBookmarks()
|
|||
BookmarkParser parser;
|
||||
parser.Init(&bookmarksFile, mInner, mPersonalToolbarName);
|
||||
|
||||
#if defined(XP_WIN) || defined(XP_BEOS)
|
||||
#if defined(XP_WIN)
|
||||
nsSpecialSystemDirectory systemBookmarksFolder(nsSpecialSystemDirectory::Win_Favorites);
|
||||
#elif defined(XP_BEOS)
|
||||
nsSpecialSystemDirectory systemBookmarksFolder(nsSpecialSystemDirectory::BeOS_SettingsDirectory);
|
||||
#endif
|
||||
|
||||
nsFileURL bookmarksURLSpec(systemBookmarksFolder);
|
||||
const char* constSystemBookmarksURL = bookmarksURLSpec.GetAsString();
|
||||
|
||||
#ifdef XP_BEOS
|
||||
bookmarksURLSpec += "NetPositive/Bookmarks/";
|
||||
#endif
|
||||
|
||||
if (constSystemBookmarksURL)
|
||||
systemBookmarksURL = strdup(constSystemBookmarksURL);
|
||||
#endif
|
||||
|
||||
if (useDynamicSystemBookmarks)
|
||||
{
|
||||
#ifdef XP_MAC
|
||||
parser.SetIEFavoritesRoot(nsCString(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(nsCString(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);
|
||||
nsCString cstringNetPositiveURL = nsCString(netPositiveURL);
|
||||
parser.SetIEFavoritesRoot(cstringNetPositiveURL);
|
||||
#elif defined(XP_WIN) || defined(XP_BEOS)
|
||||
nsCString cstringBookmarksURL = nsCString(systemBookmarksURL);
|
||||
parser.SetIEFavoritesRoot(cstringBookmarksURL);
|
||||
#endif
|
||||
|
||||
parser.ParserFoundIEFavoritesRoot(&foundIERoot);
|
||||
}
|
||||
|
||||
BeginUpdateBatch(this);
|
||||
parser.Parse(kNC_BookmarksRoot, kNC_Bookmark);
|
||||
parser.Parse(kNC_BookmarksRoot, kNC_Bookmark);
|
||||
EndUpdateBatch(this);
|
||||
mBookmarksAvailable = PR_TRUE;
|
||||
mBookmarksAvailable = PR_TRUE;
|
||||
|
||||
PRBool foundPTFolder = PR_FALSE;
|
||||
parser.ParserFoundPersonalToolbarFolder(&foundPTFolder);
|
||||
PRBool foundPTFolder = PR_FALSE;
|
||||
parser.ParserFoundPersonalToolbarFolder(&foundPTFolder);
|
||||
// try to ensure that we end up with a personal toolbar folder
|
||||
if ((foundPTFolder == PR_FALSE) && (mPersonalToolbarName.Length() > 0))
|
||||
{
|
||||
nsCOMPtr<nsIRDFLiteral> ptNameLiteral;
|
||||
if ((foundPTFolder == PR_FALSE) && (mPersonalToolbarName.Length() > 0)) {
|
||||
nsCOMPtr<nsIRDFLiteral> ptNameLiteral;
|
||||
rv = gRDF->GetLiteral(mPersonalToolbarName.get(), getter_AddRefs(ptNameLiteral));
|
||||
if (NS_SUCCEEDED(rv))
|
||||
{
|
||||
nsCOMPtr<nsIRDFResource> ptSource;
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
nsCOMPtr<nsIRDFResource> ptSource;
|
||||
rv = mInner->GetSource(kNC_Name, ptNameLiteral, PR_TRUE, getter_AddRefs(ptSource));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if ((rv != NS_RDF_NO_VALUE) && (ptSource))
|
||||
setFolderHint(ptSource, kNC_PersonalToolbarFolder);
|
||||
}
|
||||
}
|
||||
setFolderHint(ptSource, kNC_PersonalToolbarFolder);
|
||||
}
|
||||
}
|
||||
} // <-- scope the stream to get the open/close automatically.
|
||||
|
||||
nsAutoString ieTitle;
|
||||
getLocaleString("ImportedIEFavorites", ieTitle);
|
||||
|
||||
#ifdef XP_BEOS
|
||||
nsAutoString netPositiveTitle;
|
||||
getLocaleString("ImportedNetPositiveBookmarks", netPositiveTitle);
|
||||
#endif
|
||||
|
||||
if (useDynamicSystemBookmarks)
|
||||
{
|
||||
#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(this, kNC_BookmarksRoot);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = bookmarksRoot->AppendElement(kNC_IEFavoritesRoot);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// make sure IE Favorites root folder has the proper type
|
||||
rv = mInner->Assert(kNC_IEFavoritesRoot, kRDF_type, kNC_IEFavoriteFolder, PR_TRUE);
|
||||
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.get(), 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(this, 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.get(), 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(this, 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
|
||||
}
|
||||
|
||||
// Now append the one-time-per-profile empty "Full" System Bookmarks Root.
|
||||
// When the user opens this folder for the first time, system bookmarks are
|
||||
// imported into this folder. A pref is used to keep track of whether or
|
||||
// not to perform this operation.
|
||||
#if defined(XP_MAC) || defined(XP_WIN)
|
||||
nsCOMPtr<nsIRDFContainer> rootContainer(do_CreateInstance(kRDFContainerCID, &rv));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
PRBool addedStaticRoot = PR_FALSE;
|
||||
if (bookmarksPrefs)
|
||||
bookmarksPrefs->GetBoolPref("added_static_root",
|
||||
&addedStaticRoot);
|
||||
|
||||
rv = rootContainer->Init(this, kNC_BookmarksRoot);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
// Add the root that System bookmarks are imported into as real bookmarks. This is
|
||||
// only done once.
|
||||
if (!addedStaticRoot) {
|
||||
nsCOMPtr<nsIRDFContainer> rootContainer(do_CreateInstance(kRDFContainerCID, &rv));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
PRBool showStaticSystemBookmarks = PR_TRUE;
|
||||
if (bookmarksPrefs)
|
||||
bookmarksPrefs->GetBoolPref("show_static_system_bookmarks",
|
||||
&showStaticSystemBookmarks);
|
||||
rv = rootContainer->Init(this, kNC_BookmarksRoot);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (showStaticSystemBookmarks) {
|
||||
rv = mInner->Assert(kNC_SystemBookmarksStaticRoot, kRDF_type, kNC_Folder, PR_TRUE);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
|
@ -4970,9 +4871,89 @@ nsBookmarksService::LoadBookmarks()
|
|||
|
||||
rv = rootContainer->AppendElement(kNC_SystemBookmarksStaticRoot);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// If the user has not specifically asked for the Dynamic bookmarks root
|
||||
// via the pref, remove it from an existing bookmarks file as it serves
|
||||
// only to add confusion.
|
||||
if (!useDynamicSystemBookmarks) {
|
||||
nsCOMPtr<nsIRDFContainer> container(do_CreateInstance(kRDFContainerCID, &rv));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = container->Init(this, kNC_BookmarksRoot);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIRDFResource> systemFolderResource;
|
||||
rv = gRDF->GetResource(systemBookmarksURL, getter_AddRefs(systemFolderResource));
|
||||
|
||||
rv = container->RemoveElement(systemFolderResource, PR_TRUE);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
|
||||
bookmarksPrefs->SetBoolPref("added_static_root", PR_TRUE);
|
||||
}
|
||||
#endif
|
||||
|
||||
// Add the dynamic system bookmarks root if the user has asked for it
|
||||
// by setting the pref.
|
||||
if (useDynamicSystemBookmarks)
|
||||
{
|
||||
#ifdef XP_MAC
|
||||
// if the IE Favorites root isn't somewhere in bookmarks.html, add it
|
||||
if (!foundIERoot)
|
||||
{
|
||||
nsCOMPtr<nsIRDFContainer> bookmarksRoot(do_CreateInstance(kRDFContainerCID, &rv));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = bookmarksRoot->Init(this, kNC_BookmarksRoot);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = bookmarksRoot->AppendElement(kNC_IEFavoritesRoot);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// make sure IE Favorites root folder has the proper type
|
||||
rv = mInner->Assert(kNC_IEFavoritesRoot, kRDF_type, kNC_IEFavoriteFolder, PR_TRUE);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
#elif defined(XP_WIN) || defined(XP_BEOS)
|
||||
nsCOMPtr<nsIRDFResource> systemFolderResource;
|
||||
rv = gRDF->GetResource(systemBookmarksURL, getter_AddRefs(systemFolderResource));
|
||||
if (NS_SUCCEEDED(rv))
|
||||
{
|
||||
nsAutoString systemBookmarksFolderTitle;
|
||||
#ifdef XP_BEOS
|
||||
getLocaleString("ImportedNetPositiveBookmarks", systemBookmarksFolderTitle);
|
||||
#else
|
||||
getLocaleString("ImportedIEFavorites", systemBookmarksFolderTitle);
|
||||
#endif
|
||||
|
||||
nsCOMPtr<nsIRDFLiteral> systemFolderTitleLiteral;
|
||||
rv = gRDF->GetLiteral(systemBookmarksFolderTitle.get(),
|
||||
getter_AddRefs(systemFolderTitleLiteral));
|
||||
if (NS_SUCCEEDED(rv) && systemFolderTitleLiteral)
|
||||
rv = mInner->Assert(systemFolderResource, kNC_Name,
|
||||
systemFolderTitleLiteral, PR_TRUE);
|
||||
|
||||
// if the IE Favorites root isn't somewhere in bookmarks.html, add it
|
||||
if (!foundIERoot)
|
||||
{
|
||||
nsCOMPtr<nsIRDFContainer> container(do_CreateInstance(kRDFContainerCID, &rv));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = container->Init(this, kNC_BookmarksRoot);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = container->AppendElement(systemFolderResource);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
}
|
||||
if (systemBookmarksURL)
|
||||
{
|
||||
free(systemBookmarksURL);
|
||||
systemBookmarksURL = nsnull;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
PRTime now2;
|
||||
#ifdef XP_MAC
|
||||
|
|
Загрузка…
Ссылка в новой задаче