File: bookmark_html_reader.h

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (110 lines) | stat: -rw-r--r-- 4,454 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// Copyright 2013 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_UTILITY_IMPORTER_BOOKMARK_HTML_READER_H_
#define CHROME_UTILITY_IMPORTER_BOOKMARK_HTML_READER_H_

#include <string>
#include <vector>

#include "base/functional/callback_forward.h"
#include "components/favicon_base/favicon_usage_data.h"
#include "components/user_data_importer/common/importer_data_types.h"

class GURL;

namespace user_data_importer {
struct ImportedBookmarkEntry;
}  // namespace user_data_importer

namespace base {
class FilePath;
class Time;
}

namespace bookmark_html_reader {

// Imports the bookmarks from the specified file.
//
// |cancellation_callback| is polled to query if the import should be cancelled;
// if it returns |true| at any time the import will be cancelled. If
// |cancellation_callback| is a null callback the import will run to completion.
//
// |valid_url_callback| is called to determine if a specified URL is valid for
// import; it returns |true| if it is. If |valid_url_callback| is a null
// callback, all URLs are considered to be valid.
//
// |file_path| is the path of the file on disk to import.
//
// |bookmarks| is a pointer to a vector, which is filled with the imported
// bookmarks. It may not be NULL.
//
// |search_engines| is a pointer to a vector, which is filled with the imported
// search engines.
//
// |favicons| is a pointer to a vector, which is filled with the favicons of
// imported bookmarks. It may be NULL, in which case favicons are not imported.
void ImportBookmarksFile(
    base::RepeatingCallback<bool(void)> cancellation_callback,
    base::RepeatingCallback<bool(const GURL&)> valid_url_callback,
    const base::FilePath& file_path,
    std::vector<user_data_importer::ImportedBookmarkEntry>* bookmarks,
    std::vector<user_data_importer::SearchEngineInfo>* search_engines,
    favicon_base::FaviconUsageDataList* favicons);

// Returns true if |url| should be imported as a search engine, i.e. because it
// has replacement terms. Chrome treats such bookmarks as search engines rather
// than true bookmarks.
bool CanImportURLAsSearchEngine(const GURL& url,
                                std::string* search_engine_url);

namespace internal {

// The file format that BookmarkHTMLReader parses starts with a heading
// tag, which contains its title. All bookmarks and sub-folders follow,
// 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

bool ParseCharsetFromLine(const std::string& line,
                          std::string* charset);
bool ParseFolderNameFromLine(const std::string& line,
                             const std::string& charset,
                             std::u16string* folder_name,
                             bool* is_toolbar_folder,
                             base::Time* add_date);
// 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).
bool ParseBookmarkFromLine(const std::string& line,
                           const std::string& charset,
                           std::u16string* title,
                           GURL* url,
                           GURL* favicon,
                           std::u16string* shortcut,
                           base::Time* add_date,
                           std::u16string* post_data);
// Save bookmarks imported from browsers with Firefox 2 compatible bookmark
// systems such as Epiphany. This bookmark format is the same as that of the
// basic Firefox 2 bookmark, but it misses additional properties and uses
// lower-case tag:
//   ...<h1>Bookmarks</h1><dl>
//   <dt><a href="url">name</a></dt>
//   <dt><a href="url">name</a></dt>
//   </dl>
bool ParseMinimumBookmarkFromLine(const std::string& line,
                                  const std::string& charset,
                                  std::u16string* title,
                                  GURL* url);

}  // namespace internal

}  // namespace bookmark_html_reader

#endif  // CHROME_UTILITY_IMPORTER_BOOKMARK_HTML_READER_H_