nsPlacesImportExportService.cpp File Reference
#include "nsPlacesImportExportService.h"
#include "nsNetUtil.h"
#include "nsParserCIID.h"
#include "nsStringAPI.h"
#include "nsUnicharUtils.h"
#include "nsAppDirectoryServiceDefs.h"
#include "nsDirectoryServiceUtils.h"
#include "nsIPrefService.h"
#include "nsToolkitCompsCID.h"
#include "nsIHTMLContentSink.h"
#include "nsIParser.h"
#include "prprf.h"
#include "nsIBrowserGlue.h"
#include "nsIObserverService.h"
#include "nsISupportsPrimitives.h"
Include dependency graph for nsPlacesImportExportService.cpp:

Go to the source code of this file.

Classes

class  BookmarkImportFrame
 
class  BookmarkContentSink
 

Macros

#define KEY_TOOLBARFOLDER_LOWER   "personal_toolbar_folder"
 
#define KEY_BOOKMARKSMENU_LOWER   "bookmarks_menu"
 
#define KEY_UNFILEDFOLDER_LOWER   "unfiled_bookmarks_folder"
 
#define KEY_PLACESROOT_LOWER   "places_root"
 
#define KEY_HREF_LOWER   "href"
 
#define KEY_FEEDURL_LOWER   "feedurl"
 
#define KEY_WEB_PANEL_LOWER   "web_panel"
 
#define KEY_LASTCHARSET_LOWER   "last_charset"
 
#define KEY_ICON_LOWER   "icon"
 
#define KEY_ICON_URI_LOWER   "icon_uri"
 
#define KEY_SHORTCUTURL_LOWER   "shortcuturl"
 
#define KEY_POST_DATA_LOWER   "post_data"
 
#define KEY_NAME_LOWER   "name"
 
#define KEY_MICSUM_GEN_URI_LOWER   "micsum_gen_uri"
 
#define KEY_DATE_ADDED_LOWER   "add_date"
 
#define KEY_LAST_MODIFIED_LOWER   "last_modified"
 
#define KEY_GENERATED_TITLE_LOWER   "generated_title"
 
#define LOAD_IN_SIDEBAR_ANNO   NS_LITERAL_CSTRING("bookmarkProperties/loadInSidebar")
 
#define DESCRIPTION_ANNO   NS_LITERAL_CSTRING("bookmarkProperties/description")
 
#define POST_DATA_ANNO   NS_LITERAL_CSTRING("bookmarkProperties/POSTData")
 
#define STATIC_TITLE_ANNO   NS_LITERAL_CSTRING("bookmarks/staticTitle")
 
#define BOOKMARKS_MENU_ICON_URI   "chrome://browser/skin/places/bookmarksMenu.png"
 
#define RESTORE_BEGIN_NSIOBSERVER_TOPIC   "bookmarks-restore-begin"
 
#define RESTORE_SUCCESS_NSIOBSERVER_TOPIC   "bookmarks-restore-success"
 
#define RESTORE_FAILED_NSIOBSERVER_TOPIC   "bookmarks-restore-failed"
 
#define RESTORE_NSIOBSERVER_DATA   NS_LITERAL_STRING("html")
 
#define RESTORE_INITIAL_NSIOBSERVER_DATA   NS_LITERAL_STRING("html-initial")
 
#define NS_LINEBREAK   "\012"
 
#define BROWSER_BOOKMARKS_MAX_BACKUPS_PREF   "browser.bookmarks.max_backups"
 

Functions

static NS_DEFINE_CID (kParserCID, NS_PARSER_CID)
 
static nsresult WriteEscapedUrl (const nsCString &aString, nsIOutputStream *aOutput)
 
char * nsEscapeHTML (const char *string)
 
 NS_IMPL_ISUPPORTS2 (nsPlacesImportExportService, nsIPlacesImportExportService, nsINavHistoryBatchCallback) nsPlacesImportExportService
 
 NS_IMPL_ISUPPORTS2 (BookmarkContentSink, nsIContentSink, nsIHTMLContentSink) NS_IMETHODIMP BookmarkContentSink
 
