зеркало из https://github.com/mozilla/pjs.git
Bug 405936 - export "unfiled bookmarks" folder to html. r=dietrich.
This commit is contained in:
Родитель
ccb58af318
Коммит
a25de50038
|
@ -110,6 +110,7 @@ static NS_DEFINE_CID(kParserCID, NS_PARSER_CID);
|
||||||
|
|
||||||
#define KEY_TOOLBARFOLDER_LOWER "personal_toolbar_folder"
|
#define KEY_TOOLBARFOLDER_LOWER "personal_toolbar_folder"
|
||||||
#define KEY_BOOKMARKSMENU_LOWER "bookmarks_menu"
|
#define KEY_BOOKMARKSMENU_LOWER "bookmarks_menu"
|
||||||
|
#define KEY_UNFILEDFOLDER_LOWER "unfiled_bookmarks_folder"
|
||||||
#define KEY_PLACESROOT_LOWER "places_root"
|
#define KEY_PLACESROOT_LOWER "places_root"
|
||||||
#define KEY_HREF_LOWER "href"
|
#define KEY_HREF_LOWER "href"
|
||||||
#define KEY_FEEDURL_LOWER "feedurl"
|
#define KEY_FEEDURL_LOWER "feedurl"
|
||||||
|
@ -164,7 +165,8 @@ public:
|
||||||
enum ContainerType { Container_Normal,
|
enum ContainerType { Container_Normal,
|
||||||
Container_Places,
|
Container_Places,
|
||||||
Container_Menu,
|
Container_Menu,
|
||||||
Container_Toolbar };
|
Container_Toolbar,
|
||||||
|
Container_Unfiled};
|
||||||
|
|
||||||
PRInt64 mContainerID;
|
PRInt64 mContainerID;
|
||||||
|
|
||||||
|
@ -756,6 +758,10 @@ BookmarkContentSink::HandleHeadBegin(const nsIParserNode& node)
|
||||||
if (mIsImportDefaults)
|
if (mIsImportDefaults)
|
||||||
frame.mLastContainerType = BookmarkImportFrame::Container_Menu;
|
frame.mLastContainerType = BookmarkImportFrame::Container_Menu;
|
||||||
break;
|
break;
|
||||||
|
} else if (node.GetKeyAt(i).LowerCaseEqualsLiteral(KEY_UNFILEDFOLDER_LOWER)) {
|
||||||
|
if (mIsImportDefaults)
|
||||||
|
frame.mLastContainerType = BookmarkImportFrame::Container_Unfiled;
|
||||||
|
break;
|
||||||
} else if (node.GetKeyAt(i).LowerCaseEqualsLiteral(KEY_PLACESROOT_LOWER)) {
|
} else if (node.GetKeyAt(i).LowerCaseEqualsLiteral(KEY_PLACESROOT_LOWER)) {
|
||||||
if (mIsImportDefaults)
|
if (mIsImportDefaults)
|
||||||
frame.mLastContainerType = BookmarkImportFrame::Container_Places;
|
frame.mLastContainerType = BookmarkImportFrame::Container_Places;
|
||||||
|
@ -1167,12 +1173,19 @@ BookmarkContentSink::NewFrame()
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
break;
|
break;
|
||||||
case BookmarkImportFrame::Container_Menu:
|
case BookmarkImportFrame::Container_Menu:
|
||||||
// menu root
|
// menu folder
|
||||||
rv = mBookmarksService->GetBookmarksMenuFolder(&ourID);
|
rv = mBookmarksService->GetBookmarksMenuFolder(&ourID);
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
if (mAllowRootChanges)
|
if (mAllowRootChanges)
|
||||||
updateFolder = PR_TRUE;
|
updateFolder = PR_TRUE;
|
||||||
break;
|
break;
|
||||||
|
case BookmarkImportFrame::Container_Unfiled:
|
||||||
|
// unfiled bookmarks folder
|
||||||
|
rv = mBookmarksService->GetUnfiledBookmarksFolder(&ourID);
|
||||||
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
if (mAllowRootChanges)
|
||||||
|
updateFolder = PR_TRUE;
|
||||||
|
break;
|
||||||
case BookmarkImportFrame::Container_Toolbar:
|
case BookmarkImportFrame::Container_Toolbar:
|
||||||
// get toolbar folder
|
// get toolbar folder
|
||||||
rv = mBookmarksService->GetToolbarFolder(&ourID);
|
rv = mBookmarksService->GetToolbarFolder(&ourID);
|
||||||
|
@ -1438,6 +1451,7 @@ static const char kDescriptionClose[] = NS_LINEBREAK;
|
||||||
static const char kPlacesRootAttribute[] = " PLACES_ROOT=\"true\"";
|
static const char kPlacesRootAttribute[] = " PLACES_ROOT=\"true\"";
|
||||||
static const char kBookmarksRootAttribute[] = " BOOKMARKS_MENU=\"true\"";
|
static const char kBookmarksRootAttribute[] = " BOOKMARKS_MENU=\"true\"";
|
||||||
static const char kToolbarFolderAttribute[] = " PERSONAL_TOOLBAR_FOLDER=\"true\"";
|
static const char kToolbarFolderAttribute[] = " PERSONAL_TOOLBAR_FOLDER=\"true\"";
|
||||||
|
static const char kUnfiledBookmarksFolderAttribute[] = " UNFILED_BOOKMARKS_FOLDER=\"true\"";
|
||||||
static const char kIconAttribute[] = " ICON=\"";
|
static const char kIconAttribute[] = " ICON=\"";
|
||||||
static const char kIconURIAttribute[] = " ICON_URI=\"";
|
static const char kIconURIAttribute[] = " ICON_URI=\"";
|
||||||
static const char kHrefAttribute[] = " HREF=\"";
|
static const char kHrefAttribute[] = " HREF=\"";
|
||||||
|
@ -1681,6 +1695,10 @@ nsPlacesImportExportService::WriteContainerHeader(nsINavHistoryResultNode* aFold
|
||||||
rv = mBookmarksService->GetToolbarFolder(&toolbarFolder);
|
rv = mBookmarksService->GetToolbarFolder(&toolbarFolder);
|
||||||
NS_ENSURE_SUCCESS(rv,rv);
|
NS_ENSURE_SUCCESS(rv,rv);
|
||||||
|
|
||||||
|
PRInt64 unfiledBookmarksFolder;
|
||||||
|
rv = mBookmarksService->GetUnfiledBookmarksFolder(&unfiledBookmarksFolder);
|
||||||
|
NS_ENSURE_SUCCESS(rv,rv);
|
||||||
|
|
||||||
// " PERSONAL_TOOLBAR_FOLDER="true"", etc.
|
// " PERSONAL_TOOLBAR_FOLDER="true"", etc.
|
||||||
if (folderId == placesRoot) {
|
if (folderId == placesRoot) {
|
||||||
rv = aOutput->Write(kPlacesRootAttribute, sizeof(kPlacesRootAttribute)-1, &dummy);
|
rv = aOutput->Write(kPlacesRootAttribute, sizeof(kPlacesRootAttribute)-1, &dummy);
|
||||||
|
@ -1688,6 +1706,9 @@ nsPlacesImportExportService::WriteContainerHeader(nsINavHistoryResultNode* aFold
|
||||||
} else if (folderId == bookmarksMenuFolder) {
|
} else if (folderId == bookmarksMenuFolder) {
|
||||||
rv = aOutput->Write(kBookmarksRootAttribute, sizeof(kBookmarksRootAttribute)-1, &dummy);
|
rv = aOutput->Write(kBookmarksRootAttribute, sizeof(kBookmarksRootAttribute)-1, &dummy);
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
} else if (folderId == unfiledBookmarksFolder) {
|
||||||
|
rv = aOutput->Write(kUnfiledBookmarksFolderAttribute, sizeof(kUnfiledBookmarksFolderAttribute)-1, &dummy);
|
||||||
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
} else if (folderId == toolbarFolder) {
|
} else if (folderId == toolbarFolder) {
|
||||||
rv = aOutput->Write(kToolbarFolderAttribute, sizeof(kToolbarFolderAttribute)-1, &dummy);
|
rv = aOutput->Write(kToolbarFolderAttribute, sizeof(kToolbarFolderAttribute)-1, &dummy);
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
@ -2273,6 +2294,13 @@ nsPlacesImportExportService::RunBatched(nsISupports* aUserData)
|
||||||
rv = mBookmarksService->RemoveFolderChildren(toolbarFolder);
|
rv = mBookmarksService->RemoveFolderChildren(toolbarFolder);
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
|
PRInt64 unfiledBookmarksFolder;
|
||||||
|
rv = mBookmarksService->GetUnfiledBookmarksFolder(&unfiledBookmarksFolder);
|
||||||
|
NS_ENSURE_SUCCESS(rv,rv);
|
||||||
|
|
||||||
|
rv = mBookmarksService->RemoveFolderChildren(unfiledBookmarksFolder);
|
||||||
|
NS_ENSURE_SUCCESS(rv,rv);
|
||||||
|
|
||||||
// add the "Places" folder
|
// add the "Places" folder
|
||||||
nsCOMPtr<nsIBrowserGlue> glue(do_GetService("@mozilla.org/browser/browserglue;1", &rv));
|
nsCOMPtr<nsIBrowserGlue> glue(do_GetService("@mozilla.org/browser/browserglue;1", &rv));
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
@ -2366,6 +2394,10 @@ nsPlacesImportExportService::ExportHTMLToFile(nsILocalFile* aBookmarksFile)
|
||||||
rv = mBookmarksService->GetToolbarFolder(&toolbarFolder);
|
rv = mBookmarksService->GetToolbarFolder(&toolbarFolder);
|
||||||
NS_ENSURE_SUCCESS(rv,rv);
|
NS_ENSURE_SUCCESS(rv,rv);
|
||||||
|
|
||||||
|
PRInt64 unfiledBookmarksFolder;
|
||||||
|
rv = mBookmarksService->GetUnfiledBookmarksFolder(&unfiledBookmarksFolder);
|
||||||
|
NS_ENSURE_SUCCESS(rv,rv);
|
||||||
|
|
||||||
// file header
|
// file header
|
||||||
PRUint32 dummy;
|
PRUint32 dummy;
|
||||||
rv = strm->Write(kFileIntro, sizeof(kFileIntro)-1, &dummy);
|
rv = strm->Write(kFileIntro, sizeof(kFileIntro)-1, &dummy);
|
||||||
|
@ -2419,8 +2451,8 @@ nsPlacesImportExportService::ExportHTMLToFile(nsILocalFile* aBookmarksFile)
|
||||||
rv = WriteContainerContents(rootNode, EmptyCString(), strm);
|
rv = WriteContainerContents(rootNode, EmptyCString(), strm);
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
// write out the toolbar folder contents as a folder under the bookmarks-menu
|
// write out the toolbar folder and unfiled-bookmarks folder (if not empty)
|
||||||
// for backwards compatibility
|
// under the bookmarks-menu for backwards compatibility
|
||||||
rv = query->SetFolders(&toolbarFolder, 1);
|
rv = query->SetFolders(&toolbarFolder, 1);
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
|
@ -2434,6 +2466,29 @@ nsPlacesImportExportService::ExportHTMLToFile(nsILocalFile* aBookmarksFile)
|
||||||
rv = WriteContainer(rootNode, nsDependentCString(kIndent), strm);
|
rv = WriteContainer(rootNode, nsDependentCString(kIndent), strm);
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
|
// unfiled bookmarks
|
||||||
|
rv = query->SetFolders(&unfiledBookmarksFolder, 1);
|
||||||
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
|
rv = mHistoryService->ExecuteQuery(query, options, getter_AddRefs(result));
|
||||||
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
|
// get root (folder) node
|
||||||
|
rv = result->GetRoot(getter_AddRefs(rootNode));
|
||||||
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
|
rv = rootNode->SetContainerOpen(PR_TRUE);
|
||||||
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
|
PRUint32 childCount = 0;
|
||||||
|
rv = rootNode->GetChildCount(&childCount);
|
||||||
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
||||||
|
if (childCount > 0) {
|
||||||
|
rv = WriteContainer(rootNode, nsDependentCString(kIndent), strm);
|
||||||
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
}
|
||||||
|
|
||||||
// epilogue
|
// epilogue
|
||||||
rv = WriteContainerEpilogue(EmptyCString(), strm);
|
rv = WriteContainerEpilogue(EmptyCString(), strm);
|
||||||
NS_ENSURE_SUCCESS(rv, rv);
|
NS_ENSURE_SUCCESS(rv, rv);
|
||||||
|
|
|
@ -26,6 +26,10 @@
|
||||||
<DD>test microsummary
|
<DD>test microsummary
|
||||||
-->
|
-->
|
||||||
</DL>
|
</DL>
|
||||||
|
<DT><H3 UNFILED_BOOKMARKS_FOLDER="true">Unsorted Bookmarks</H3>
|
||||||
|
<DL><p>
|
||||||
|
<DT><A HREF="http://example.tld">Example.tld</A>
|
||||||
|
</DL><p>
|
||||||
<DT><H3 LAST_MODIFIED="1177541040" PERSONAL_TOOLBAR_FOLDER="true" ID="rdf:#$FvPhC3">Bookmarks Toolbar Folder</H3>
|
<DT><H3 LAST_MODIFIED="1177541040" PERSONAL_TOOLBAR_FOLDER="true" ID="rdf:#$FvPhC3">Bookmarks Toolbar Folder</H3>
|
||||||
<DD>Add bookmarks to this folder to see them displayed on the Bookmarks Toolbar
|
<DD>Add bookmarks to this folder to see them displayed on the Bookmarks Toolbar
|
||||||
<DL><p>
|
<DL><p>
|
||||||
|
|
|
@ -284,12 +284,13 @@ function testUnfiledBookmarks() {
|
||||||
var result = PlacesUtils.history.executeQuery(query, PlacesUtils.history.getNewQueryOptions());
|
var result = PlacesUtils.history.executeQuery(query, PlacesUtils.history.getNewQueryOptions());
|
||||||
var rootNode = result.root;
|
var rootNode = result.root;
|
||||||
rootNode.containerOpen = true;
|
rootNode.containerOpen = true;
|
||||||
do_check_eq(rootNode.childCount, bookmarkData.length);
|
// child count (add 1 for pre-existing item)
|
||||||
for (var i = 0; i < rootNode.childCount; i++) {
|
do_check_eq(rootNode.childCount, bookmarkData.length + 1);
|
||||||
|
for (var i = 1; i < rootNode.childCount; i++) {
|
||||||
var child = rootNode.getChild(i);
|
var child = rootNode.getChild(i);
|
||||||
dump(bookmarkData[i].uri.spec + " == " + child.uri + "?\n");
|
dump(bookmarkData[i - 1].uri.spec + " == " + child.uri + "?\n");
|
||||||
do_check_true(bookmarkData[i].uri.equals(uri(child.uri)));
|
do_check_true(bookmarkData[i - 1].uri.equals(uri(child.uri)));
|
||||||
do_check_eq(child.title, bookmarkData[i].title);
|
do_check_eq(child.title, bookmarkData[i - 1].title);
|
||||||
/* WTF
|
/* WTF
|
||||||
if (child.tags)
|
if (child.tags)
|
||||||
do_check_eq(child.tags, bookmarkData[i].title);
|
do_check_eq(child.tags, bookmarkData[i].title);
|
||||||
|
|
|
@ -127,7 +127,8 @@ function run_test() {
|
||||||
try {
|
try {
|
||||||
importer.importHTMLFromFile(bookmarksFileNew, true);
|
importer.importHTMLFromFile(bookmarksFileNew, true);
|
||||||
} catch(ex) { do_throw("couldn't import the exported file: " + ex); }
|
} catch(ex) { do_throw("couldn't import the exported file: " + ex); }
|
||||||
testCanonicalBookmarks(bmsvc.bookmarksMenuFolder);
|
testCanonicalBookmarks(bmsvc.bookmarksMenuFolder);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
// XXX import-to-folder tests disabled due to bug 363634
|
// XXX import-to-folder tests disabled due to bug 363634
|
||||||
// Test importing a pre-Places canonical bookmarks file to a specific folder.
|
// Test importing a pre-Places canonical bookmarks file to a specific folder.
|
||||||
|
@ -194,8 +195,8 @@ function testCanonicalBookmarks(aFolder) {
|
||||||
var rootNode = result.root;
|
var rootNode = result.root;
|
||||||
rootNode.containerOpen = true;
|
rootNode.containerOpen = true;
|
||||||
|
|
||||||
// 6-2: the toolbar contents are imported to the places-toolbar folder,
|
// 6-2: the toolbar folder and unfiled bookmarks folder imported to the
|
||||||
// the separator above it is removed.
|
// corresponding places folders
|
||||||
do_check_eq(rootNode.childCount, 4);
|
do_check_eq(rootNode.childCount, 4);
|
||||||
|
|
||||||
// get test folder
|
// get test folder
|
||||||
|
@ -299,4 +300,12 @@ function testCanonicalBookmarks(aFolder) {
|
||||||
livemarksvc.getFeedURI(livemark.itemId).spec);
|
livemarksvc.getFeedURI(livemark.itemId).spec);
|
||||||
|
|
||||||
toolbar.containerOpen = false;
|
toolbar.containerOpen = false;
|
||||||
|
|
||||||
|
// unfiled bookmarks
|
||||||
|
query.setFolders([bmsvc.unfiledBookmarksFolder], 1);
|
||||||
|
result = histsvc.executeQuery(query, histsvc.getNewQueryOptions());
|
||||||
|
var unfiledBookmarks = result.root;
|
||||||
|
unfiledBookmarks.containerOpen = true;
|
||||||
|
do_check_eq(unfiledBookmarks.childCount, 1);
|
||||||
|
unfiledBookmarks.containerOpen = false;
|
||||||
}
|
}
|
||||||
|
|
Загрузка…
Ссылка в новой задаче