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/firefox3_importer.h" | 5 #include "chrome/browser/importer/firefox3_importer.h" |
6 | 6 |
7 #include <set> | 7 #include <set> |
8 | 8 |
9 #include "base/file_util.h" | 9 #include "base/file_util.h" |
10 #include "base/files/file_enumerator.h" | 10 #include "base/files/file_enumerator.h" |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 if ((items & importer::PASSWORDS) && !cancelled()) { | 124 if ((items & importer::PASSWORDS) && !cancelled()) { |
125 bridge_->NotifyItemStarted(importer::PASSWORDS); | 125 bridge_->NotifyItemStarted(importer::PASSWORDS); |
126 ImportPasswords(); | 126 ImportPasswords(); |
127 bridge_->NotifyItemEnded(importer::PASSWORDS); | 127 bridge_->NotifyItemEnded(importer::PASSWORDS); |
128 } | 128 } |
129 bridge_->NotifyEnded(); | 129 bridge_->NotifyEnded(); |
130 } | 130 } |
131 | 131 |
132 void Firefox3Importer::ImportHistory() { | 132 void Firefox3Importer::ImportHistory() { |
133 base::FilePath file = source_path_.AppendASCII("places.sqlite"); | 133 base::FilePath file = source_path_.AppendASCII("places.sqlite"); |
134 if (!file_util::PathExists(file)) | 134 if (!base::PathExists(file)) |
135 return; | 135 return; |
136 | 136 |
137 sql::Connection db; | 137 sql::Connection db; |
138 if (!db.Open(file)) | 138 if (!db.Open(file)) |
139 return; | 139 return; |
140 | 140 |
141 // |visit_type| represent the transition type of URLs (typed, click, | 141 // |visit_type| represent the transition type of URLs (typed, click, |
142 // redirect, bookmark, etc.) We eliminate some URLs like sub-frames and | 142 // redirect, bookmark, etc.) We eliminate some URLs like sub-frames and |
143 // redirects, since we don't want them to appear in history. | 143 // redirects, since we don't want them to appear in history. |
144 // Firefox transition types are defined in: | 144 // Firefox transition types are defined in: |
(...skipping 23 matching lines...) Expand all Loading... |
168 | 168 |
169 rows.push_back(row); | 169 rows.push_back(row); |
170 } | 170 } |
171 | 171 |
172 if (!rows.empty() && !cancelled()) | 172 if (!rows.empty() && !cancelled()) |
173 bridge_->SetHistoryItems(rows, importer::VISIT_SOURCE_FIREFOX_IMPORTED); | 173 bridge_->SetHistoryItems(rows, importer::VISIT_SOURCE_FIREFOX_IMPORTED); |
174 } | 174 } |
175 | 175 |
176 void Firefox3Importer::ImportBookmarks() { | 176 void Firefox3Importer::ImportBookmarks() { |
177 base::FilePath file = source_path_.AppendASCII("places.sqlite"); | 177 base::FilePath file = source_path_.AppendASCII("places.sqlite"); |
178 if (!file_util::PathExists(file)) | 178 if (!base::PathExists(file)) |
179 return; | 179 return; |
180 | 180 |
181 sql::Connection db; | 181 sql::Connection db; |
182 if (!db.Open(file)) | 182 if (!db.Open(file)) |
183 return; | 183 return; |
184 | 184 |
185 // Get the bookmark folders that we are interested in. | 185 // Get the bookmark folders that we are interested in. |
186 int toolbar_folder_id = -1; | 186 int toolbar_folder_id = -1; |
187 int menu_folder_id = -1; | 187 int menu_folder_id = -1; |
188 int unsorted_folder_id = -1; | 188 int unsorted_folder_id = -1; |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 // Initializes NSS3. | 326 // Initializes NSS3. |
327 NSSDecryptor decryptor; | 327 NSSDecryptor decryptor; |
328 if (!decryptor.Init(source_path_, source_path_) && | 328 if (!decryptor.Init(source_path_, source_path_) && |
329 !decryptor.Init(app_path_, source_path_)) { | 329 !decryptor.Init(app_path_, source_path_)) { |
330 return; | 330 return; |
331 } | 331 } |
332 | 332 |
333 std::vector<content::PasswordForm> forms; | 333 std::vector<content::PasswordForm> forms; |
334 base::FilePath source_path = source_path_; | 334 base::FilePath source_path = source_path_; |
335 base::FilePath file = source_path.AppendASCII("signons.sqlite"); | 335 base::FilePath file = source_path.AppendASCII("signons.sqlite"); |
336 if (file_util::PathExists(file)) { | 336 if (base::PathExists(file)) { |
337 // Since Firefox 3.1, passwords are in signons.sqlite db. | 337 // Since Firefox 3.1, passwords are in signons.sqlite db. |
338 decryptor.ReadAndParseSignons(file, &forms); | 338 decryptor.ReadAndParseSignons(file, &forms); |
339 } else { | 339 } else { |
340 // Firefox 3.0 uses signons3.txt to store the passwords. | 340 // Firefox 3.0 uses signons3.txt to store the passwords. |
341 file = source_path.AppendASCII("signons3.txt"); | 341 file = source_path.AppendASCII("signons3.txt"); |
342 if (!file_util::PathExists(file)) | 342 if (!base::PathExists(file)) |
343 file = source_path.AppendASCII("signons2.txt"); | 343 file = source_path.AppendASCII("signons2.txt"); |
344 | 344 |
345 std::string content; | 345 std::string content; |
346 file_util::ReadFileToString(file, &content); | 346 file_util::ReadFileToString(file, &content); |
347 decryptor.ParseSignons(content, &forms); | 347 decryptor.ParseSignons(content, &forms); |
348 } | 348 } |
349 | 349 |
350 if (!cancelled()) { | 350 if (!cancelled()) { |
351 for (size_t i = 0; i < forms.size(); ++i) { | 351 for (size_t i = 0; i < forms.size(); ++i) { |
352 bridge_->SetPasswordForm(forms[i]); | 352 bridge_->SetPasswordForm(forms[i]); |
(...skipping 11 matching lines...) Expand all Loading... |
364 void Firefox3Importer::ImportHomepage() { | 364 void Firefox3Importer::ImportHomepage() { |
365 GURL home_page = GetHomepage(source_path_); | 365 GURL home_page = GetHomepage(source_path_); |
366 if (home_page.is_valid() && !IsDefaultHomepage(home_page, app_path_)) { | 366 if (home_page.is_valid() && !IsDefaultHomepage(home_page, app_path_)) { |
367 bridge_->AddHomePage(home_page); | 367 bridge_->AddHomePage(home_page); |
368 } | 368 } |
369 } | 369 } |
370 | 370 |
371 void Firefox3Importer::GetSearchEnginesXMLData( | 371 void Firefox3Importer::GetSearchEnginesXMLData( |
372 std::vector<std::string>* search_engine_data) { | 372 std::vector<std::string>* search_engine_data) { |
373 base::FilePath file = source_path_.AppendASCII("search.sqlite"); | 373 base::FilePath file = source_path_.AppendASCII("search.sqlite"); |
374 if (!file_util::PathExists(file)) | 374 if (!base::PathExists(file)) |
375 return; | 375 return; |
376 | 376 |
377 sql::Connection db; | 377 sql::Connection db; |
378 if (!db.Open(file)) | 378 if (!db.Open(file)) |
379 return; | 379 return; |
380 | 380 |
381 const char* query = "SELECT engineid FROM engine_data " | 381 const char* query = "SELECT engineid FROM engine_data " |
382 "WHERE engineid NOT IN " | 382 "WHERE engineid NOT IN " |
383 "(SELECT engineid FROM engine_data " | 383 "(SELECT engineid FROM engine_data " |
384 "WHERE name='hidden') " | 384 "WHERE name='hidden') " |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
582 | 582 |
583 if (!FaviconUtil::ReencodeFavicon(&data[0], data.size(), &usage.png_data)) | 583 if (!FaviconUtil::ReencodeFavicon(&data[0], data.size(), &usage.png_data)) |
584 continue; // Unable to decode. | 584 continue; // Unable to decode. |
585 | 585 |
586 usage.urls = i->second; | 586 usage.urls = i->second; |
587 favicons->push_back(usage); | 587 favicons->push_back(usage); |
588 } | 588 } |
589 s.Reset(true); | 589 s.Reset(true); |
590 } | 590 } |
591 } | 591 } |
OLD | NEW |