| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
| 11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
| 12 #include "base/i18n/icu_string_conversions.h" | 12 #include "base/i18n/icu_string_conversions.h" |
| 13 #include "base/message_loop.h" | 13 #include "base/message_loop.h" |
| 14 #include "base/path_service.h" | 14 #include "base/path_service.h" |
| 15 #include "base/stl_util.h" | 15 #include "base/stl_util.h" |
| 16 #include "base/string_util.h" | 16 #include "base/string_util.h" |
| 17 #include "base/strings/string_number_conversions.h" | 17 #include "base/strings/string_number_conversions.h" |
| 18 #include "base/strings/string_split.h" | 18 #include "base/strings/string_split.h" |
| 19 #include "base/utf_string_conversions.h" | 19 #include "base/utf_string_conversions.h" |
| 20 #include "chrome/browser/bookmarks/imported_bookmark_entry.h" |
| 20 #include "chrome/browser/history/history_types.h" | 21 #include "chrome/browser/history/history_types.h" |
| 21 #include "chrome/browser/importer/firefox_importer_utils.h" | 22 #include "chrome/browser/importer/firefox_importer_utils.h" |
| 22 #include "chrome/browser/importer/importer_bridge.h" | 23 #include "chrome/browser/importer/importer_bridge.h" |
| 23 #include "chrome/browser/importer/importer_util.h" | 24 #include "chrome/browser/importer/importer_util.h" |
| 24 #include "chrome/browser/importer/mork_reader.h" | 25 #include "chrome/browser/importer/mork_reader.h" |
| 25 #include "chrome/browser/importer/nss_decryptor.h" | 26 #include "chrome/browser/importer/nss_decryptor.h" |
| 26 #include "chrome/browser/search_engines/template_url.h" | 27 #include "chrome/browser/search_engines/template_url.h" |
| 27 #include "chrome/common/time_format.h" | 28 #include "chrome/common/time_format.h" |
| 28 #include "chrome/common/url_constants.h" | 29 #include "chrome/common/url_constants.h" |
| 29 #include "content/public/common/password_form.h" | 30 #include "content/public/common/password_form.h" |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 data.SetKeyword(keyword); | 142 data.SetKeyword(keyword); |
| 142 data.SetURL(TemplateURLRef::DisplayURLToURLRef(UTF8ToUTF16(url.spec()))); | 143 data.SetURL(TemplateURLRef::DisplayURLToURLRef(UTF8ToUTF16(url.spec()))); |
| 143 return new TemplateURL(NULL, data); | 144 return new TemplateURL(NULL, data); |
| 144 } | 145 } |
| 145 | 146 |
| 146 // static | 147 // static |
| 147 void Firefox2Importer::ImportBookmarksFile( | 148 void Firefox2Importer::ImportBookmarksFile( |
| 148 const base::FilePath& file_path, | 149 const base::FilePath& file_path, |
| 149 const std::set<GURL>& default_urls, | 150 const std::set<GURL>& default_urls, |
| 150 Importer* importer, | 151 Importer* importer, |
| 151 std::vector<ProfileWriter::BookmarkEntry>* bookmarks, | 152 std::vector<ImportedBookmarkEntry>* bookmarks, |
| 152 std::vector<TemplateURL*>* template_urls, | 153 std::vector<TemplateURL*>* template_urls, |
| 153 std::vector<history::ImportedFaviconUsage>* favicons) { | 154 std::vector<history::ImportedFaviconUsage>* favicons) { |
| 154 std::string content; | 155 std::string content; |
| 155 file_util::ReadFileToString(file_path, &content); | 156 file_util::ReadFileToString(file_path, &content); |
| 156 std::vector<std::string> lines; | 157 std::vector<std::string> lines; |
| 157 base::SplitString(content, '\n', &lines); | 158 base::SplitString(content, '\n', &lines); |
| 158 | 159 |
| 159 string16 last_folder; | 160 string16 last_folder; |
| 160 bool last_folder_on_toolbar = false; | 161 bool last_folder_on_toolbar = false; |
| 161 bool last_folder_is_empty = true; | 162 bool last_folder_is_empty = true; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 | 199 |
| 199 if (is_bookmark && | 200 if (is_bookmark && |
| 200 post_data.empty() && | 201 post_data.empty() && |
| 201 CanImportURL(GURL(url)) && | 202 CanImportURL(GURL(url)) && |
| 202 default_urls.find(url) == default_urls.end()) { | 203 default_urls.find(url) == default_urls.end()) { |
| 203 if (toolbar_folder > path.size() && !path.empty()) { | 204 if (toolbar_folder > path.size() && !path.empty()) { |
| 204 NOTREACHED(); // error in parsing. | 205 NOTREACHED(); // error in parsing. |
| 205 break; | 206 break; |
| 206 } | 207 } |
| 207 | 208 |
| 208 ProfileWriter::BookmarkEntry entry; | 209 ImportedBookmarkEntry entry; |
| 209 entry.creation_time = add_date; | 210 entry.creation_time = add_date; |
| 210 entry.url = url; | 211 entry.url = url; |
| 211 entry.title = title; | 212 entry.title = title; |
| 212 | 213 |
| 213 if (toolbar_folder) { | 214 if (toolbar_folder) { |
| 214 // The toolbar folder should be at the top level. | 215 // The toolbar folder should be at the top level. |
| 215 entry.in_toolbar = true; | 216 entry.in_toolbar = true; |
| 216 entry.path.assign(path.begin() + toolbar_folder - 1, path.end()); | 217 entry.path.assign(path.begin() + toolbar_folder - 1, path.end()); |
| 217 } else { | 218 } else { |
| 218 // Add this bookmark to the list of |bookmarks|. | 219 // Add this bookmark to the list of |bookmarks|. |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 last_folder_is_empty = true; | 255 last_folder_is_empty = true; |
| 255 } else if (StartsWithASCII(line, "</DL>", false)) { | 256 } else if (StartsWithASCII(line, "</DL>", false)) { |
| 256 if (path.empty()) | 257 if (path.empty()) |
| 257 break; // Mismatch <DL>. | 258 break; // Mismatch <DL>. |
| 258 | 259 |
| 259 string16 folder_title = path.back(); | 260 string16 folder_title = path.back(); |
| 260 path.pop_back(); | 261 path.pop_back(); |
| 261 | 262 |
| 262 if (last_folder_is_empty) { | 263 if (last_folder_is_empty) { |
| 263 // Empty folder should be added explicitly. | 264 // Empty folder should be added explicitly. |
| 264 ProfileWriter::BookmarkEntry entry; | 265 ImportedBookmarkEntry entry; |
| 265 entry.is_folder = true; | 266 entry.is_folder = true; |
| 266 entry.creation_time = last_folder_add_date; | 267 entry.creation_time = last_folder_add_date; |
| 267 entry.title = folder_title; | 268 entry.title = folder_title; |
| 268 if (toolbar_folder) { | 269 if (toolbar_folder) { |
| 269 // The toolbar folder should be at the top level. | 270 // The toolbar folder should be at the top level. |
| 270 // Make sure we don't add the toolbar folder itself if it is empty. | 271 // Make sure we don't add the toolbar folder itself if it is empty. |
| 271 if (toolbar_folder <= path.size()) { | 272 if (toolbar_folder <= path.size()) { |
| 272 entry.in_toolbar = true; | 273 entry.in_toolbar = true; |
| 273 entry.path.assign(path.begin() + toolbar_folder - 1, path.end()); | 274 entry.path.assign(path.begin() + toolbar_folder - 1, path.end()); |
| 274 bookmarks->push_back(entry); | 275 bookmarks->push_back(entry); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 289 } | 290 } |
| 290 } | 291 } |
| 291 | 292 |
| 292 void Firefox2Importer::ImportBookmarks() { | 293 void Firefox2Importer::ImportBookmarks() { |
| 293 // Load the default bookmarks. | 294 // Load the default bookmarks. |
| 294 std::set<GURL> default_urls; | 295 std::set<GURL> default_urls; |
| 295 if (!parsing_bookmarks_html_file_) | 296 if (!parsing_bookmarks_html_file_) |
| 296 LoadDefaultBookmarks(app_path_, &default_urls); | 297 LoadDefaultBookmarks(app_path_, &default_urls); |
| 297 | 298 |
| 298 // Parse the bookmarks.html file. | 299 // Parse the bookmarks.html file. |
| 299 std::vector<ProfileWriter::BookmarkEntry> bookmarks, toolbar_bookmarks; | 300 std::vector<ImportedBookmarkEntry> bookmarks, toolbar_bookmarks; |
| 300 std::vector<TemplateURL*> template_urls; | 301 std::vector<TemplateURL*> template_urls; |
| 301 std::vector<history::ImportedFaviconUsage> favicons; | 302 std::vector<history::ImportedFaviconUsage> favicons; |
| 302 base::FilePath file = source_path_; | 303 base::FilePath file = source_path_; |
| 303 if (!parsing_bookmarks_html_file_) | 304 if (!parsing_bookmarks_html_file_) |
| 304 file = file.AppendASCII("bookmarks.html"); | 305 file = file.AppendASCII("bookmarks.html"); |
| 305 | 306 |
| 306 ImportBookmarksFile(file, default_urls, this, &bookmarks, &template_urls, | 307 ImportBookmarksFile(file, default_urls, this, &bookmarks, &template_urls, |
| 307 &favicons); | 308 &favicons); |
| 308 | 309 |
| 309 // Write data into profile. | 310 // Write data into profile. |
| (...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 657 | 658 |
| 658 // We need to make up a URL for the favicon. We use a version of the page's | 659 // We need to make up a URL for the favicon. We use a version of the page's |
| 659 // URL so that we can be sure it will not collide. | 660 // URL so that we can be sure it will not collide. |
| 660 usage.favicon_url = GURL(std::string("made-up-favicon:") + link_url.spec()); | 661 usage.favicon_url = GURL(std::string("made-up-favicon:") + link_url.spec()); |
| 661 | 662 |
| 662 // We only have one URL per favicon for Firefox 2 bookmarks. | 663 // We only have one URL per favicon for Firefox 2 bookmarks. |
| 663 usage.urls.insert(link_url); | 664 usage.urls.insert(link_url); |
| 664 | 665 |
| 665 favicons->push_back(usage); | 666 favicons->push_back(usage); |
| 666 } | 667 } |
| OLD | NEW |