static nsresult SyncChannelStatus (nsIChannel *channel, nsresult status)
 
static nsresult WriteContainerPrologue (const nsACString &aIndent, nsIOutputStream *aOutput)
 
static nsresult WriteContainerEpilogue (const nsACString &aIndent, nsIOutputStream *aOutput)
 
static nsresult WriteFaviconAttribute (const nsACString &aURI, nsIOutputStream *aOutput)
 
static nsresult WriteDateAttribute (const char aAttributeStart[], PRInt32 aLength, PRTime aAttributeValue, nsIOutputStream *aOutput)
 
static void NotifyImportObservers (const char *aTopic, PRInt64 aFolderId, PRBool aIsInitialImport)
 

Variables

static const char kWhitespace [] = " \r\n\t\b"
 
static char kFileIntro []
 
static const char kRootIntro [] = "<H1"
 
static const char kCloseRootH1 [] = "</H1>" "\012" "\012"
 
static const char kBookmarkIntro [] = "<DL><p>" "\012"
 
static const char kBookmarkClose [] = "</DL><p>" "\012"
 
static const char kContainerIntro [] = "<DT><H3"
 
static const char kContainerClose [] = "</H3>" "\012"
 
static const char kItemOpen [] = "<DT><A"
 
static const char kItemClose [] = "</A>" "\012"
 
static const char kSeparator [] = "<HR"
 
static const char kQuoteStr [] = "\""
 
static const char kCloseAngle [] = ">"
 
static const char kIndent [] = " "
 
static const char kDescriptionIntro [] = "<DD>"
 
static const char kDescriptionClose [] = "\012"
 
static const char kPlacesRootAttribute [] = " PLACES_ROOT=\"true\""
 
static const char kBookmarksRootAttribute [] = " BOOKMARKS_MENU=\"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 kIconURIAttribute [] = " ICON_URI=\""
 
static const char kHrefAttribute [] = " HREF=\""
 
static const char kFeedURIAttribute [] = " FEEDURL=\""
 
static const char kWebPanelAttribute [] = " WEB_PANEL=\"true\""
 
static const char kKeywordAttribute [] = " SHORTCUTURL=\""
 
static const char kPostDataAttribute [] = " POST_DATA=\""
 
static const char kItemIdAttribute [] = " ITEM_ID=\""
 
static const char kNameAttribute [] = " NAME=\""
 
static const char kMicsumGenURIAttribute [] = " MICSUM_GEN_URI=\""
 
static const char kDateAddedAttribute [] = " ADD_DATE=\""
 
static const char kLastModifiedAttribute [] = " LAST_MODIFIED=\""
 
static const char kLastCharsetAttribute [] = " LAST_CHARSET=\""
 

Macro Definition Documentation

#define BOOKMARKS_MENU_ICON_URI   "chrome://browser/skin/places/bookmarksMenu.png"

Definition at line 135 of file nsPlacesImportExportService.cpp.

#define BROWSER_BOOKMARKS_MAX_BACKUPS_PREF   "browser.bookmarks.max_backups"

Definition at line 2553 of file nsPlacesImportExportService.cpp.

#define DESCRIPTION_ANNO   NS_LITERAL_CSTRING("bookmarkProperties/description")

Definition at line 131 of file nsPlacesImportExportService.cpp.

#define KEY_BOOKMARKSMENU_LOWER   "bookmarks_menu"

Definition at line 113 of file nsPlacesImportExportService.cpp.

#define KEY_DATE_ADDED_LOWER   "add_date"

Definition at line 126 of file nsPlacesImportExportService.cpp.

#define KEY_FEEDURL_LOWER   "feedurl"

Definition at line 117 of file nsPlacesImportExportService.cpp.

#define KEY_GENERATED_TITLE_LOWER   "generated_title"

Definition at line 128 of file nsPlacesImportExportService.cpp.

#define KEY_HREF_LOWER   "href"

Definition at line 116 of file nsPlacesImportExportService.cpp.

#define KEY_ICON_LOWER   "icon"

Definition at line 120 of file nsPlacesImportExportService.cpp.

