Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(118)

Side by Side Diff: chrome/utility/importer/bookmark_html_reader.cc

Issue 1873403003: Read bookmarks from 'NETSCAPE-Bookmark-file's that don't have a beginning <DT> tag. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed failing tests Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 // We only have one URL per favicon for Firefox 2 bookmarks. 84 // We only have one URL per favicon for Firefox 2 bookmarks.
85 usage.urls.insert(link_url); 85 usage.urls.insert(link_url);
86 86
87 favicons->push_back(usage); 87 favicons->push_back(usage);
88 } 88 }
89 89
90 } // namespace 90 } // namespace
91 91
92 namespace bookmark_html_reader { 92 namespace bookmark_html_reader {
93 93
94 static void stripDt(std::string& line) {
95 // Remove "<DT>" if the line starts with "<DT>". This may not occur if
96 // "<DT>" was on the previous line. Liberally accept entries that do not
97 // have an opening "<DT>" at all.
98 static const char kDtTag[] = "<DT>";
99 if (base::StartsWith(line, kDtTag,
100 base::CompareCase::INSENSITIVE_ASCII)) {
101 line.erase(0, arraysize(kDtTag) - 1);
102 base::TrimString(line, " ", &line);
103 }
104 }
105
94 void ImportBookmarksFile( 106 void ImportBookmarksFile(
95 const base::Callback<bool(void)>& cancellation_callback, 107 const base::Callback<bool(void)>& cancellation_callback,
96 const base::Callback<bool(const GURL&)>& valid_url_callback, 108 const base::Callback<bool(const GURL&)>& valid_url_callback,
97 const base::FilePath& file_path, 109 const base::FilePath& file_path,
98 std::vector<ImportedBookmarkEntry>* bookmarks, 110 std::vector<ImportedBookmarkEntry>* bookmarks,
99 std::vector<importer::SearchEngineInfo>* search_engines, 111 std::vector<importer::SearchEngineInfo>* search_engines,
100 favicon_base::FaviconUsageDataList* favicons) { 112 favicon_base::FaviconUsageDataList* favicons) {
101 std::string content; 113 std::string content;
102 base::ReadFileToString(file_path, &content); 114 base::ReadFileToString(file_path, &content);
103 std::vector<std::string> lines = base::SplitString( 115 std::vector<std::string> lines = base::SplitString(
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 if (begin == std::string::npos) 303 if (begin == std::string::npos)
292 return false; 304 return false;
293 begin += std::string(kCharset).size(); 305 begin += std::string(kCharset).size();
294 size_t end = line.find_first_of('\"', begin); 306 size_t end = line.find_first_of('\"', begin);
295 *charset = line.substr(begin, end - begin); 307 *charset = line.substr(begin, end - begin);
296 return true; 308 return true;
297 } 309 }
298 return false; 310 return false;
299 } 311 }
300 312
301 bool ParseFolderNameFromLine(const std::string& line, 313 bool ParseFolderNameFromLine(std::string line,
Ilya Sherman 2016/04/14 02:22:53 Even if you want to modify the variable in the met
Tom (Use chromium acct) 2016/04/14 17:21:44 Done.
302 const std::string& charset, 314 const std::string& charset,
303 base::string16* folder_name, 315 base::string16* folder_name,
304 bool* is_toolbar_folder, 316 bool* is_toolbar_folder,
305 base::Time* add_date) { 317 base::Time* add_date) {
306 const char kFolderOpen[] = "<DT><H3"; 318 const char kFolderOpen[] = "<H3";
307 const char kFolderClose[] = "</H3>"; 319 const char kFolderClose[] = "</H3>";
308 const char kToolbarFolderAttribute[] = "PERSONAL_TOOLBAR_FOLDER"; 320 const char kToolbarFolderAttribute[] = "PERSONAL_TOOLBAR_FOLDER";
309 const char kAddDateAttribute[] = "ADD_DATE"; 321 const char kAddDateAttribute[] = "ADD_DATE";
310 322
323 stripDt(line);
Ilya Sherman 2016/04/14 02:22:53 Hmm, why do you need to also strip DT tags here, r
Tom (Use chromium acct) 2016/04/14 17:21:44 I removed the code that strips the DT near where w
324
311 if (!base::StartsWith(line, kFolderOpen, base::CompareCase::SENSITIVE)) 325 if (!base::StartsWith(line, kFolderOpen, base::CompareCase::SENSITIVE))
312 return false; 326 return false;
313 327
314 size_t end = line.find(kFolderClose); 328 size_t end = line.find(kFolderClose);
315 size_t tag_end = line.rfind('>', end) + 1; 329 size_t tag_end = line.rfind('>', end) + 1;
316 // If no end tag or start tag is broken, we skip to find the folder name. 330 // If no end tag or start tag is broken, we skip to find the folder name.
317 if (end == std::string::npos || tag_end < arraysize(kFolderOpen)) 331 if (end == std::string::npos || tag_end < arraysize(kFolderOpen))
318 return false; 332 return false;
319 333
320 base::CodepageToUTF16(line.substr(tag_end, end - tag_end), charset.c_str(), 334 base::CodepageToUTF16(line.substr(tag_end, end - tag_end), charset.c_str(),
(...skipping 15 matching lines...) Expand all
336 350
337 if (GetAttribute(attribute_list, kToolbarFolderAttribute, &value) && 351 if (GetAttribute(attribute_list, kToolbarFolderAttribute, &value) &&
338 base::LowerCaseEqualsASCII(value, "true")) 352 base::LowerCaseEqualsASCII(value, "true"))
339 *is_toolbar_folder = true; 353 *is_toolbar_folder = true;
340 else 354 else
341 *is_toolbar_folder = false; 355 *is_toolbar_folder = false;
342 356
343 return true; 357 return true;
344 } 358 }
345 359
346 bool ParseBookmarkFromLine(const std::string& line, 360 bool ParseBookmarkFromLine(std::string line,
347 const std::string& charset, 361 const std::string& charset,
348 base::string16* title, 362 base::string16* title,
349 GURL* url, 363 GURL* url,
350 GURL* favicon, 364 GURL* favicon,
351 base::string16* shortcut, 365 base::string16* shortcut,
352 base::Time* add_date, 366 base::Time* add_date,
353 base::string16* post_data) { 367 base::string16* post_data) {
354 const char kItemOpen[] = "<DT><A"; 368 const char kItemOpen[] = "<A";
355 const char kItemClose[] = "</A>"; 369 const char kItemClose[] = "</A>";
356 const char kFeedURLAttribute[] = "FEEDURL"; 370 const char kFeedURLAttribute[] = "FEEDURL";
357 const char kHrefAttribute[] = "HREF"; 371 const char kHrefAttribute[] = "HREF";
358 const char kIconAttribute[] = "ICON"; 372 const char kIconAttribute[] = "ICON";
359 const char kShortcutURLAttribute[] = "SHORTCUTURL"; 373 const char kShortcutURLAttribute[] = "SHORTCUTURL";
360 const char kAddDateAttribute[] = "ADD_DATE"; 374 const char kAddDateAttribute[] = "ADD_DATE";
361 const char kPostDataAttribute[] = "POST_DATA"; 375 const char kPostDataAttribute[] = "POST_DATA";
362 376
377 stripDt(line);
363 title->clear(); 378 title->clear();
364 *url = GURL(); 379 *url = GURL();
365 *favicon = GURL(); 380 *favicon = GURL();
366 shortcut->clear(); 381 shortcut->clear();
367 post_data->clear(); 382 post_data->clear();
368 *add_date = base::Time(); 383 *add_date = base::Time();
369 384
370 if (!base::StartsWith(line, kItemOpen, base::CompareCase::SENSITIVE)) 385 if (!base::StartsWith(line, kItemOpen, base::CompareCase::SENSITIVE))
371 return false; 386 return false;
372 387
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 // Post data. 438 // Post data.
424 if (GetAttribute(attribute_list, kPostDataAttribute, &value)) { 439 if (GetAttribute(attribute_list, kPostDataAttribute, &value)) {
425 base::CodepageToUTF16(value, charset.c_str(), 440 base::CodepageToUTF16(value, charset.c_str(),
426 base::OnStringConversionError::SKIP, post_data); 441 base::OnStringConversionError::SKIP, post_data);
427 *post_data = net::UnescapeForHTML(*post_data); 442 *post_data = net::UnescapeForHTML(*post_data);
428 } 443 }
429 444
430 return true; 445 return true;
431 } 446 }
432 447
433 bool ParseMinimumBookmarkFromLine(const std::string& line, 448 bool ParseMinimumBookmarkFromLine(std::string line,
434 const std::string& charset, 449 const std::string& charset,
435 base::string16* title, 450 base::string16* title,
436 GURL* url) { 451 GURL* url) {
437 const char kItemOpen[] = "<DT><A"; 452 const char kItemOpen[] = "<A";
438 const char kItemClose[] = "</"; 453 const char kItemClose[] = "</";
439 const char kHrefAttributeUpper[] = "HREF"; 454 const char kHrefAttributeUpper[] = "HREF";
440 const char kHrefAttributeLower[] = "href"; 455 const char kHrefAttributeLower[] = "href";
441 456
457 stripDt(line);
442 title->clear(); 458 title->clear();
443 *url = GURL(); 459 *url = GURL();
444 460
445 // Case-insensitive check of open tag. 461 // Case-insensitive check of open tag.
446 if (!base::StartsWith(line, kItemOpen, base::CompareCase::INSENSITIVE_ASCII)) 462 if (!base::StartsWith(line, kItemOpen, base::CompareCase::INSENSITIVE_ASCII))
447 return false; 463 return false;
448 464
449 // Find any close tag. 465 // Find any close tag.
450 size_t end = line.find(kItemClose); 466 size_t end = line.find(kItemClose);
451 size_t tag_end = line.rfind('>', end) + 1; 467 size_t tag_end = line.rfind('>', end) + 1;
(...skipping 23 matching lines...) Expand all
475 *url = GURL(value); 491 *url = GURL(value);
476 } 492 }
477 } 493 }
478 494
479 return true; 495 return true;
480 } 496 }
481 497
482 } // namespace internal 498 } // namespace internal
483 499
484 } // namespace bookmark_html_reader 500 } // namespace bookmark_html_reader
OLDNEW
« no previous file with comments | « chrome/utility/importer/bookmark_html_reader.h ('k') | chrome/utility/importer/bookmark_html_reader_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698