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

Side by Side Diff: chrome/browser/importer/firefox2_importer.cc

Issue 126036: Patch to solve the problem in import export bookmarks (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: '' Created 11 years, 5 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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/browser/importer/firefox2_importer.h" 5 #include "chrome/browser/importer/firefox2_importer.h"
6 6
7 #include "app/l10n_util.h" 7 #include "app/l10n_util.h"
8 #include "base/file_path.h" 8 #include "base/file_path.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
(...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after
440 if (GetAttribute(attribute_list, kFeedURLAttribute, &value)) 440 if (GetAttribute(attribute_list, kFeedURLAttribute, &value))
441 return false; 441 return false;
442 442
443 // Title 443 // Title
444 CodepageToWide(line.substr(tag_end, end - tag_end), charset.c_str(), 444 CodepageToWide(line.substr(tag_end, end - tag_end), charset.c_str(),
445 OnStringUtilConversionError::SKIP, title); 445 OnStringUtilConversionError::SKIP, title);
446 HTMLUnescape(title); 446 HTMLUnescape(title);
447 447
448 // URL 448 // URL
449 if (GetAttribute(attribute_list, kHrefAttribute, &value)) { 449 if (GetAttribute(attribute_list, kHrefAttribute, &value)) {
450 ReplaceSubstringsAfterOffset(&value, 0, "%22", "\""); 450 std::wstring w_url;
451 *url = GURL(value); 451 CodepageToWide(value, charset.c_str(), OnStringUtilConversionError::SKIP,
452 &w_url);
453 HTMLUnescape(&w_url);
454
455 string16 url16 = WideToUTF16Hack(w_url);
456
457 *url = GURL(url16);
452 } 458 }
453 459
454 // Favicon 460 // Favicon
455 if (GetAttribute(attribute_list, kIconAttribute, &value)) 461 if (GetAttribute(attribute_list, kIconAttribute, &value))
456 *favicon = GURL(value); 462 *favicon = GURL(value);
457 463
458 // Keyword 464 // Keyword
459 if (GetAttribute(attribute_list, kShortcutURLAttribute, &value)) { 465 if (GetAttribute(attribute_list, kShortcutURLAttribute, &value)) {
460 CodepageToWide(value, charset.c_str(), OnStringUtilConversionError::SKIP, 466 CodepageToWide(value, charset.c_str(), OnStringUtilConversionError::SKIP,
461 shortcut); 467 shortcut);
(...skipping 22 matching lines...) Expand all
484 bool Firefox2Importer::GetAttribute(const std::string& attribute_list, 490 bool Firefox2Importer::GetAttribute(const std::string& attribute_list,
485 const std::string& attribute, 491 const std::string& attribute,
486 std::string* value) { 492 std::string* value) {
487 const char kQuote[] = "\""; 493 const char kQuote[] = "\"";
488 494
489 size_t begin = attribute_list.find(attribute + "=" + kQuote); 495 size_t begin = attribute_list.find(attribute + "=" + kQuote);
490 if (begin == std::string::npos) 496 if (begin == std::string::npos)
491 return false; // Can't find the attribute. 497 return false; // Can't find the attribute.
492 498
493 begin = attribute_list.find(kQuote, begin) + 1; 499 begin = attribute_list.find(kQuote, begin) + 1;
494 size_t end = attribute_list.find(kQuote, begin); 500
495 if (end == std::string::npos) 501 size_t end = begin + 1;
502 while (end < attribute_list.size()) {
503 if (attribute_list[end] == '"' &&
504 attribute_list[end - 1] != '\\') {
505 break;
506 }
507 end++;
508 }
509
510 if (end == attribute_list.size())
496 return false; // The value is not quoted. 511 return false; // The value is not quoted.
497 512
498 *value = attribute_list.substr(begin, end - begin); 513 *value = attribute_list.substr(begin, end - begin);
499 return true; 514 return true;
500 } 515 }
501 516
502 // static 517 // static
503 void Firefox2Importer::HTMLUnescape(std::wstring *text) { 518 void Firefox2Importer::HTMLUnescape(std::wstring *text) {
504 string16 text16 = WideToUTF16Hack(*text); 519 string16 text16 = WideToUTF16Hack(*text);
505 ReplaceSubstringsAfterOffset( 520 ReplaceSubstringsAfterOffset(
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
551 566
552 // We need to make up a URL for the favicon. We use a version of the page's 567 // We need to make up a URL for the favicon. We use a version of the page's
553 // URL so that we can be sure it will not collide. 568 // URL so that we can be sure it will not collide.
554 usage.favicon_url = GURL(std::string("made-up-favicon:") + link_url.spec()); 569 usage.favicon_url = GURL(std::string("made-up-favicon:") + link_url.spec());
555 570
556 // We only have one URL per favicon for Firefox 2 bookmarks. 571 // We only have one URL per favicon for Firefox 2 bookmarks.
557 usage.urls.insert(link_url); 572 usage.urls.insert(link_url);
558 573
559 favicons->push_back(usage); 574 favicons->push_back(usage);
560 } 575 }
OLDNEW
« no previous file with comments | « chrome/browser/bookmarks/bookmark_html_writer_unittest.cc ('k') | chrome/browser/importer/firefox_importer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698