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

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: 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 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 // separator in Firefox that Chrome does not support. Note that there can be 122 // separator in Firefox that Chrome does not support. Note that there can be
123 // multiple "<HR>" tags at the beginning of a single line. 123 // multiple "<HR>" tags at the beginning of a single line.
124 // See http://crbug.com/257474. 124 // See http://crbug.com/257474.
125 static const char kHrTag[] = "<HR>"; 125 static const char kHrTag[] = "<HR>";
126 while (base::StartsWith(line, kHrTag, 126 while (base::StartsWith(line, kHrTag,
127 base::CompareCase::INSENSITIVE_ASCII)) { 127 base::CompareCase::INSENSITIVE_ASCII)) {
128 line.erase(0, arraysize(kHrTag) - 1); 128 line.erase(0, arraysize(kHrTag) - 1);
129 base::TrimString(line, " ", &line); 129 base::TrimString(line, " ", &line);
130 } 130 }
131 131
132 // Remove "<DT>" if the line starts with "<DT>". This may not occur if
133 // "<DT>" was on the previous line. Liberally accept entries that do not
134 // have an opening "<DT>" at all.
135 static const char kDtTag[] = "<DT>";
136 if (base::StartsWith(line, kDtTag,
137 base::CompareCase::INSENSITIVE_ASCII)) {
Ilya Sherman 2016/04/13 00:11:11 nit: This indentation looks a bit off to me. Coul
Tom (Use chromium acct) 2016/04/14 01:43:56 Done.
138 line.erase(0, arraysize(kDtTag) - 1);
139 base::TrimString(line, " ", &line);
140 }
141
132 // Get the encoding of the bookmark file. 142 // Get the encoding of the bookmark file.
133 if (internal::ParseCharsetFromLine(line, &charset)) 143 if (internal::ParseCharsetFromLine(line, &charset))
134 continue; 144 continue;
135 145
136 // Get the folder name. 146 // Get the folder name.
137 if (internal::ParseFolderNameFromLine(line, 147 if (internal::ParseFolderNameFromLine(line,
138 charset, 148 charset,
139 &last_folder, 149 &last_folder,
140 &last_folder_on_toolbar, 150 &last_folder_on_toolbar,
141 &last_folder_add_date)) { 151 &last_folder_add_date)) {
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 return true; 306 return true;
297 } 307 }
298 return false; 308 return false;
299 } 309 }
300 310
301 bool ParseFolderNameFromLine(const std::string& line, 311 bool ParseFolderNameFromLine(const std::string& line,
302 const std::string& charset, 312 const std::string& charset,
303 base::string16* folder_name, 313 base::string16* folder_name,
304 bool* is_toolbar_folder, 314 bool* is_toolbar_folder,
305 base::Time* add_date) { 315 base::Time* add_date) {
306 const char kFolderOpen[] = "<DT><H3"; 316 const char kFolderOpen[] = "<H3";
307 const char kFolderClose[] = "</H3>"; 317 const char kFolderClose[] = "</H3>";
308 const char kToolbarFolderAttribute[] = "PERSONAL_TOOLBAR_FOLDER"; 318 const char kToolbarFolderAttribute[] = "PERSONAL_TOOLBAR_FOLDER";
309 const char kAddDateAttribute[] = "ADD_DATE"; 319 const char kAddDateAttribute[] = "ADD_DATE";
310 320
311 if (!base::StartsWith(line, kFolderOpen, base::CompareCase::SENSITIVE)) 321 if (!base::StartsWith(line, kFolderOpen, base::CompareCase::SENSITIVE))
312 return false; 322 return false;
313 323
314 size_t end = line.find(kFolderClose); 324 size_t end = line.find(kFolderClose);
315 size_t tag_end = line.rfind('>', end) + 1; 325 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. 326 // If no end tag or start tag is broken, we skip to find the folder name.
(...skipping 27 matching lines...) Expand all
344 } 354 }
345 355
346 bool ParseBookmarkFromLine(const std::string& line, 356 bool ParseBookmarkFromLine(const std::string& line,
347 const std::string& charset, 357 const std::string& charset,
348 base::string16* title, 358 base::string16* title,
349 GURL* url, 359 GURL* url,
350 GURL* favicon, 360 GURL* favicon,
351 base::string16* shortcut, 361 base::string16* shortcut,
352 base::Time* add_date, 362 base::Time* add_date,
353 base::string16* post_data) { 363 base::string16* post_data) {
354 const char kItemOpen[] = "<DT><A"; 364 const char kItemOpen[] = "<A";
355 const char kItemClose[] = "</A>"; 365 const char kItemClose[] = "</A>";
356 const char kFeedURLAttribute[] = "FEEDURL"; 366 const char kFeedURLAttribute[] = "FEEDURL";
357 const char kHrefAttribute[] = "HREF"; 367 const char kHrefAttribute[] = "HREF";
358 const char kIconAttribute[] = "ICON"; 368 const char kIconAttribute[] = "ICON";
359 const char kShortcutURLAttribute[] = "SHORTCUTURL"; 369 const char kShortcutURLAttribute[] = "SHORTCUTURL";
360 const char kAddDateAttribute[] = "ADD_DATE"; 370 const char kAddDateAttribute[] = "ADD_DATE";
361 const char kPostDataAttribute[] = "POST_DATA"; 371 const char kPostDataAttribute[] = "POST_DATA";
362 372
363 title->clear(); 373 title->clear();
364 *url = GURL(); 374 *url = GURL();
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 *post_data = net::UnescapeForHTML(*post_data); 437 *post_data = net::UnescapeForHTML(*post_data);
428 } 438 }
429 439
430 return true; 440 return true;
431 } 441 }
432 442
433 bool ParseMinimumBookmarkFromLine(const std::string& line, 443 bool ParseMinimumBookmarkFromLine(const std::string& line,
434 const std::string& charset, 444 const std::string& charset,
435 base::string16* title, 445 base::string16* title,
436 GURL* url) { 446 GURL* url) {
437 const char kItemOpen[] = "<DT><A"; 447 const char kItemOpen[] = "<A";
438 const char kItemClose[] = "</"; 448 const char kItemClose[] = "</";
439 const char kHrefAttributeUpper[] = "HREF"; 449 const char kHrefAttributeUpper[] = "HREF";
440 const char kHrefAttributeLower[] = "href"; 450 const char kHrefAttributeLower[] = "href";
441 451
442 title->clear(); 452 title->clear();
443 *url = GURL(); 453 *url = GURL();
444 454
445 // Case-insensitive check of open tag. 455 // Case-insensitive check of open tag.
446 if (!base::StartsWith(line, kItemOpen, base::CompareCase::INSENSITIVE_ASCII)) 456 if (!base::StartsWith(line, kItemOpen, base::CompareCase::INSENSITIVE_ASCII))
447 return false; 457 return false;
(...skipping 27 matching lines...) Expand all
475 *url = GURL(value); 485 *url = GURL(value);
476 } 486 }
477 } 487 }
478 488
479 return true; 489 return true;
480 } 490 }
481 491
482 } // namespace internal 492 } // namespace internal
483 493
484 } // namespace bookmark_html_reader 494 } // namespace bookmark_html_reader
OLDNEW
« no previous file with comments | « chrome/test/data/bookmark_html_reader/redditsaver.html ('k') | chrome/utility/importer/bookmark_html_reader_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698