#define KEY_ICON_URI_LOWER   "icon_uri"

Definition at line 121 of file nsPlacesImportExportService.cpp.

#define KEY_LAST_MODIFIED_LOWER   "last_modified"

Definition at line 127 of file nsPlacesImportExportService.cpp.

#define KEY_LASTCHARSET_LOWER   "last_charset"

Definition at line 119 of file nsPlacesImportExportService.cpp.

#define KEY_MICSUM_GEN_URI_LOWER   "micsum_gen_uri"

Definition at line 125 of file nsPlacesImportExportService.cpp.

#define KEY_NAME_LOWER   "name"

Definition at line 124 of file nsPlacesImportExportService.cpp.

#define KEY_PLACESROOT_LOWER   "places_root"

Definition at line 115 of file nsPlacesImportExportService.cpp.

#define KEY_POST_DATA_LOWER   "post_data"

Definition at line 123 of file nsPlacesImportExportService.cpp.

#define KEY_SHORTCUTURL_LOWER   "shortcuturl"

Definition at line 122 of file nsPlacesImportExportService.cpp.

#define KEY_TOOLBARFOLDER_LOWER   "personal_toolbar_folder"

Definition at line 112 of file nsPlacesImportExportService.cpp.

#define KEY_UNFILEDFOLDER_LOWER   "unfiled_bookmarks_folder"

Definition at line 114 of file nsPlacesImportExportService.cpp.

#define KEY_WEB_PANEL_LOWER   "web_panel"

Definition at line 118 of file nsPlacesImportExportService.cpp.

#define LOAD_IN_SIDEBAR_ANNO   NS_LITERAL_CSTRING("bookmarkProperties/loadInSidebar")

Definition at line 130 of file nsPlacesImportExportService.cpp.

#define NS_LINEBREAK   "\012"

Definition at line 152 of file nsPlacesImportExportService.cpp.

#define POST_DATA_ANNO   NS_LITERAL_CSTRING("bookmarkProperties/POSTData")

Definition at line 132 of file nsPlacesImportExportService.cpp.

#define RESTORE_BEGIN_NSIOBSERVER_TOPIC   "bookmarks-restore-begin"

Definition at line 139 of file nsPlacesImportExportService.cpp.

#define RESTORE_FAILED_NSIOBSERVER_TOPIC   "bookmarks-restore-failed"

Definition at line 141 of file nsPlacesImportExportService.cpp.

#define RESTORE_INITIAL_NSIOBSERVER_DATA   NS_LITERAL_STRING("html-initial")

Definition at line 143 of file nsPlacesImportExportService.cpp.

#define RESTORE_NSIOBSERVER_DATA   NS_LITERAL_STRING("html")

Definition at line 142 of file nsPlacesImportExportService.cpp.

#define RESTORE_SUCCESS_NSIOBSERVER_TOPIC   "bookmarks-restore-success"

Definition at line 140 of file nsPlacesImportExportService.cpp.

#define STATIC_TITLE_ANNO   NS_LITERAL_CSTRING("bookmarks/staticTitle")

Definition at line 133 of file nsPlacesImportExportService.cpp.

Function Documentation

static void NotifyImportObservers ( const char *  aTopic,
PRInt64  aFolderId,
PRBool  aIsInitialImport 
)
static

Definition at line 2183 of file nsPlacesImportExportService.cpp.

static NS_DEFINE_CID ( kParserCID  ,
NS_PARSER_CID   
)
static

Importer/exporter between the mozStorage-based bookmarks and the old-style "bookmarks.html"

Format:

