| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/utility/importer/bookmark_html_reader.h" | 5 #include "chrome/utility/importer/bookmark_html_reader.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include "base/callback.h" | 10 #include "base/callback.h" |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 favicon_base::FaviconUsageDataList* favicons) { | 114 favicon_base::FaviconUsageDataList* favicons) { |
| 115 std::string content; | 115 std::string content; |
| 116 base::ReadFileToString(file_path, &content); | 116 base::ReadFileToString(file_path, &content); |
| 117 std::vector<std::string> lines = base::SplitString( | 117 std::vector<std::string> lines = base::SplitString( |
| 118 content, "\n", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | 118 content, "\n", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
| 119 | 119 |
| 120 base::string16 last_folder; | 120 base::string16 last_folder; |
| 121 bool last_folder_on_toolbar = false; | 121 bool last_folder_on_toolbar = false; |
| 122 bool last_folder_is_empty = true; | 122 bool last_folder_is_empty = true; |
| 123 bool has_subfolder = false; | 123 bool has_subfolder = false; |
| 124 bool has_last_folder = false; |
| 124 base::Time last_folder_add_date; | 125 base::Time last_folder_add_date; |
| 125 std::vector<base::string16> path; | 126 std::vector<base::string16> path; |
| 126 size_t toolbar_folder_index = 0; | 127 size_t toolbar_folder_index = 0; |
| 127 std::string charset = "UTF-8"; // If no charset is specified, assume utf-8. | 128 std::string charset = "UTF-8"; // If no charset is specified, assume utf-8. |
| 128 for (size_t i = 0; | 129 for (size_t i = 0; |
| 129 i < lines.size() && | 130 i < lines.size() && |
| 130 (cancellation_callback.is_null() || !cancellation_callback.Run()); | 131 (cancellation_callback.is_null() || !cancellation_callback.Run()); |
| 131 ++i) { | 132 ++i) { |
| 132 std::string line; | 133 std::string line; |
| 133 base::TrimString(lines[i], " ", &line); | 134 base::TrimString(lines[i], " ", &line); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 146 // Get the encoding of the bookmark file. | 147 // Get the encoding of the bookmark file. |
| 147 if (internal::ParseCharsetFromLine(line, &charset)) | 148 if (internal::ParseCharsetFromLine(line, &charset)) |
| 148 continue; | 149 continue; |
| 149 | 150 |
| 150 // Get the folder name. | 151 // Get the folder name. |
| 151 if (internal::ParseFolderNameFromLine(line, | 152 if (internal::ParseFolderNameFromLine(line, |
| 152 charset, | 153 charset, |
| 153 &last_folder, | 154 &last_folder, |
| 154 &last_folder_on_toolbar, | 155 &last_folder_on_toolbar, |
| 155 &last_folder_add_date)) { | 156 &last_folder_add_date)) { |
| 157 has_last_folder = true; |
| 156 continue; | 158 continue; |
| 157 } | 159 } |
| 158 | 160 |
| 159 // Get the bookmark entry. | 161 // Get the bookmark entry. |
| 160 base::string16 title; | 162 base::string16 title; |
| 161 base::string16 shortcut; | 163 base::string16 shortcut; |
| 162 GURL url, favicon; | 164 GURL url, favicon; |
| 163 base::Time add_date; | 165 base::Time add_date; |
| 164 base::string16 post_data; | 166 base::string16 post_data; |
| 165 bool is_bookmark; | 167 bool is_bookmark; |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 entry.creation_time = add_date; | 202 entry.creation_time = add_date; |
| 201 entry.url = url; | 203 entry.url = url; |
| 202 entry.title = title; | 204 entry.title = title; |
| 203 | 205 |
| 204 if (toolbar_folder_index) { | 206 if (toolbar_folder_index) { |
| 205 // The toolbar folder should be at the top level. | 207 // The toolbar folder should be at the top level. |
| 206 entry.in_toolbar = true; | 208 entry.in_toolbar = true; |
| 207 entry.path.assign(path.begin() + toolbar_folder_index - 1, path.end()); | 209 entry.path.assign(path.begin() + toolbar_folder_index - 1, path.end()); |
| 208 } else { | 210 } else { |
| 209 // Add this bookmark to the list of |bookmarks|. | 211 // Add this bookmark to the list of |bookmarks|. |
| 210 if (!has_subfolder && !last_folder.empty()) { | 212 if (!has_subfolder && has_last_folder) { |
| 211 path.push_back(last_folder); | 213 path.push_back(last_folder); |
| 214 has_last_folder = false; |
| 212 last_folder.clear(); | 215 last_folder.clear(); |
| 213 } | 216 } |
| 214 entry.path.assign(path.begin(), path.end()); | 217 entry.path.assign(path.begin(), path.end()); |
| 215 } | 218 } |
| 216 bookmarks->push_back(entry); | 219 bookmarks->push_back(entry); |
| 217 | 220 |
| 218 // Save the favicon. DataURLToFaviconUsage will handle the case where | 221 // Save the favicon. DataURLToFaviconUsage will handle the case where |
| 219 // there is no favicon. | 222 // there is no favicon. |
| 220 if (favicons) | 223 if (favicons) |
| 221 DataURLToFaviconUsage(url, favicon, favicons); | 224 DataURLToFaviconUsage(url, favicon, favicons); |
| 222 | 225 |
| 223 continue; | 226 continue; |
| 224 } | 227 } |
| 225 | 228 |
| 226 // Bookmarks in sub-folder are encapsulated with <DL> tag. | 229 // Bookmarks in sub-folder are encapsulated with <DL> tag. |
| 227 if (base::StartsWith(line, "<DL>", base::CompareCase::INSENSITIVE_ASCII)) { | 230 if (base::StartsWith(line, "<DL>", base::CompareCase::INSENSITIVE_ASCII)) { |
| 228 has_subfolder = true; | 231 has_subfolder = true; |
| 229 if (!last_folder.empty()) { | 232 if (has_last_folder) { |
| 230 path.push_back(last_folder); | 233 path.push_back(last_folder); |
| 234 has_last_folder = false; |
| 231 last_folder.clear(); | 235 last_folder.clear(); |
| 232 } | 236 } |
| 233 if (last_folder_on_toolbar && !toolbar_folder_index) | 237 if (last_folder_on_toolbar && !toolbar_folder_index) |
| 234 toolbar_folder_index = path.size(); | 238 toolbar_folder_index = path.size(); |
| 235 | 239 |
| 236 // Mark next folder empty as initial state. | 240 // Mark next folder empty as initial state. |
| 237 last_folder_is_empty = true; | 241 last_folder_is_empty = true; |
| 238 } else if (base::StartsWith(line, "</DL>", | 242 } else if (base::StartsWith(line, "</DL>", |
| 239 base::CompareCase::INSENSITIVE_ASCII)) { | 243 base::CompareCase::INSENSITIVE_ASCII)) { |
| 240 if (path.empty()) | 244 if (path.empty()) |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 494 *url = GURL(value); | 498 *url = GURL(value); |
| 495 } | 499 } |
| 496 } | 500 } |
| 497 | 501 |
| 498 return true; | 502 return true; |
| 499 } | 503 } |
| 500 | 504 |
| 501 } // namespace internal | 505 } // namespace internal |
| 502 | 506 |
| 503 } // namespace bookmark_html_reader | 507 } // namespace bookmark_html_reader |
| OLD | NEW |