diff options
author | beng@google.com <beng@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-09-13 00:56:27 +0000 |
---|---|---|
committer | beng@google.com <beng@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-09-13 00:56:27 +0000 |
commit | 6c9851a40d3f6280dc322c2392d9cfcf8fba1b2d (patch) | |
tree | 91072da4d7f80596bcc437e82685cf7de7944dfe /chrome/browser/importer/firefox2_importer.h | |
parent | 231d5a36e476d013a91ca742bb8a0a2973cfee54 (diff) | |
download | chromium_src-6c9851a40d3f6280dc322c2392d9cfcf8fba1b2d.zip chromium_src-6c9851a40d3f6280dc322c2392d9cfcf8fba1b2d.tar.gz chromium_src-6c9851a40d3f6280dc322c2392d9cfcf8fba1b2d.tar.bz2 |
Move importer files into an importer subdirectory.
Also delete title chomper no one uses it.
B=2205
Review URL: http://codereview.chromium.org/3035
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@2154 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/importer/firefox2_importer.h')
-rw-r--r-- | chrome/browser/importer/firefox2_importer.h | 112 |
1 files changed, 112 insertions, 0 deletions
diff --git a/chrome/browser/importer/firefox2_importer.h b/chrome/browser/importer/firefox2_importer.h new file mode 100644 index 0000000..2c44993 --- /dev/null +++ b/chrome/browser/importer/firefox2_importer.h @@ -0,0 +1,112 @@ +// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_IMPORTER_FIREFOX2_IMPORTER_H_ +#define CHROME_BROWSER_IMPORTER_FIREFOX2_IMPORTER_H_ + +#include "chrome/browser/importer/importer.h" + +class TemplateURL; + +// Importer for Mozilla Firefox 2. +class Firefox2Importer : public Importer { + public: + Firefox2Importer(); + virtual ~Firefox2Importer(); + + // Importer methods. + virtual void StartImport(ProfileInfo profile_info, + uint16 items, + ProfileWriter* writer, + ImporterHost* host); + + // Loads the default bookmarks in the Firefox installed at |firefox_app_path|, + // and stores their locations in |urls|. + static void LoadDefaultBookmarks(const std::wstring& firefox_app_path, + std::set<GURL> *urls); + + // Creates a TemplateURL with the |keyword| and |url|. |title| may be empty. + // This function transfers ownership of the created TemplateURL to the caller. + static TemplateURL* CreateTemplateURL(const std::wstring& title, + const std::wstring& keyword, + const GURL& url); + + private: + FRIEND_TEST(FirefoxImporterTest, Firefox2BookmarkParse); + FRIEND_TEST(FirefoxImporterTest, Firefox2CookesParse); + + void ImportBookmarks(); + void ImportPasswords(); + void ImportHistory(); + void ImportSearchEngines(); + // Import the user's home page, unless it is set to default home page as + // defined in browserconfig.properties. + void ImportHomepage(); + + // Fills |files| with the paths to the files containing the search engine + // descriptions. + void GetSearchEnginesXMLFiles(std::vector<std::wstring>* files); + + // Helper methods for parsing bookmark file. + // Firefox 2 saves its bookmarks in a html file. We are interested in the + // bookmarks and folders, and their hierarchy. A folder starts with a + // heading tag, which contains it title. All bookmarks and sub-folders is + // following, and bracketed by a <DL> tag: + // <DT><H3 PERSONAL_TOOLBAR_FOLDER="true" ...>title</H3> + // <DL><p> + // ... container ... + // </DL><p> + // And a bookmark is presented by a <A> tag: + // <DT><A HREF="url" SHORTCUTURL="shortcut" ADD_DATE="11213014"...>name</A> + // Reference: http://kb.mozillazine.org/Bookmarks.html + static bool ParseCharsetFromLine(const std::string& line, + std::string* charset); + static bool ParseFolderNameFromLine(const std::string& line, + const std::string& charset, + std::wstring* folder_name, + bool* is_toolbar_folder); + // See above, this will also put the data: URL of the favicon into *favicon + // if there is a favicon given. |post_data| is set for POST base keywords to + // the contents of the actual POST (with %s for the search term). + static bool ParseBookmarkFromLine(const std::string& line, + const std::string& charset, + std::wstring* title, + GURL* url, + GURL* favicon, + std::wstring* shortcut, + Time* add_date, + std::wstring* post_data); + + // Fetches the given attribute value from the |tag|. Returns true if + // successful, and |value| will contain the value. + static bool GetAttribute(const std::string& tag, + const std::string& attribute, + std::string* value); + + // There are some characters in html file will be escaped: + // '<', '>', '"', '\', '&' + // Un-escapes them if the bookmark name has those characters. + static void HTMLUnescape(std::wstring* text); + + // Fills |xml_files| with the file with an xml extension found under |dir|. + static void FindXMLFilesInDir(const std::wstring& dir, + std::vector<std::wstring>* xml_files); + + // Given the URL of a page and a favicon data URL, adds an appropriate record + // to the given favicon usage vector. Will do nothing if the favicon is not + // valid. + static void DataURLToFaviconUsage( + const GURL& link_url, + const GURL& favicon_data, + std::vector<history::ImportedFavIconUsage>* favicons); + + ProfileWriter* writer_; + std::wstring source_path_; + std::wstring app_path_; + + DISALLOW_EVIL_CONSTRUCTORS(Firefox2Importer); +}; + +#endif // CHROME_BROWSER_IMPORTER_FIREFOX2_IMPORTER_H_ + |