Primary heading := h1 Old version used this to set attributes on the bookmarks RDF root, such as the last modified date. We only use H1 to check for the attribute PLACES_ROOT, which tells us that this hierarchy root is the places root. For backwards compatability, if we don't find this, we assume that the hierarchy is rooted at the bookmarks menu. Heading := any heading other than h1 Old version used this to set attributes on the current container. We only care about the content of the heading container, which contains the title of the bookmark container. Bookmark := a HREF is the destination of the bookmark FEEDURL is the URI of the RSS feed if this is a livemark. LAST_CHARSET is stored as an annotation so that the next time we go to that page we remember the user's preference. WEB_PANEL is set to "true" if the bookmark should be loaded in the sidebar. ICON will be stored in the favicon service ICON_URI is new for places bookmarks.html, it refers to the original URI of the favicon so we don't have to make up favicon URLs. Text of the container is the name of the bookmark Ignored: LAST_VISIT, ID (writing out non-RDF IDs can confuse Firefox 2) Bookmark comment := dd This affects the previosly added bookmark Separator := hr Insert a separator into the current container The folder hierarchy is defined by

<menu> (the old importing code handles all these cases, when we write, use

.

Overall design

We need to emulate a recursive parser. A "Bookmark import frame" is created corresponding to each folder we encounter. These are arranged in a stack, and contain all the state we need to keep track of.

A frame is created when we find a heading, which defines a new container. The frame also keeps track of the nesting of

, (in well-formed bookmarks files, these will have a 1-1 correspondence with frames, but we try to be a little more flexible here). When the nesting count decreases to 0, then we know a frame is complete and to pop back to the previous frame.

Note that a lot of things happen when tags are CLOSED because we need to get the text from the content of the tag. For example, link and heading tags both require the content (= title) before actually creating it.

NS_IMPL_ISUPPORTS2 ( nsPlacesImportExportService  ,
nsIPlacesImportExportService  ,
nsINavHistoryBatchCallback   
)

Definition at line 317 of file nsPlacesImportExportService.cpp.

NS_IMPL_ISUPPORTS2 ( BookmarkContentSink  ,
nsIContentSink  ,
nsIHTMLContentSink   
)

Definition at line 501 of file nsPlacesImportExportService.cpp.

char* nsEscapeHTML ( const char *  string)

copied from nsEscape.cpp, which requires internal string API

Definition at line 252 of file nsPlacesImportExportService.cpp.

Here is the caller graph for this function:

static nsresult SyncChannelStatus ( nsIChannel channel,
nsresult  status 
)
static

Definition at line 1400 of file nsPlacesImportExportService.cpp.

static nsresult WriteContainerEpilogue ( const nsACString &  aIndent,
nsIOutputStream *  aOutput 
)
static

Definition at line 1483 of file nsPlacesImportExportService.cpp.

Here is the caller graph for this function:

static nsresult WriteContainerPrologue ( const nsACString &  aIndent,
nsIOutputStream *  aOutput 
)
static

Definition at line 1465 of file nsPlacesImportExportService.cpp.

Here is the caller graph for this function:

static nsresult WriteDateAttribute ( const char  aAttributeStart[],
PRInt32  aLength,
PRTime  aAttributeValue,
nsIOutputStream *  aOutput 
)
static

Definition at line 1568 of file nsPlacesImportExportService.cpp.

Here is the caller graph for this function:

nsresult WriteEscapedUrl ( const nsCString &  aString,
nsIOutputStream *  aOutput 
)
static

Definition at line 2107 of file nsPlacesImportExportService.cpp.

Here is the caller graph for this function:

static nsresult WriteFaviconAttribute ( const nsACString &  aURI,
nsIOutputStream *  aOutput 
)
static

Definition at line 1501 of file nsPlacesImportExportService.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

Variable Documentation

const char kBookmarkClose[] = "</DL><p>" "\012"
static

Definition at line 1428 of file nsPlacesImportExportService.cpp.

const char kBookmarkIntro[] = "<DL><p>" "\012"
static

Definition at line 1427 of file nsPlacesImportExportService.cpp.

const char kBookmarksRootAttribute[] = " BOOKMARKS_MENU=\"true\""
static

Definition at line 1441 of file nsPlacesImportExportService.cpp.

const char kCloseAngle[] = ">"
static

Definition at line 1435 of file nsPlacesImportExportService.cpp.

const char kCloseRootH1[] = "</H1>" "\012" "\012"
static

Definition at line 1425 of file nsPlacesImportExportService.cpp.

const char kContainerClose[] = "</H3>" "\012"
static

Definition at line 1430 of file nsPlacesImportExportService.cpp.

const char kContainerIntro[] = "<DT><H3"
static

Definition at line 1429 of file nsPlacesImportExportService.cpp.

const char kDateAddedAttribute[] = " ADD_DATE=\""
static

Definition at line 1454 of file nsPlacesImportExportService.cpp.

const char kDescriptionClose[] = "\012"
static

Definition at line 1438 of file nsPlacesImportExportService.cpp.

const char kDescriptionIntro[] = "<DD>"
static

Definition at line 1437 of file nsPlacesImportExportService.cpp.

const char kFeedURIAttribute[] = " FEEDURL=\""
static

Definition at line 1447 of file nsPlacesImportExportService.cpp.

char kFileIntro[]
static
Initial value:
=
"<!DOCTYPE NETSCAPE-Bookmark-file-1>" "\012"
"<!-- This is an automatically generated file." "\012"
" It will be read and overwritten." "\012"
" DO NOT EDIT! -->" "\012"
"<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=UTF-8\">" "\012"
"<TITLE>Bookmarks</TITLE>" "\012"

Definition at line 1416 of file nsPlacesImportExportService.cpp.

const char kHrefAttribute[] = " HREF=\""
static

Definition at line 1446 of file nsPlacesImportExportService.cpp.

const char kIconAttribute[] = " ICON=\""
static

Definition at line 1444 of file nsPlacesImportExportService.cpp.

const char kIconURIAttribute[] = " ICON_URI=\""
static

Definition at line 1445 of file nsPlacesImportExportService.cpp.

const char kIndent[] = " "
static

Definition at line 1436 of file nsPlacesImportExportService.cpp.

const char kItemClose[] = "</A>" "\012"
static

Definition at line 1432 of file nsPlacesImportExportService.cpp.

const char kItemIdAttribute[] = " ITEM_ID=\""
static

Definition at line 1451 of file nsPlacesImportExportService.cpp.

const char kItemOpen[] = "<DT><A"
static

Definition at line 1431 of file nsPlacesImportExportService.cpp.

const char kKeywordAttribute[] = " SHORTCUTURL=\""
static

Definition at line 1449 of file nsPlacesImportExportService.cpp.

const char kLastCharsetAttribute[] = " LAST_CHARSET=\""
static

Definition at line 1456 of file nsPlacesImportExportService.cpp.

const char kLastModifiedAttribute[] = " LAST_MODIFIED=\""
static

Definition at line 1455 of file nsPlacesImportExportService.cpp.

const char kMicsumGenURIAttribute[] = " MICSUM_GEN_URI=\""
static

Definition at line 1453 of file nsPlacesImportExportService.cpp.

const char kNameAttribute[] = " NAME=\""
static

Definition at line 1452 of file nsPlacesImportExportService.cpp.

const char kPlacesRootAttribute[] = " PLACES_ROOT=\"true\""
static

Definition at line 1440 of file nsPlacesImportExportService.cpp.

const char kPostDataAttribute[] = " POST_DATA=\""
static

Definition at line 1450 of file nsPlacesImportExportService.cpp.

const char kQuoteStr[] = "\""
static

Definition at line 1434 of file nsPlacesImportExportService.cpp.

const char kRootIntro[] = "<H1"
static

Definition at line 1424 of file nsPlacesImportExportService.cpp.

const char kSeparator[] = "<HR"
static

Definition at line 1433 of file nsPlacesImportExportService.cpp.

const char kToolbarFolderAttribute[] = " PERSONAL_TOOLBAR_FOLDER=\"true\""
static

Definition at line 1442 of file nsPlacesImportExportService.cpp.

const char kUnfiledBookmarksFolderAttribute[] = " UNFILED_BOOKMARKS_FOLDER=\"true\""
static

Definition at line 1443 of file nsPlacesImportExportService.cpp.

const char kWebPanelAttribute[] = " WEB_PANEL=\"true\""
static

Definition at line 1448 of file nsPlacesImportExportService.cpp.

const char kWhitespace[] = " \r\n\t\b"
static

Definition at line 156 of file nsPlacesImportExportService.cpp.