diff options
author | Kristian Monsen <kristianm@google.com> | 2011-05-31 20:30:28 +0100 |
---|---|---|
committer | Kristian Monsen <kristianm@google.com> | 2011-06-14 20:31:41 -0700 |
commit | 72a454cd3513ac24fbdd0e0cb9ad70b86a99b801 (patch) | |
tree | 382278a54ce7a744d62fa510a9a80688cc12434b /chrome/browser/importer | |
parent | c4becdd46e31d261b930e4b5a539cbc1d45c23a6 (diff) | |
download | external_chromium-72a454cd3513ac24fbdd0e0cb9ad70b86a99b801.zip external_chromium-72a454cd3513ac24fbdd0e0cb9ad70b86a99b801.tar.gz external_chromium-72a454cd3513ac24fbdd0e0cb9ad70b86a99b801.tar.bz2 |
Merge Chromium.org at r11.0.672.0: Initial merge by git.
Change-Id: I8b4aaf611a2a405fe3fe10e8a94ea7658645c192
Diffstat (limited to 'chrome/browser/importer')
27 files changed, 444 insertions, 248 deletions
diff --git a/chrome/browser/importer/firefox2_importer.cc b/chrome/browser/importer/firefox2_importer.cc index 7783a7c..bf68af0 100644 --- a/chrome/browser/importer/firefox2_importer.cc +++ b/chrome/browser/importer/firefox2_importer.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -140,9 +140,9 @@ TemplateURL* Firefox2Importer::CreateTemplateURL(const std::wstring& title, TemplateURL* t_url = new TemplateURL(); // We set short name by using the title if it exists. // Otherwise, we use the shortcut. - t_url->set_short_name(!title.empty() ? title : keyword); - t_url->set_keyword(keyword); - t_url->SetURL(TemplateURLRef::DisplayURLToURLRef(UTF8ToWide(url.spec())), + t_url->set_short_name(WideToUTF16Hack(!title.empty() ? title : keyword)); + t_url->set_keyword(WideToUTF16Hack(keyword)); + t_url->SetURL(TemplateURLRef::DisplayURLToURLRef(UTF8ToUTF16(url.spec())), 0, 0); return t_url; } @@ -165,6 +165,8 @@ void Firefox2Importer::ImportBookmarksFile( std::vector<ProfileWriter::BookmarkEntry> toolbar_bookmarks; std::wstring last_folder = first_folder_name; bool last_folder_on_toolbar = false; + bool last_folder_is_empty = true; + Time last_folder_add_date; std::vector<std::wstring> path; size_t toolbar_folder = 0; std::string charset; @@ -179,7 +181,8 @@ void Firefox2Importer::ImportBookmarksFile( // Get the folder name. if (ParseFolderNameFromLine(line, charset, &last_folder, - &last_folder_on_toolbar)) + &last_folder_on_toolbar, + &last_folder_add_date)) continue; // Get the bookmark entry. @@ -187,11 +190,18 @@ void Firefox2Importer::ImportBookmarksFile( GURL url, favicon; Time add_date; std::wstring post_data; + bool is_bookmark; // TODO(jcampan): http://b/issue?id=1196285 we do not support POST based // keywords yet. - if (ParseBookmarkFromLine(line, charset, &title, - &url, &favicon, &shortcut, &add_date, - &post_data) && + is_bookmark = ParseBookmarkFromLine(line, charset, &title, + &url, &favicon, &shortcut, &add_date, + &post_data) || + ParseMinimumBookmarkFromLine(line, charset, &title, &url); + + if (is_bookmark) + last_folder_is_empty = false; + + if (is_bookmark && post_data.empty() && CanImportURL(GURL(url)) && default_urls.find(url) == default_urls.end()) { @@ -235,15 +245,44 @@ void Firefox2Importer::ImportBookmarksFile( } // Bookmarks in sub-folder are encapsulated with <DL> tag. - if (StartsWithASCII(line, "<DL>", true)) { + if (StartsWithASCII(line, "<DL>", false)) { path.push_back(last_folder); last_folder.clear(); if (last_folder_on_toolbar && !toolbar_folder) toolbar_folder = path.size(); - } else if (StartsWithASCII(line, "</DL>", true)) { + + // Mark next folder empty as initial state. + last_folder_is_empty = true; + } else if (StartsWithASCII(line, "</DL>", false)) { if (path.empty()) break; // Mismatch <DL>. + + std::wstring folder_title = path.back(); path.pop_back(); + + if (last_folder_is_empty) { + // Empty folder should be added explicitly. + ProfileWriter::BookmarkEntry entry; + entry.is_folder = true; + entry.creation_time = last_folder_add_date; + entry.title = folder_title; + if (import_to_bookmark_bar && toolbar_folder) { + // Flatten the folder in toolbar. + entry.in_toolbar = true; + entry.path.assign(path.begin() + toolbar_folder, path.end()); + toolbar_bookmarks.push_back(entry); + } else { + // Insert the folder into the "Imported from Firefox" folder. + entry.path.assign(path.begin(), path.end()); + if (import_to_bookmark_bar) + entry.path.erase(entry.path.begin()); + bookmarks->push_back(entry); + } + + // Parent folder include current one, so it's not empty. + last_folder_is_empty = false; + } + if (toolbar_folder > path.size()) toolbar_folder = 0; } @@ -298,10 +337,8 @@ void Firefox2Importer::ImportBookmarks() { void Firefox2Importer::ImportPasswords() { // Initializes NSS3. NSSDecryptor decryptor; - if (!decryptor.Init(source_path_.ToWStringHack(), - source_path_.ToWStringHack()) && - !decryptor.Init(app_path_.ToWStringHack(), - source_path_.ToWStringHack())) { + if (!decryptor.Init(source_path_, source_path_) && + !decryptor.Init(app_path_, source_path_)) { return; } @@ -365,8 +402,9 @@ void Firefox2Importer::GetSearchEnginesXMLFiles( bool Firefox2Importer::ParseCharsetFromLine(const std::string& line, std::string* charset) { const char kCharset[] = "charset="; - if (StartsWithASCII(line, "<META", true) && - line.find("CONTENT=\"") != std::string::npos) { + if (StartsWithASCII(line, "<META", false) && + (line.find("CONTENT=\"") != std::string::npos || + line.find("content=\"") != std::string::npos)) { size_t begin = line.find(kCharset); if (begin == std::string::npos) return false; @@ -382,10 +420,12 @@ bool Firefox2Importer::ParseCharsetFromLine(const std::string& line, bool Firefox2Importer::ParseFolderNameFromLine(const std::string& line, const std::string& charset, std::wstring* folder_name, - bool* is_toolbar_folder) { + bool* is_toolbar_folder, + Time* add_date) { const char kFolderOpen[] = "<DT><H3"; const char kFolderClose[] = "</H3>"; const char kToolbarFolderAttribute[] = "PERSONAL_TOOLBAR_FOLDER"; + const char kAddDateAttribute[] = "ADD_DATE"; if (!StartsWithASCII(line, kFolderOpen, true)) return false; @@ -403,6 +443,16 @@ bool Firefox2Importer::ParseFolderNameFromLine(const std::string& line, std::string attribute_list = line.substr(arraysize(kFolderOpen), tag_end - arraysize(kFolderOpen) - 1); std::string value; + + // Add date + if (GetAttribute(attribute_list, kAddDateAttribute, &value)) { + int64 time; + base::StringToInt64(value, &time); + // Upper bound it at 32 bits. + if (0 < time && time < (1LL << 32)) + *add_date = Time::FromTimeT(time); + } + if (GetAttribute(attribute_list, kToolbarFolderAttribute, &value) && LowerCaseEqualsASCII(value, "true")) *is_toolbar_folder = true; @@ -503,6 +553,58 @@ bool Firefox2Importer::ParseBookmarkFromLine(const std::string& line, } // static +bool Firefox2Importer::ParseMinimumBookmarkFromLine(const std::string& line, + const std::string& charset, + std::wstring* title, + GURL* url) { + const char kItemOpen[] = "<DT><A"; + const char kItemClose[] = "</"; + const char kHrefAttributeUpper[] = "HREF"; + const char kHrefAttributeLower[] = "href"; + + title->clear(); + *url = GURL(); + + // Case-insensitive check of open tag. + if (!StartsWithASCII(line, kItemOpen, false)) + return false; + + // Find any close tag. + size_t end = line.find(kItemClose); + size_t tag_end = line.rfind('>', end) + 1; + if (end == std::string::npos || tag_end < arraysize(kItemOpen)) + return false; // No end tag or start tag is broken. + + std::string attribute_list = line.substr(arraysize(kItemOpen), + tag_end - arraysize(kItemOpen) - 1); + + // Title + base::CodepageToWide(line.substr(tag_end, end - tag_end), charset.c_str(), + base::OnStringConversionError::SKIP, title); + HTMLUnescape(title); + + // URL + std::string value; + if (GetAttribute(attribute_list, kHrefAttributeUpper, &value) || + GetAttribute(attribute_list, kHrefAttributeLower, &value)) { + if (charset.length() != 0) { + std::wstring w_url; + base::CodepageToWide(value, charset.c_str(), + base::OnStringConversionError::SKIP, &w_url); + HTMLUnescape(&w_url); + + string16 url16 = WideToUTF16Hack(w_url); + + *url = GURL(url16); + } else { + *url = GURL(value); + } + } + + return true; +} + +// static bool Firefox2Importer::GetAttribute(const std::string& attribute_list, const std::string& attribute, std::string* value) { diff --git a/chrome/browser/importer/firefox2_importer.h b/chrome/browser/importer/firefox2_importer.h index 5264c55..7fef5e6 100644 --- a/chrome/browser/importer/firefox2_importer.h +++ b/chrome/browser/importer/firefox2_importer.h @@ -52,6 +52,7 @@ class Firefox2Importer : public Importer { private: FRIEND_TEST_ALL_PREFIXES(FirefoxImporterTest, Firefox2BookmarkParse); FRIEND_TEST_ALL_PREFIXES(FirefoxImporterTest, Firefox2CookesParse); + FRIEND_TEST_ALL_PREFIXES(FirefoxImporterTest, Firefox2BookmarkFileImport); virtual ~Firefox2Importer(); @@ -84,7 +85,8 @@ class Firefox2Importer : public Importer { static bool ParseFolderNameFromLine(const std::string& line, const std::string& charset, std::wstring* folder_name, - bool* is_toolbar_folder); + 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). @@ -96,6 +98,18 @@ class Firefox2Importer : public Importer { std::wstring* shortcut, base::Time* add_date, std::wstring* post_data); + // Save bookmarks imported from browsers with Firefox2 compatible bookmark + // systems such as Epiphany. This bookmark format is the same as that of the + // basic Firefox 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> + static bool ParseMinimumBookmarkFromLine(const std::string& line, + const std::string& charset, + std::wstring* title, + GURL* url); // Fetches the given attribute value from the |tag|. Returns true if // successful, and |value| will contain the value. diff --git a/chrome/browser/importer/firefox3_importer.cc b/chrome/browser/importer/firefox3_importer.cc index 6442c87..38317be 100644 --- a/chrome/browser/importer/firefox3_importer.cc +++ b/chrome/browser/importer/firefox3_importer.cc @@ -35,15 +35,25 @@ using importer::ProfileInfo; using importer::SEARCH_ENGINES; using webkit_glue::PasswordForm; +// Original definition is in http://mxr.mozilla.org/firefox/source/toolkit/ +// components/places/public/nsINavBookmarksService.idl +enum BookmarkItemType { + TYPE_BOOKMARK = 1, + TYPE_FOLDER = 2, + TYPE_SEPARATOR = 3, + TYPE_DYNAMIC_CONTAINER = 4 +}; + struct Firefox3Importer::BookmarkItem { int parent; int id; GURL url; std::wstring title; - int type; + BookmarkItemType type; std::string keyword; base::Time date_added; int64 favicon; + bool empty_folder; }; Firefox3Importer::Firefox3Importer() { @@ -104,10 +114,8 @@ void Firefox3Importer::ImportHistory() { return; sqlite3* sqlite; - if (sqlite3_open(WideToUTF8(file.ToWStringHack()).c_str(), - &sqlite) != SQLITE_OK) { + if (sqlite_utils::OpenSqliteDb(file, &sqlite) != SQLITE_OK) return; - } sqlite_utils::scoped_sqlite_db_ptr db(sqlite); SQLStatement s; @@ -153,10 +161,8 @@ void Firefox3Importer::ImportBookmarks() { return; sqlite3* sqlite; - if (sqlite3_open(WideToUTF8(file.ToWStringHack()).c_str(), - &sqlite) != SQLITE_OK) { + if (sqlite_utils::OpenSqliteDb(file, &sqlite) != SQLITE_OK) return; - } sqlite_utils::scoped_sqlite_db_ptr db(sqlite); // Get the bookmark folders that we are interested in. @@ -180,7 +186,7 @@ void Firefox3Importer::ImportBookmarks() { GetTopBookmarkFolder(db.get(), unsorted_folder_id, &list); size_t count = list.size(); for (size_t i = 0; i < count; ++i) - GetWholeBookmarkFolder(db.get(), &list, i); + GetWholeBookmarkFolder(db.get(), &list, i, NULL); std::vector<ProfileWriter::BookmarkEntry> bookmarks; std::vector<TemplateURL*> template_urls; @@ -207,13 +213,21 @@ void Firefox3Importer::ImportBookmarks() { for (size_t i = 0; i < list.size(); ++i) { BookmarkItem* item = list[i]; - // The type of bookmark items is 1. - if (item->type != 1) + if (item->type == TYPE_FOLDER) { + // Folders are added implicitly on adding children, + // so now we pass only empty folders to add them explicitly. + if (!item->empty_folder) + continue; + } else if (item->type == TYPE_BOOKMARK) { + // Import only valid bookmarks + if (!CanImportURL(item->url)) + continue; + } else { continue; + } // Skip the default bookmarks and unwanted URLs. - if (!CanImportURL(item->url) || - default_urls.find(item->url) != default_urls.end() || + if (default_urls.find(item->url) != default_urls.end() || post_keyword_ids.find(item->id) != post_keyword_ids.end()) continue; @@ -261,6 +275,7 @@ void Firefox3Importer::ImportBookmarks() { entry.url = item->url; entry.path = path; entry.in_toolbar = is_in_toolbar; + entry.is_folder = item->type == TYPE_FOLDER; bookmarks.push_back(entry); @@ -300,10 +315,8 @@ void Firefox3Importer::ImportBookmarks() { void Firefox3Importer::ImportPasswords() { // Initializes NSS3. NSSDecryptor decryptor; - if (!decryptor.Init(source_path_.ToWStringHack(), - source_path_.ToWStringHack()) && - !decryptor.Init(app_path_.ToWStringHack(), - source_path_.ToWStringHack())) { + if (!decryptor.Init(source_path_, source_path_) && + !decryptor.Init(app_path_, source_path_)) { return; } @@ -356,10 +369,8 @@ void Firefox3Importer::GetSearchEnginesXMLFiles( return; sqlite3* sqlite; - if (sqlite3_open(WideToUTF8(file.ToWStringHack()).c_str(), - &sqlite) != SQLITE_OK) { + if (sqlite_utils::OpenSqliteDb(file, &sqlite) != SQLITE_OK) return; - } sqlite_utils::scoped_sqlite_db_ptr db(sqlite); SQLStatement s; @@ -488,14 +499,16 @@ void Firefox3Importer::GetTopBookmarkFolder(sqlite3* db, int folder_id, item->parent = -1; // The top level folder has no parent. item->id = folder_id; item->title = s.column_wstring(0); - item->type = 2; + item->type = TYPE_FOLDER; item->favicon = 0; + item->empty_folder = true; list->push_back(item); } } void Firefox3Importer::GetWholeBookmarkFolder(sqlite3* db, BookmarkList* list, - size_t position) { + size_t position, + bool* empty_folder) { if (position >= list->size()) { NOTREACHED(); return; @@ -520,12 +533,15 @@ void Firefox3Importer::GetWholeBookmarkFolder(sqlite3* db, BookmarkList* list, item->id = s.column_int(0); item->url = GURL(s.column_string(1)); item->title = s.column_wstring(2); - item->type = s.column_int(3); + item->type = static_cast<BookmarkItemType>(s.column_int(3)); item->keyword = s.column_string(4); item->date_added = Time::FromTimeT(s.column_int64(5)/1000000); item->favicon = s.column_int64(6); + item->empty_folder = true; temp_list.push_back(item); + if (empty_folder != NULL) + *empty_folder = false; } // Appends all items to the list. @@ -533,8 +549,8 @@ void Firefox3Importer::GetWholeBookmarkFolder(sqlite3* db, BookmarkList* list, i != temp_list.end(); ++i) { list->push_back(*i); // Recursive add bookmarks in sub-folders. - if ((*i)->type == 2) - GetWholeBookmarkFolder(db, list, list->size() - 1); + if ((*i)->type == TYPE_FOLDER) + GetWholeBookmarkFolder(db, list, list->size() - 1, &(*i)->empty_folder); } } diff --git a/chrome/browser/importer/firefox3_importer.h b/chrome/browser/importer/firefox3_importer.h index fe3deb7..6530edc 100644 --- a/chrome/browser/importer/firefox3_importer.h +++ b/chrome/browser/importer/firefox3_importer.h @@ -62,7 +62,7 @@ class Firefox3Importer : public Importer { // Loads all children of the given folder, and appends them to the |list|. void GetWholeBookmarkFolder(sqlite3* db, BookmarkList* list, - size_t position); + size_t position, bool* empty_folder); // Loads the favicons given in the map from the database, loads the data, // and converts it into FaviconUsage structures. diff --git a/chrome/browser/importer/firefox_importer_unittest.cc b/chrome/browser/importer/firefox_importer_unittest.cc index 73c70a4..15bdb14 100644 --- a/chrome/browser/importer/firefox_importer_unittest.cc +++ b/chrome/browser/importer/firefox_importer_unittest.cc @@ -33,10 +33,9 @@ TEST(FirefoxImporterTest, Firefox2NSS3Decryptor) { db_path = db_path.AppendASCII("firefox2_profile"); FFUnitTestDecryptorProxy decryptor_proxy; - ASSERT_TRUE(decryptor_proxy.Setup(nss_path.ToWStringHack())); + ASSERT_TRUE(decryptor_proxy.Setup(nss_path)); - EXPECT_TRUE(decryptor_proxy.DecryptorInit(nss_path.ToWStringHack(), - db_path.ToWStringHack())); + EXPECT_TRUE(decryptor_proxy.DecryptorInit(nss_path, db_path)); EXPECT_EQ(ASCIIToUTF16("hello"), decryptor_proxy.Decrypt("MDIEEPgAAAAAAAAAAAAAAAAAAAEwFAYIKoZIhvcNAwcECBJ" "M63MpT9rtBAjMCm7qo/EhlA==")); @@ -59,10 +58,9 @@ TEST(FirefoxImporterTest, Firefox3NSS3Decryptor) { db_path = db_path.AppendASCII("firefox3_profile"); FFUnitTestDecryptorProxy decryptor_proxy; - ASSERT_TRUE(decryptor_proxy.Setup(nss_path.ToWStringHack())); + ASSERT_TRUE(decryptor_proxy.Setup(nss_path)); - EXPECT_TRUE(decryptor_proxy.DecryptorInit(nss_path.ToWStringHack(), - db_path.ToWStringHack())); + EXPECT_TRUE(decryptor_proxy.DecryptorInit(nss_path, db_path)); EXPECT_EQ(ASCIIToUTF16("hello"), decryptor_proxy.Decrypt("MDIEEPgAAAAAAAAAAAAAAAAAAAEwFAYIKoZIhvcNAwcECKa" "jtRg4qFSHBAhv9luFkXgDJA==")); @@ -87,18 +85,20 @@ TEST(FirefoxImporterTest, Firefox2BookmarkParse) { // Escaped characters in name. std::wstring folder_name; bool is_toolbar_folder; + Time folder_add_date; result = Firefox2Importer::ParseFolderNameFromLine( "<DT><H3 ADD_DATE=\"1207558707\" >< >" " & " ' \\ /</H3>", - charset, &folder_name, &is_toolbar_folder); + charset, &folder_name, &is_toolbar_folder, &folder_add_date); EXPECT_TRUE(result); EXPECT_EQ(L"< > & \" ' \\ /", folder_name); EXPECT_FALSE(is_toolbar_folder); + EXPECT_TRUE(Time::FromTimeT(1207558707) == folder_add_date); // Empty name and toolbar folder attribute. result = Firefox2Importer::ParseFolderNameFromLine( "<DT><H3 PERSONAL_TOOLBAR_FOLDER=\"true\"></H3>", - charset, &folder_name, &is_toolbar_folder); + charset, &folder_name, &is_toolbar_folder, &folder_add_date); EXPECT_TRUE(result); EXPECT_EQ(L"", folder_name); EXPECT_TRUE(is_toolbar_folder); @@ -176,4 +176,125 @@ TEST(FirefoxImporterTest, Firefox2BookmarkParse) { EXPECT_EQ(L"", shortcut); EXPECT_EQ(L"", post_data); EXPECT_TRUE(Time() == add_date); + + // Epiphany format. + result = Firefox2Importer::ParseMinimumBookmarkFromLine( + "<dt><a href=\"http://www.google.com/\">Google</a></dt>", + charset, &title, &url); + EXPECT_TRUE(result); + EXPECT_EQ(L"Google", title); + EXPECT_EQ("http://www.google.com/", url.spec()); +} + +TEST(FirefoxImporterTest, Firefox2BookmarkFileImport) { + FilePath path; + ASSERT_TRUE(PathService::Get(chrome::DIR_TEST_DATA, &path)); + path = path.AppendASCII("firefox2_importer"); + + // Import all bookmarks from a file which include an empty folder entry. + FilePath empty_folder_path = path.AppendASCII("empty_folder.html"); + std::set<GURL> default_urls; + std::wstring first_folder_name; + Firefox2Importer* importer = new Firefox2Importer(); + importer->AddRef(); + std::vector<ProfileWriter::BookmarkEntry> bookmarks; + importer->ImportBookmarksFile(empty_folder_path, default_urls, false, + first_folder_name, importer, &bookmarks, + NULL, NULL); + EXPECT_EQ(3, static_cast<int>(bookmarks.size())); + std::vector<ProfileWriter::BookmarkEntry>::iterator it; + ProfileWriter::BookmarkEntry entry; + std::vector<std::wstring>::iterator path_it; + if (bookmarks.size() == 3) { + it = bookmarks.begin(); + entry = *it++; + EXPECT_EQ(L"Empty", entry.title); + EXPECT_TRUE(entry.is_folder); + EXPECT_EQ(Time::FromTimeT(1295938143), entry.creation_time); + EXPECT_EQ(2, static_cast<int>(entry.path.size())); + if (entry.path.size() == 2) { + path_it = entry.path.begin(); + EXPECT_EQ(L"", *path_it++); + EXPECT_EQ(L"Empty's Parent", *path_it); + } + + entry = *it++; + EXPECT_EQ(L"[Tamura Yukari.com]", entry.title); + EXPECT_FALSE(entry.is_folder); + EXPECT_EQ(Time::FromTimeT(1234567890), entry.creation_time); + EXPECT_EQ(2, static_cast<int>(entry.path.size())); + if (entry.path.size() == 2) { + path_it = entry.path.begin(); + EXPECT_EQ(L"", *path_it++); + EXPECT_EQ(L"Not Empty", *path_it); + } + EXPECT_EQ("http://www.tamurayukari.com/", entry.url.spec()); + + entry = *it++; + EXPECT_EQ(L"Google", entry.title); + EXPECT_FALSE(entry.is_folder); + EXPECT_EQ(Time::FromTimeT(0000000000), entry.creation_time); + EXPECT_EQ(2, static_cast<int>(entry.path.size())); + if (entry.path.size() == 2) { + path_it = entry.path.begin(); + EXPECT_EQ(L"", *path_it++); + EXPECT_EQ(L"Not Empty But Default", *path_it); + } + EXPECT_EQ("http://www.google.com/", entry.url.spec()); + } + + // Import non-default bookmarks from a file. + bookmarks.clear(); + default_urls.insert(GURL("http://www.google.com/")); + importer->ImportBookmarksFile(empty_folder_path, default_urls, false, + first_folder_name, importer, &bookmarks, + NULL, NULL); + EXPECT_EQ(2, static_cast<int>(bookmarks.size())); + if (bookmarks.size() == 2) { + it = bookmarks.begin(); + entry = *it++; + EXPECT_EQ(L"Empty", entry.title); + EXPECT_TRUE(entry.is_folder); + EXPECT_EQ(Time::FromTimeT(1295938143), entry.creation_time); + EXPECT_EQ(2, static_cast<int>(entry.path.size())); + if (entry.path.size() == 2) { + path_it = entry.path.begin(); + EXPECT_EQ(L"", *path_it++); + EXPECT_EQ(L"Empty's Parent", *path_it); + } + + entry = *it++; + EXPECT_EQ(L"[Tamura Yukari.com]", entry.title); + EXPECT_FALSE(entry.is_folder); + EXPECT_EQ(Time::FromTimeT(1234567890), entry.creation_time); + EXPECT_EQ(2, static_cast<int>(entry.path.size())); + if (entry.path.size() == 2) { + path_it = entry.path.begin(); + EXPECT_EQ(L"", *path_it++); + EXPECT_EQ(L"Not Empty", *path_it); + } + EXPECT_EQ("http://www.tamurayukari.com/", entry.url.spec()); + } + + // Import Epiphany bookmarks from a file + FilePath epiphany_path = path.AppendASCII("epiphany.html"); + bookmarks.clear(); + default_urls.clear(); + importer->ImportBookmarksFile(epiphany_path, default_urls, false, + first_folder_name, importer, &bookmarks, + NULL, NULL); + EXPECT_EQ(2, static_cast<int>(bookmarks.size())); + if (bookmarks.size() == 2) { + it = bookmarks.begin(); + entry = *it++; + EXPECT_EQ(L"[Tamura Yukari.com]", entry.title); + EXPECT_EQ("http://www.tamurayukari.com/", entry.url.spec()); + EXPECT_EQ(0, static_cast<int>(entry.path.size())); + entry = *it++; + EXPECT_EQ(L"Google", entry.title); + EXPECT_EQ("http://www.google.com/", entry.url.spec()); + EXPECT_EQ(0, static_cast<int>(entry.path.size())); + } + + importer->Release(); } diff --git a/chrome/browser/importer/firefox_importer_unittest_messages_internal.h b/chrome/browser/importer/firefox_importer_unittest_messages_internal.h index fd70f7f..b0e25c2 100644 --- a/chrome/browser/importer/firefox_importer_unittest_messages_internal.h +++ b/chrome/browser/importer/firefox_importer_unittest_messages_internal.h @@ -11,8 +11,8 @@ // Server->Child: Initialize the decrytor with the following paramters. IPC_MESSAGE_CONTROL2(Msg_Decryptor_Init, - std::wstring /* dll_path */, - std::wstring /* db_path */) + FilePath /* dll_path */, + FilePath /* db_path */) // Child->Server: Return paramter from init call. IPC_MESSAGE_CONTROL1(Msg_Decryptor_InitReturnCode, bool /* ret */) diff --git a/chrome/browser/importer/firefox_importer_unittest_utils.h b/chrome/browser/importer/firefox_importer_unittest_utils.h index 9a1df8d..9001f9a 100644 --- a/chrome/browser/importer/firefox_importer_unittest_utils.h +++ b/chrome/browser/importer/firefox_importer_unittest_utils.h @@ -35,10 +35,10 @@ class FFUnitTestDecryptorProxy { // Initialize a decryptor, returns true if the object was // constructed successfully. - bool Setup(const std::wstring& nss_path); + bool Setup(const FilePath& nss_path); // This match the parallel functions in NSSDecryptor. - bool DecryptorInit(const std::wstring& dll_path, const std::wstring& db_path); + bool DecryptorInit(const FilePath& dll_path, const FilePath& db_path); string16 Decrypt(const std::string& crypt); private: @@ -68,12 +68,12 @@ FFUnitTestDecryptorProxy::FFUnitTestDecryptorProxy() { FFUnitTestDecryptorProxy::~FFUnitTestDecryptorProxy() { } -bool FFUnitTestDecryptorProxy::Setup(const std::wstring& /* nss_path */) { +bool FFUnitTestDecryptorProxy::Setup(const FilePath& nss_path) { return true; } -bool FFUnitTestDecryptorProxy::DecryptorInit(const std::wstring& dll_path, - const std::wstring& db_path) { +bool FFUnitTestDecryptorProxy::DecryptorInit(const FilePath& dll_path, + const FilePath& db_path) { return decryptor_.Init(dll_path, db_path); } diff --git a/chrome/browser/importer/firefox_importer_unittest_utils_mac.cc b/chrome/browser/importer/firefox_importer_unittest_utils_mac.cc index f27a53c..dbaf19a 100644 --- a/chrome/browser/importer/firefox_importer_unittest_utils_mac.cc +++ b/chrome/browser/importer/firefox_importer_unittest_utils_mac.cc @@ -29,19 +29,18 @@ const char kTestChannelID[] = "T1"; // |channel| - IPC Channel to use for communication. // |handle| - On return, the process handle to use to communicate with the // child. -bool LaunchNSSDecrypterChildProcess(const std::wstring& nss_path, +bool LaunchNSSDecrypterChildProcess(const FilePath& nss_path, const IPC::Channel& channel, base::ProcessHandle* handle) { CommandLine cl(*CommandLine::ForCurrentProcess()); cl.AppendSwitchASCII(switches::kTestChildProcess, "NSSDecrypterChildProcess"); - FilePath ff_dylib_dir = FilePath::FromWStringHack(nss_path); // Set env variable needed for FF encryption libs to load. // See "chrome/browser/importer/nss_decryptor_mac.mm" for an explanation of // why we need this. base::environment_vector env; std::pair<std::string, std::string> dyld_override; dyld_override.first = "DYLD_FALLBACK_LIBRARY_PATH"; - dyld_override.second = ff_dylib_dir.value(); + dyld_override.second = nss_path.value(); env.push_back(dyld_override); base::file_handle_mapping_vector fds_to_map; @@ -123,7 +122,7 @@ FFUnitTestDecryptorProxy::FFUnitTestDecryptorProxy() : child_process_(0) { } -bool FFUnitTestDecryptorProxy::Setup(const std::wstring& nss_path) { +bool FFUnitTestDecryptorProxy::Setup(const FilePath& nss_path) { // Create a new message loop and spawn the child process. message_loop_.reset(new MessageLoopForIO()); @@ -185,8 +184,8 @@ bool FFUnitTestDecryptorProxy::WaitForClientResponse() { return ret; } -bool FFUnitTestDecryptorProxy::DecryptorInit(const std::wstring& dll_path, - const std::wstring& db_path) { +bool FFUnitTestDecryptorProxy::DecryptorInit(const FilePath& dll_path, + const FilePath& db_path) { channel_->Send(new Msg_Decryptor_Init(dll_path, db_path)); bool ok = WaitForClientResponse(); if (ok && listener_->got_result) { @@ -219,7 +218,7 @@ class FFDecryptorClientChannelListener : public IPC::Channel::Listener { sender_ = sender; } - void OnDecryptor_Init(std::wstring dll_path, std::wstring db_path) { + void OnDecryptor_Init(FilePath dll_path, FilePath db_path) { bool ret = decryptor_.Init(dll_path, db_path); sender_->Send(new Msg_Decryptor_InitReturnCode(ret)); } diff --git a/chrome/browser/importer/firefox_importer_utils.cc b/chrome/browser/importer/firefox_importer_utils.cc index be606ff..3ff88f2 100644 --- a/chrome/browser/importer/firefox_importer_utils.cc +++ b/chrome/browser/importer/firefox_importer_utils.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -312,7 +312,7 @@ int GetFirefoxDefaultSearchEngineIndex( int default_se_index = -1; for (std::vector<TemplateURL*>::const_iterator iter = search_engines.begin(); iter != search_engines.end(); ++iter) { - if (default_se_name == WideToUTF8((*iter)->short_name())) { + if (default_se_name == UTF16ToUTF8((*iter)->short_name())) { default_se_index = static_cast<int>(iter - search_engines.begin()); break; } diff --git a/chrome/browser/importer/firefox_importer_utils_win.cc b/chrome/browser/importer/firefox_importer_utils_win.cc index 7fc2a41..16696b9 100644 --- a/chrome/browser/importer/firefox_importer_utils_win.cc +++ b/chrome/browser/importer/firefox_importer_utils_win.cc @@ -31,9 +31,9 @@ int GetCurrentFirefoxMajorVersionFromRegistry() { base::win::RegKey reg_key(kFireFoxRegistryPaths[i], L"Software\\Mozilla\\Mozilla Firefox", KEY_READ); - bool result = reg_key.ReadValue(L"CurrentVersion", ver_buffer, + LONG result = reg_key.ReadValue(L"CurrentVersion", ver_buffer, &ver_buffer_length, NULL); - if (!result) + if (result != ERROR_SUCCESS) continue; highest_version = std::max(highest_version, _wtoi(ver_buffer)); } @@ -47,9 +47,9 @@ std::wstring GetFirefoxInstallPathFromRegistry() { DWORD buffer_length = sizeof(buffer); base::win::RegKey reg_key(HKEY_LOCAL_MACHINE, registry_path.c_str(), KEY_READ); - bool result = reg_key.ReadValue(L"CurrentVersion", buffer, + LONG result = reg_key.ReadValue(L"CurrentVersion", buffer, &buffer_length, NULL); - if (!result) + if (result != ERROR_SUCCESS) return std::wstring(); registry_path += L"\\" + std::wstring(buffer) + L"\\Main"; buffer_length = sizeof(buffer); @@ -57,7 +57,7 @@ std::wstring GetFirefoxInstallPathFromRegistry() { registry_path.c_str(), KEY_READ); result = reg_key_directory.ReadValue(L"Install Directory", buffer, &buffer_length, NULL); - if (!result) + if (result != ERROR_SUCCESS) return std::wstring(); return buffer; } diff --git a/chrome/browser/importer/ie_importer.cc b/chrome/browser/importer/ie_importer.cc index b26c306..d10453c 100644 --- a/chrome/browser/importer/ie_importer.cc +++ b/chrome/browser/importer/ie_importer.cc @@ -15,7 +15,6 @@ #include <string> #include <vector> -#include "app/l10n_util.h" #include "app/win/scoped_co_mem.h" #include "app/win/scoped_com_initializer.h" #include "base/file_path.h" @@ -40,6 +39,7 @@ #include "chrome/common/url_constants.h" #include "googleurl/src/gurl.h" #include "grit/generated_resources.h" +#include "ui/base/l10n/l10n_util.h" #include "webkit/glue/password_form.h" using base::Time; @@ -75,7 +75,7 @@ void IEImporter::StartImport(const ProfileInfo& profile_info, uint16 items, ImporterBridge* bridge) { bridge_ = bridge; - source_path_ = profile_info.source_path.ToWStringHack(); + source_path_ = profile_info.source_path.value(); bridge_->NotifyStarted(); @@ -263,19 +263,18 @@ void IEImporter::ImportPasswordsIE7() { base::win::RegKey key(HKEY_CURRENT_USER, kStorage2Path, KEY_READ); base::win::RegistryValueIterator reg_iterator(HKEY_CURRENT_USER, kStorage2Path); + IE7PasswordInfo password_info; while (reg_iterator.Valid() && !cancelled()) { // Get the size of the encrypted data. DWORD value_len = 0; - if (key.ReadValue(reg_iterator.Name(), NULL, &value_len, NULL) && - value_len) { + key.ReadValue(reg_iterator.Name(), NULL, &value_len, NULL); + if (value_len) { // Query the encrypted data. - std::vector<unsigned char> value; - value.resize(value_len); - if (key.ReadValue(reg_iterator.Name(), &value.front(), &value_len, - NULL)) { - IE7PasswordInfo password_info; + password_info.encrypted_data.resize(value_len); + if (key.ReadValue(reg_iterator.Name(), + &password_info.encrypted_data.front(), + &value_len, NULL) == ERROR_SUCCESS) { password_info.url_hash = reg_iterator.Name(); - password_info.encrypted_data = value; password_info.date_created = Time::Now(); bridge_->AddIE7PasswordInfo(password_info); @@ -366,7 +365,8 @@ void IEImporter::ImportSearchEngines() { base::win::RegKey sub_key(HKEY_CURRENT_USER, sub_key_name.c_str(), KEY_READ); std::wstring wide_url; - if (!sub_key.ReadValue(L"URL", &wide_url) || wide_url.empty()) { + if ((sub_key.ReadValue(L"URL", &wide_url) != ERROR_SUCCESS) || + wide_url.empty()) { VLOG(1) << "No URL for IE search engine at " << key_iterator.Name(); ++key_iterator; continue; @@ -375,9 +375,10 @@ void IEImporter::ImportSearchEngines() { // non displayable name in DisplayName, and the readable name under the // default value). std::wstring name; - if (!sub_key.ReadValue(NULL, &name) || name.empty()) { + if ((sub_key.ReadValue(NULL, &name) != ERROR_SUCCESS) || name.empty()) { // Try the displayable name. - if (!sub_key.ReadValue(L"DisplayName", &name) || name.empty()) { + if ((sub_key.ReadValue(L"DisplayName", &name) != ERROR_SUCCESS) || + name.empty()) { VLOG(1) << "No name for IE search engine at " << key_iterator.Name(); ++key_iterator; continue; @@ -433,7 +434,8 @@ void IEImporter::ImportHomepage() { base::win::RegKey key(HKEY_CURRENT_USER, kIESettingsMain, KEY_READ); std::wstring homepage_url; - if (!key.ReadValue(kIEHomepage, &homepage_url) || homepage_url.empty()) + if (key.ReadValue(kIEHomepage, &homepage_url) != ERROR_SUCCESS || + homepage_url.empty()) return; GURL homepage = GURL(homepage_url); @@ -443,8 +445,8 @@ void IEImporter::ImportHomepage() { // Check to see if this is the default website and skip import. base::win::RegKey keyDefault(HKEY_LOCAL_MACHINE, kIESettingsMain, KEY_READ); std::wstring default_homepage_url; - if (keyDefault.ReadValue(kIEDefaultHomepage, &default_homepage_url) && - !default_homepage_url.empty()) { + LONG result = keyDefault.ReadValue(kIEDefaultHomepage, &default_homepage_url); + if (result == ERROR_SUCCESS && !default_homepage_url.empty()) { if (homepage.spec() == GURL(default_homepage_url).spec()) return; } @@ -477,7 +479,8 @@ bool IEImporter::GetFavoritesInfo(IEImporter::FavoritesInfo *info) { DWORD buffer_length = sizeof(buffer); base::win::RegKey reg_key(HKEY_CURRENT_USER, L"Software\\Microsoft\\Internet Explorer\\Toolbar", KEY_READ); - if (!reg_key.ReadValue(L"LinksFolderName", buffer, &buffer_length, NULL)) + if (reg_key.ReadValue(L"LinksFolderName", buffer, + &buffer_length, NULL) != ERROR_SUCCESS) return false; info->links_folder = buffer; } else { @@ -587,8 +590,8 @@ int IEImporter::CurrentIEVersion() const { DWORD buffer_length = sizeof(buffer); base::win::RegKey reg_key(HKEY_LOCAL_MACHINE, L"Software\\Microsoft\\Internet Explorer", KEY_READ); - bool result = reg_key.ReadValue(L"Version", buffer, &buffer_length, NULL); - version = (result ? _wtoi(buffer) : 0); + LONG result = reg_key.ReadValue(L"Version", buffer, &buffer_length, NULL); + version = ((result == ERROR_SUCCESS)? _wtoi(buffer) : 0); } return version; } diff --git a/chrome/browser/importer/importer.cc b/chrome/browser/importer/importer.cc index d69aff4..03c72cf 100644 --- a/chrome/browser/importer/importer.cc +++ b/chrome/browser/importer/importer.cc @@ -1,10 +1,9 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #include "chrome/browser/importer/importer.h" -#include "app/l10n_util.h" #include "base/threading/thread.h" #include "base/utf_string_conversions.h" #include "base/values.h" @@ -19,24 +18,21 @@ #include "chrome/browser/search_engines/template_url.h" #include "chrome/browser/search_engines/template_url_model.h" #include "chrome/browser/tabs/tab_strip_model.h" +#include "chrome/browser/ui/browser_dialogs.h" #include "chrome/browser/ui/browser_navigator.h" #include "chrome/browser/webdata/web_data_service.h" #include "chrome/common/notification_source.h" -#include "gfx/codec/png_codec.h" -#include "gfx/favicon_size.h" #include "grit/generated_resources.h" #include "skia/ext/image_operations.h" +#include "ui/base/l10n/l10n_util.h" +#include "ui/gfx/codec/png_codec.h" +#include "ui/gfx/favicon_size.h" #include "webkit/glue/image_decoder.h" // TODO(port): Port these files. #if defined(OS_WIN) -#include "app/win/win_util.h" -#include "chrome/browser/views/importer_lock_view.h" +#include "ui/base/message_box_win.h" #include "views/window/window.h" -#elif defined(OS_MACOSX) -#include "chrome/browser/ui/cocoa/importer_lock_dialog.h" -#elif defined(TOOLKIT_USES_GTK) -#include "chrome/browser/gtk/import_lock_dialog_gtk.h" #endif using webkit_glue::PasswordForm; @@ -88,28 +84,13 @@ ImporterHost::ImporterHost() installed_bookmark_observer_(false), is_source_readable_(true), headless_(false), - parent_window_(NULL), - importer_list_(new ImporterList) { - importer_list_->DetectSourceProfilesHack(); -} - -ImporterHost::ImporterHost(ImporterList::Observer* observer) - : profile_(NULL), - observer_(NULL), - task_(NULL), - importer_(NULL), - waiting_for_bookmarkbar_model_(false), - installed_bookmark_observer_(false), - is_source_readable_(true), - headless_(false), - parent_window_(NULL), - importer_list_(new ImporterList) { - importer_list_->DetectSourceProfiles(observer); + parent_window_(NULL) { } ImporterHost::~ImporterHost() { if (NULL != importer_) importer_->Release(); + if (installed_bookmark_observer_) { DCHECK(profile_); // Only way for waiting_for_bookmarkbar_model_ to be true // is if we have a profile. @@ -143,14 +124,7 @@ void ImporterHost::ShowWarningDialog() { if (headless_) { OnLockViewEnd(false); } else { -#if defined(OS_WIN) - views::Window::CreateChromeWindow(NULL, gfx::Rect(), - new ImporterLockView(this))->Show(); -#elif defined(TOOLKIT_USES_GTK) - ImportLockDialogGtk::Show(parent_window_, this); -#else - ImportLockDialogCocoa::ShowWarning(this); -#endif + browser::ShowImportLockDialog(parent_window_, this); } } @@ -212,7 +186,7 @@ void ImporterHost::StartImportSettings( // credentials. if (profile_info.browser_type == importer::GOOGLE_TOOLBAR5) { if (!toolbar_importer_utils::IsGoogleGAIACookieInstalled()) { - app::win::MessageBox( + ui::MessageBox( NULL, UTF16ToWide(l10n_util::GetStringUTF16( IDS_IMPORTER_GOOGLE_LOGIN_TEXT)).c_str(), @@ -326,15 +300,6 @@ ExternalProcessImporterHost::ExternalProcessImporterHost() import_process_launched_(false) { } -ExternalProcessImporterHost::ExternalProcessImporterHost( - ImporterList::Observer* observer) - : ImporterHost(observer), - items_(0), - import_to_bookmark_bar_(false), - cancelled_(false), - import_process_launched_(false) { -} - void ExternalProcessImporterHost::Loaded(BookmarkModel* model) { DCHECK(model->IsLoaded()); model->RemoveObserver(this); @@ -410,7 +375,7 @@ ExternalProcessImporterClient::ExternalProcessImporterClient( items_(items), import_to_bookmark_bar_(import_to_bookmark_bar), bridge_(bridge), - cancelled_(FALSE) { + cancelled_(false) { bridge_->AddRef(); process_importer_host_->ImportStarted(); } diff --git a/chrome/browser/importer/importer.h b/chrome/browser/importer/importer.h index e994036..179d68b 100644 --- a/chrome/browser/importer/importer.h +++ b/chrome/browser/importer/importer.h @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -21,7 +21,7 @@ #include "chrome/browser/profile_import_process_host.h" #include "chrome/common/notification_observer.h" #include "chrome/common/notification_registrar.h" -#include "gfx/native_widget_types.h" +#include "ui/gfx/native_widget_types.h" using importer::ImportItem; using importer::ProfileInfo; @@ -76,15 +76,8 @@ class ImporterHost : public base::RefCountedThreadSafe<ImporterHost>, virtual ~Observer() {} }; - // DEPRECATED: Calls the synchronous version of - // ImporterList::DetectSourceProfiles. - // TODO(jhawkins): Remove this constructor once all callers are fixed. - // See http://crbug.com/65633 and http://crbug.com/65638. ImporterHost(); - // |observer| must not be NULL. - explicit ImporterHost(ImporterList::Observer* observer); - // BookmarkModelObserver implementation. virtual void Loaded(BookmarkModel* model); virtual void BookmarkNodeMoved(BookmarkModel* model, @@ -162,33 +155,6 @@ class ImporterHost : public base::RefCountedThreadSafe<ImporterHost>, virtual void ImportItemEnded(importer::ImportItem item); virtual void ImportEnded(); - int GetAvailableProfileCount() const { - return importer_list_->GetAvailableProfileCount(); - } - - // Returns the name of the profile at the 'index' slot. The profiles are - // ordered such that the profile at index 0 is the likely default browser. - std::wstring GetSourceProfileNameAt(int index) const { - return importer_list_->GetSourceProfileNameAt(index); - } - - // Returns the ProfileInfo at the specified index. The ProfileInfo should be - // passed to StartImportSettings(). - const importer::ProfileInfo& GetSourceProfileInfoAt(int index) const { - return importer_list_->GetSourceProfileInfoAt(index); - } - - // Returns the ProfileInfo with the given browser type. - const importer::ProfileInfo& GetSourceProfileInfoForBrowserType( - int browser_type) const { - return importer_list_->GetSourceProfileInfoForBrowserType(browser_type); - } - - // Returns true if the source profiles have been loaded. - bool source_profiles_loaded() const { - return importer_list_->source_profiles_loaded(); - } - protected: friend class base::RefCountedThreadSafe<ImporterHost>; @@ -255,24 +221,15 @@ class ImporterHost : public base::RefCountedThreadSafe<ImporterHost>, // complete. virtual void InvokeTaskIfDone(); - // Used to create an importer of the appropriate type. - scoped_refptr<ImporterList> importer_list_; - DISALLOW_COPY_AND_ASSIGN(ImporterHost); }; -// This class manages the import process. It creates the in-process half of -// the importer bridge and the external process importer client. +// This class manages the import process. It creates the in-process half of the +// importer bridge and the external process importer client. class ExternalProcessImporterHost : public ImporterHost { public: - // DEPRECATED: Calls the deprecated ImporterHost constructor. - // TODO(jhawkins): Remove this constructor once all callers are fixed. - // See http://crbug.com/65633 and http://crbug.com/65638. ExternalProcessImporterHost(); - // |observer| must not be NULL. - explicit ExternalProcessImporterHost(ImporterList::Observer* observer); - // Called when the BookmarkModel has finished loading. Calls InvokeTaskIfDone // to start importing. virtual void Loaded(BookmarkModel* model); diff --git a/chrome/browser/importer/importer_bridge.cc b/chrome/browser/importer/importer_bridge.cc index 588e365..2fb48a7 100644 --- a/chrome/browser/importer/importer_bridge.cc +++ b/chrome/browser/importer/importer_bridge.cc @@ -4,7 +4,6 @@ #include "chrome/browser/importer/importer_bridge.h" -#include "app/l10n_util.h" #include "base/scoped_ptr.h" #include "base/string_number_conversions.h" #include "base/string16.h" @@ -19,6 +18,7 @@ #include "chrome/common/child_thread.h" #include "chrome/browser/importer/importer_messages.h" #include "chrome/profile_import/profile_import_thread.h" +#include "ui/base/l10n/l10n_util.h" #include "webkit/glue/password_form.h" ImporterBridge::ImporterBridge() { } @@ -128,8 +128,7 @@ ExternalProcessImporterBridge::ExternalProcessImporterBridge( : profile_import_thread_(profile_import_thread) { // Bridge needs to make its own copy because OS 10.6 autoreleases the // localized_strings value that is passed in (see http://crbug.com/46003 ). - localized_strings_.reset( - static_cast<DictionaryValue*>(localized_strings.DeepCopy())); + localized_strings_.reset(localized_strings.DeepCopy()); } void ExternalProcessImporterBridge::AddBookmarkEntries( diff --git a/chrome/browser/importer/importer_list.cc b/chrome/browser/importer/importer_list.cc index 9574f95..a47e9b4 100644 --- a/chrome/browser/importer/importer_list.cc +++ b/chrome/browser/importer/importer_list.cc @@ -4,7 +4,6 @@ #include "chrome/browser/importer/importer_list.h" -#include "app/l10n_util.h" #include "base/file_util.h" #include "base/stl_util-inl.h" #include "base/values.h" @@ -17,6 +16,7 @@ #include "chrome/browser/importer/toolbar_importer.h" #include "chrome/browser/shell_integration.h" #include "grit/generated_resources.h" +#include "ui/base/l10n/l10n_util.h" #if defined(OS_WIN) #include "chrome/browser/importer/ie_importer.h" @@ -146,6 +146,7 @@ Importer* ImporterList::CreateImporterByType(importer::ProfileType type) { ImporterList::ImporterList() : source_thread_id_(BrowserThread::UI), observer_(NULL), + is_observed_(false), source_profiles_loaded_(false) { } @@ -155,6 +156,7 @@ ImporterList::~ImporterList() { void ImporterList::DetectSourceProfiles(Observer* observer) { DCHECK(observer); observer_ = observer; + is_observed_ = true; BrowserThread::GetCurrentThreadIdentifier(&source_thread_id_); @@ -164,6 +166,10 @@ void ImporterList::DetectSourceProfiles(Observer* observer) { NewRunnableMethod(this, &ImporterList::DetectSourceProfilesWorker)); } +void ImporterList::SetObserver(Observer* observer) { + observer_ = observer; +} + void ImporterList::DetectSourceProfilesHack() { DetectSourceProfilesWorker(); } @@ -205,8 +211,8 @@ bool ImporterList::source_profiles_loaded() const { void ImporterList::DetectSourceProfilesWorker() { // TODO(jhawkins): Remove this condition once DetectSourceProfileHack is - // removed. |observer_| is NULL when said method is called. - if (observer_) + // removed. + if (is_observed_) DCHECK(BrowserThread::CurrentlyOn(BrowserThread::FILE)); std::vector<importer::ProfileInfo*> profiles; @@ -236,8 +242,8 @@ void ImporterList::DetectSourceProfilesWorker() { #endif // TODO(jhawkins): Remove this condition once DetectSourceProfileHack is - // removed. |observer_| is NULL when said method is called. - if (observer_) { + // removed. + if (is_observed_) { BrowserThread::PostTask( source_thread_id_, FROM_HERE, @@ -250,7 +256,9 @@ void ImporterList::DetectSourceProfilesWorker() { void ImporterList::SourceProfilesLoaded( const std::vector<importer::ProfileInfo*>& profiles) { - DCHECK_NE(static_cast<Observer*>(NULL), observer_); + // |observer_| may be NULL if it removed itself before being notified. + if (!observer_) + return; BrowserThread::ID current_thread_id; BrowserThread::GetCurrentThreadIdentifier(¤t_thread_id); @@ -258,7 +266,11 @@ void ImporterList::SourceProfilesLoaded( source_profiles_->assign(profiles.begin(), profiles.end()); source_profiles_loaded_ = true; + source_thread_id_ = BrowserThread::UI; + observer_->SourceProfilesLoaded(); observer_ = NULL; - source_thread_id_ = BrowserThread::UI; + + // TODO(jhawkins): Remove once DetectSourceProfileHack is removed. + is_observed_ = false; } diff --git a/chrome/browser/importer/importer_list.h b/chrome/browser/importer/importer_list.h index 513a55f..e82764b 100644 --- a/chrome/browser/importer/importer_list.h +++ b/chrome/browser/importer/importer_list.h @@ -41,6 +41,11 @@ class ImporterList : public base::RefCountedThreadSafe<ImporterList> { // non-NULL. void DetectSourceProfiles(Observer* observer); + // Sets the observer of this object. When the current observer is destroyed, + // this method should be called with a NULL |observer| so it is not notified + // after destruction. + void SetObserver(Observer* observer); + // DEPRECATED: This method is synchronous and performs file operations which // may end up blocking the current thread, which is usually the UI thread. void DetectSourceProfilesHack(); @@ -90,6 +95,12 @@ class ImporterList : public base::RefCountedThreadSafe<ImporterList> { // SourceProfilesLoaded() has returned. Observer* observer_; + // True if |observer_| is set during the lifetime of source profile detection. + // This hack is necessary in order to not use |observer_| != NULL as a method + // of determining whether this object is being observed or not. + // TODO(jhawkins): Remove once DetectSourceProfilesHack() is removed. + bool is_observed_; + // True if source profiles are loaded. bool source_profiles_loaded_; diff --git a/chrome/browser/importer/importer_messages.h b/chrome/browser/importer/importer_messages.h index e05aac8..ac63526 100644 --- a/chrome/browser/importer/importer_messages.h +++ b/chrome/browser/importer/importer_messages.h @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -222,7 +222,7 @@ struct ParamTraits<TemplateURL::ImageRef> { WriteParam(m, p.url); } static bool Read(const Message* m, void** iter, param_type* p) { - std::wstring type; + std::string type; int width; int height; GURL url; @@ -275,17 +275,17 @@ struct ParamTraits<TemplateURL> { WriteParam(m, p.prepopulate_id()); } static bool Read(const Message* m, void** iter, param_type* p) { - std::wstring short_name; - std::wstring description; + string16 short_name; + string16 description; bool includes_suggestions_url; TemplateURLRef suggestions_url; TemplateURLRef url; GURL originating_url; - std::wstring keyword; + string16 keyword; bool autogenerate_keyword; bool show_in_default_list; bool safe_for_autoreplace; - std::vector<std::wstring> languages; + std::vector<string16> languages; std::vector<std::string> input_encodings; base::Time date_created; int usage_count; @@ -314,7 +314,7 @@ struct ParamTraits<TemplateURL> { *p = TemplateURL(); for (size_t i = 0; i < image_refs_size; ++i) { - std::wstring type; + std::string type; int width; int height; GURL url; @@ -344,7 +344,7 @@ struct ParamTraits<TemplateURL> { p->set_show_in_default_list(show_in_default_list); p->set_safe_for_autoreplace(safe_for_autoreplace); - std::vector<std::wstring>::const_iterator lang_iter; + std::vector<string16>::const_iterator lang_iter; for (lang_iter = languages.begin(); lang_iter != languages.end(); ++lang_iter) { diff --git a/chrome/browser/importer/importer_unittest.cc b/chrome/browser/importer/importer_unittest.cc index 595a3d7..cfca4de 100644 --- a/chrome/browser/importer/importer_unittest.cc +++ b/chrome/browser/importer/importer_unittest.cc @@ -114,7 +114,7 @@ class ImporterTest : public testing::Test { profile_info.browser_type = FIREFOX3; profile_info.app_path = app_path_; profile_info.source_path = profile_path_; - scoped_refptr<ImporterHost> host(new ImporterHost()); + scoped_refptr<ImporterHost> host(new ImporterHost); host->SetObserver(observer); int items = HISTORY | PASSWORDS | FAVORITES; if (import_search_plugins) @@ -416,7 +416,7 @@ TEST_F(ImporterTest, IEImporter) { // Starts to import the above settings. MessageLoop* loop = MessageLoop::current(); - scoped_refptr<ImporterHost> host = new ImporterHost(); + scoped_refptr<ImporterHost> host(new ImporterHost); TestObserver* observer = new TestObserver(); host->SetObserver(observer); @@ -637,9 +637,10 @@ class FirefoxObserver : public ProfileWriter, // The order might not be deterministic, look in the expected list for // that template URL. bool found = false; - std::wstring keyword = template_urls[i]->keyword(); + string16 keyword = template_urls[i]->keyword(); for (size_t j = 0; j < arraysize(kFirefox2Keywords); ++j) { - if (template_urls[i]->keyword() == kFirefox2Keywords[j].keyword) { + if (template_urls[i]->keyword() == + WideToUTF16Hack(kFirefox2Keywords[j].keyword)) { EXPECT_EQ(kFirefox2Keywords[j].url, template_urls[i]->url()->url()); found = true; break; @@ -652,7 +653,7 @@ class FirefoxObserver : public ProfileWriter, if (default_keyword_index != -1) { EXPECT_LT(default_keyword_index, static_cast<int>(template_urls.size())); TemplateURL* default_turl = template_urls[default_keyword_index]; - default_keyword_ = default_turl->keyword(); + default_keyword_ = UTF16ToWideHack(default_turl->keyword()); default_keyword_url_ = default_turl->url()->url(); } @@ -695,7 +696,7 @@ TEST_F(ImporterTest, MAYBE(Firefox2Importer)) { ASSERT_TRUE(file_util::CopyDirectory(data_path, search_engine_path, false)); MessageLoop* loop = MessageLoop::current(); - scoped_refptr<ImporterHost> host(new ImporterHost()); + scoped_refptr<ImporterHost> host(new ImporterHost); FirefoxObserver* observer = new FirefoxObserver(); host->SetObserver(observer); ProfileInfo profile_info; @@ -844,9 +845,10 @@ class Firefox3Observer : public ProfileWriter, // The order might not be deterministic, look in the expected list for // that template URL. bool found = false; - std::wstring keyword = template_urls[i]->keyword(); + string16 keyword = template_urls[i]->keyword(); for (size_t j = 0; j < arraysize(kFirefox3Keywords); ++j) { - if (template_urls[i]->keyword() == kFirefox3Keywords[j].keyword) { + if (template_urls[i]->keyword() == + WideToUTF16Hack(kFirefox3Keywords[j].keyword)) { EXPECT_EQ(kFirefox3Keywords[j].url, template_urls[i]->url()->url()); found = true; break; @@ -859,7 +861,7 @@ class Firefox3Observer : public ProfileWriter, if (default_keyword_index != -1) { EXPECT_LT(default_keyword_index, static_cast<int>(template_urls.size())); TemplateURL* default_turl = template_urls[default_keyword_index]; - default_keyword_ = default_turl->keyword(); + default_keyword_ = UTF16ToWideHack(default_turl->keyword()); default_keyword_url_ = default_turl->url()->url(); } diff --git a/chrome/browser/importer/nss_decryptor_mac.h b/chrome/browser/importer/nss_decryptor_mac.h index 5e0eeff..e88fd11 100644 --- a/chrome/browser/importer/nss_decryptor_mac.h +++ b/chrome/browser/importer/nss_decryptor_mac.h @@ -120,8 +120,7 @@ class NSSDecryptor { ~NSSDecryptor(); // Initializes NSS if it hasn't already been initialized. - bool Init(const std::wstring& /* dll_path */, - const std::wstring& /* db_path */); + bool Init(const FilePath& dll_path, const FilePath& db_path); // Decrypts Firefox stored passwords. Before using this method, // make sure Init() returns true. @@ -152,9 +151,6 @@ class NSSDecryptor { PK11SDRDecryptFunc PK11SDR_Decrypt; SECITEMFreeItemFunc SECITEM_FreeItem; - // Libraries necessary for decrypting the passwords. - static const wchar_t kNSS3Library[]; - // True if NSS_Init() has been called bool is_nss_initialized_; diff --git a/chrome/browser/importer/nss_decryptor_mac.mm b/chrome/browser/importer/nss_decryptor_mac.mm index 988ab56..d9d3d7a 100644 --- a/chrome/browser/importer/nss_decryptor_mac.mm +++ b/chrome/browser/importer/nss_decryptor_mac.mm @@ -13,25 +13,20 @@ #include "chrome/browser/importer/nss_decryptor_mac.h" #include "chrome/browser/importer/firefox_importer_utils.h" -// static -const wchar_t NSSDecryptor::kNSS3Library[] = L"libnss3.dylib"; - // Important!! : On OS X the nss3 libraries are compiled with depedencies // on one another, referenced using dyld's @executable_path directive. // To make a long story short in order to get the libraries to load, dyld's // fallback path needs to be set to the directory containing the libraries. // To do so, the process this function runs in must have the // DYLD_FALLBACK_LIBRARY_PATH set on startup to said directory. -bool NSSDecryptor::Init(const std::wstring& dll_path, - const std::wstring& db_path) { +bool NSSDecryptor::Init(const FilePath& dll_path, const FilePath& db_path) { if (getenv("DYLD_FALLBACK_LIBRARY_PATH") == NULL) { LOG(ERROR) << "DYLD_FALLBACK_LIBRARY_PATH variable not set"; return false; } - FilePath dylib_file_path = FilePath::FromWStringHack(dll_path); - FilePath nss3_path = dylib_file_path.Append("libnss3.dylib"); + FilePath nss3_path = dll_path.Append("libnss3.dylib"); - void *nss_3_lib = dlopen(nss3_path.value().c_str(), RTLD_LAZY); + void* nss_3_lib = dlopen(nss3_path.value().c_str(), RTLD_LAZY); if (!nss_3_lib) { LOG(ERROR) << "Failed to load nss3 lib" << dlerror(); return false; @@ -56,7 +51,7 @@ bool NSSDecryptor::Init(const std::wstring& dll_path, return false; } - SECStatus result = NSS_Init(base::SysWideToNativeMB(db_path).c_str()); + SECStatus result = NSS_Init(db_path.value().c_str()); if (result != SECSuccess) { LOG(ERROR) << "NSS_Init Failed returned: " << result; diff --git a/chrome/browser/importer/nss_decryptor_null.h b/chrome/browser/importer/nss_decryptor_null.h index 155f1e0..af725c1 100644 --- a/chrome/browser/importer/nss_decryptor_null.h +++ b/chrome/browser/importer/nss_decryptor_null.h @@ -23,8 +23,7 @@ struct PasswordForm; class NSSDecryptor { public: NSSDecryptor() {} - bool Init(const std::wstring& /* dll_path */, - const std::wstring& db_path) { return false; } + bool Init(const FilePath& dll_path, const FilePath& db_path) { return false; } string16 Decrypt(const std::string& crypt) const { return string16(); } void ParseSignons(const std::string& content, std::vector<webkit_glue::PasswordForm>* forms) {} diff --git a/chrome/browser/importer/nss_decryptor_system_nss.cc b/chrome/browser/importer/nss_decryptor_system_nss.cc index 06be5da..58ce34e 100644 --- a/chrome/browser/importer/nss_decryptor_system_nss.cc +++ b/chrome/browser/importer/nss_decryptor_system_nss.cc @@ -8,6 +8,7 @@ #include <pk11sdr.h> #include "base/basictypes.h" +#include "base/file_path.h" #include "base/nss_util.h" #include "base/string_util.h" #include "base/sys_string_conversions.h" @@ -23,13 +24,12 @@ NSSDecryptor::~NSSDecryptor() { } } -bool NSSDecryptor::Init(const std::wstring& /* dll_path */, - const std::wstring& db_path) { +bool NSSDecryptor::Init(const FilePath& dll_path, const FilePath& db_path) { base::EnsureNSSInit(); is_nss_initialized_ = true; const std::string modspec = StringPrintf("configDir='%s' tokenDescription='Firefox NSS database' " - "flags=readOnly", base::SysWideToNativeMB(db_path).c_str()); + "flags=readOnly", db_path.value().c_str()); db_slot_ = SECMOD_OpenUserDB(modspec.c_str()); return db_slot_ != NULL; } diff --git a/chrome/browser/importer/nss_decryptor_system_nss.h b/chrome/browser/importer/nss_decryptor_system_nss.h index c08496d..b4087d9 100644 --- a/chrome/browser/importer/nss_decryptor_system_nss.h +++ b/chrome/browser/importer/nss_decryptor_system_nss.h @@ -26,8 +26,7 @@ class NSSDecryptor { ~NSSDecryptor(); // Initializes NSS if it hasn't already been initialized. - bool Init(const std::wstring& /* dll_path */, - const std::wstring& db_path); + bool Init(const FilePath& dll_path, const FilePath& db_path); // Decrypts Firefox stored passwords. Before using this method, // make sure Init() returns true. diff --git a/chrome/browser/importer/nss_decryptor_win.cc b/chrome/browser/importer/nss_decryptor_win.cc index a7b5592..bb1b2d4 100644 --- a/chrome/browser/importer/nss_decryptor_win.cc +++ b/chrome/browser/importer/nss_decryptor_win.cc @@ -37,8 +37,7 @@ const wchar_t NSSDecryptor::kSoftokn3Library[] = L"softokn3.dll"; const wchar_t NSSDecryptor::kPLDS4Library[] = L"plds4.dll"; const wchar_t NSSDecryptor::kNSPR4Library[] = L"nspr4.dll"; -bool NSSDecryptor::Init(const std::wstring& dll_path, - const std::wstring& db_path) { +bool NSSDecryptor::Init(const FilePath& dll_path, const FilePath& db_path) { // We call SetDllDirectory to work around a Purify bug (GetModuleHandle // fails inside Purify under certain conditions). SetDllDirectory only // exists on Windows XP SP1 or later, so we look up its address at run time. @@ -50,7 +49,7 @@ bool NSSDecryptor::Init(const std::wstring& dll_path, SetDllDirectoryCaller caller; if (set_dll_directory != NULL) { - if (!set_dll_directory(dll_path.c_str())) + if (!set_dll_directory(dll_path.value().c_str())) return false; caller.set_func(set_dll_directory); nss3_dll_ = LoadLibrary(kNSS3Library); @@ -60,7 +59,7 @@ bool NSSDecryptor::Init(const std::wstring& dll_path, // Fall back on LoadLibraryEx if SetDllDirectory isn't available. We // actually prefer this method because it doesn't change the DLL search // path, which is a process-wide property. - FilePath path = FilePath(dll_path).Append(kNSS3Library); + FilePath path = dll_path.Append(kNSS3Library); nss3_dll_ = LoadLibraryEx(path.value().c_str(), NULL, LOAD_WITH_ALTERED_SEARCH_PATH); if (nss3_dll_ == NULL) @@ -103,7 +102,7 @@ NSSDecryptor::~NSSDecryptor() { Free(); } -bool NSSDecryptor::InitNSS(const std::wstring& db_path, +bool NSSDecryptor::InitNSS(const FilePath& db_path, base::NativeLibrary plds4_dll, base::NativeLibrary nspr4_dll) { // NSPR DLLs are already loaded now. @@ -142,7 +141,7 @@ bool NSSDecryptor::InitNSS(const std::wstring& db_path, return false; } - SECStatus result = NSS_Init(base::SysWideToNativeMB(db_path).c_str()); + SECStatus result = NSS_Init(base::SysWideToNativeMB(db_path.value()).c_str()); if (result != SECSuccess) { Free(); return false; diff --git a/chrome/browser/importer/nss_decryptor_win.h b/chrome/browser/importer/nss_decryptor_win.h index 0436323..23e7b1a 100644 --- a/chrome/browser/importer/nss_decryptor_win.h +++ b/chrome/browser/importer/nss_decryptor_win.h @@ -117,7 +117,7 @@ class NSSDecryptor { // Loads NSS3 library and returns true if successful. // |dll_path| indicates the location of NSS3 DLL files, and |db_path| // is the location of the database file that stores the keys. - bool Init(const std::wstring& dll_path, const std::wstring& db_path); + bool Init(const FilePath& dll_path, const FilePath& db_path); // Frees the libraries. void Free(); @@ -139,8 +139,8 @@ class NSSDecryptor { std::vector<webkit_glue::PasswordForm>* forms); private: - // Performs tasks common across all platforms to initialize NSS. - bool InitNSS(const std::wstring& db_path, + // Call NSS initialization funcs. + bool InitNSS(const FilePath& db_path, base::NativeLibrary plds4_dll, base::NativeLibrary nspr4_dll); diff --git a/chrome/browser/importer/profile_writer.cc b/chrome/browser/importer/profile_writer.cc index 00e8dcf..1ea2c46 100644 --- a/chrome/browser/importer/profile_writer.cc +++ b/chrome/browser/importer/profile_writer.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -19,7 +19,8 @@ using webkit_glue::PasswordForm; -ProfileWriter::BookmarkEntry::BookmarkEntry() : in_toolbar(false) {} +ProfileWriter::BookmarkEntry::BookmarkEntry() : in_toolbar(false), + is_folder(false) {} ProfileWriter::BookmarkEntry::~BookmarkEntry() {} @@ -82,7 +83,7 @@ void ProfileWriter::AddBookmarkEntry( for (std::vector<BookmarkEntry>::const_iterator it = bookmark.begin(); it != bookmark.end(); ++it) { // Don't insert this url if it isn't valid. - if (!it->url.is_valid()) + if (!it->is_folder && !it->url.is_valid()) continue; // We suppose that bookmarks are unique by Title, URL, and Folder. Since @@ -119,8 +120,13 @@ void ProfileWriter::AddBookmarkEntry( parent = child; } groups_added_to.insert(parent); - model->AddURLWithCreationTime(parent, parent->GetChildCount(), - WideToUTF16Hack(it->title), it->url, it->creation_time); + if (it->is_folder) { + model->AddGroup(parent, parent->GetChildCount(), + WideToUTF16Hack(it->title)); + } else { + model->AddURLWithCreationTime(parent, parent->GetChildCount(), + WideToUTF16Hack(it->title), it->url, it->creation_time); + } // If some items are put into toolbar, it looks like the user was using // it in their last browser. We turn on the bookmarks toolbar. @@ -181,8 +187,8 @@ static std::string BuildHostPathKey(const TemplateURL* t_url, if (t_url->url()->SupportsReplacement()) { return HostPathKeyForURL(GURL( t_url->url()->ReplaceSearchTerms( - *t_url, L"random string", - TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, std::wstring()))); + *t_url, ASCIIToUTF16("random string"), + TemplateURLRef::NO_SUGGESTIONS_AVAILABLE, string16()))); } } return std::string(); diff --git a/chrome/browser/importer/profile_writer.h b/chrome/browser/importer/profile_writer.h index 5c0e25c..3002b1a 100644 --- a/chrome/browser/importer/profile_writer.h +++ b/chrome/browser/importer/profile_writer.h @@ -56,6 +56,7 @@ class ProfileWriter : public base::RefCountedThreadSafe<ProfileWriter> { ~BookmarkEntry(); bool in_toolbar; + bool is_folder; GURL url; std::vector<std::wstring> path; std::wstring title; |