Fix broken path in extensions/common/PRESUBMIT.py
[chromium-blink-merge.git] / chrome / utility / importer / bookmark_html_reader.h
blob8150347cefd0bc7cf6cccbce838ad8aae717c9f8
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef CHROME_UTILITY_IMPORTER_BOOKMARK_HTML_READER_H_
6 #define CHROME_UTILITY_IMPORTER_BOOKMARK_HTML_READER_H_
8 #include <string>
9 #include <vector>
11 #include "base/callback_forward.h"
12 #include "base/strings/string16.h"
13 #include "chrome/common/importer/importer_data_types.h"
14 #include "components/favicon_base/favicon_usage_data.h"
16 class GURL;
17 struct ImportedBookmarkEntry;
19 namespace base {
20 class FilePath;
21 class Time;
24 namespace bookmark_html_reader {
26 // Imports the bookmarks from the specified file.
28 // |cancellation_callback| is polled to query if the import should be cancelled;
29 // if it returns |true| at any time the import will be cancelled. If
30 // |cancellation_callback| is a null callback the import will run to completion.
32 // |valid_url_callback| is called to determine if a specified URL is valid for
33 // import; it returns |true| if it is. If |valid_url_callback| is a null
34 // callback, all URLs are considered to be valid.
36 // |file_path| is the path of the file on disk to import.
38 // |bookmarks| is a pointer to a vector, which is filled with the imported
39 // bookmarks. It may not be NULL.
41 // |search_engines| is a pointer to a vector, which is filled with the imported
42 // search engines.
44 // |favicons| is a pointer to a vector, which is filled with the favicons of
45 // imported bookmarks. It may be NULL, in which case favicons are not imported.
46 void ImportBookmarksFile(
47 const base::Callback<bool(void)>& cancellation_callback,
48 const base::Callback<bool(const GURL&)>& valid_url_callback,
49 const base::FilePath& file_path,
50 std::vector<ImportedBookmarkEntry>* bookmarks,
51 std::vector<importer::SearchEngineInfo>* search_engines,
52 favicon_base::FaviconUsageDataList* favicons);
54 // Returns true if |url| should be imported as a search engine, i.e. because it
55 // has replacement terms. Chrome treats such bookmarks as search engines rather
56 // than true bookmarks.
57 bool CanImportURLAsSearchEngine(const GURL& url,
58 std::string* search_engine_url);
60 namespace internal {
62 // The file format that BookmarkHTMLReader parses starts with a heading
63 // tag, which contains its title. All bookmarks and sub-folders follow,
64 // bracketed by a <DL> tag:
65 // <DT><H3 PERSONAL_TOOLBAR_FOLDER="true" ...>title</H3>
66 // <DL><p>
67 // ... container ...
68 // </DL><p>
69 // And a bookmark is presented by a <A> tag:
70 // <DT><A HREF="url" SHORTCUTURL="shortcut" ADD_DATE="11213014"...>name</A>
71 // Reference: http://kb.mozillazine.org/Bookmarks.html
73 bool ParseCharsetFromLine(const std::string& line,
74 std::string* charset);
75 bool ParseFolderNameFromLine(const std::string& line,
76 const std::string& charset,
77 base::string16* folder_name,
78 bool* is_toolbar_folder,
79 base::Time* add_date);
80 // See above, this will also put the data: URL of the favicon into |*favicon|
81 // if there is a favicon given. |post_data| is set for POST base keywords to
82 // the contents of the actual POST (with %s for the search term).
83 bool ParseBookmarkFromLine(const std::string& line,
84 const std::string& charset,
85 base::string16* title,
86 GURL* url,
87 GURL* favicon,
88 base::string16* shortcut,
89 base::Time* add_date,
90 base::string16* post_data);
91 // Save bookmarks imported from browsers with Firefox 2 compatible bookmark
92 // systems such as Epiphany. This bookmark format is the same as that of the
93 // basic Firefox 2 bookmark, but it misses additional properties and uses
94 // lower-case tag:
95 // ...<h1>Bookmarks</h1><dl>
96 // <dt><a href="url">name</a></dt>
97 // <dt><a href="url">name</a></dt>
98 // </dl>
99 bool ParseMinimumBookmarkFromLine(const std::string& line,
100 const std::string& charset,
101 base::string16* title,
102 GURL* url);
104 } // namespace internal
106 } // namespace bookmark_html_reader
108 #endif // CHROME_UTILITY_IMPORTER_BOOKMARK_HTML_READER_H_