| OLD | NEW |
| 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/firefox_importer.h" | 5 #include "chrome/utility/importer/firefox_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 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 473 for (base::FilePath engine_path = engines.Next(); | 473 for (base::FilePath engine_path = engines.Next(); |
| 474 !engine_path.value().empty(); engine_path = engines.Next()) { | 474 !engine_path.value().empty(); engine_path = engines.Next()) { |
| 475 std::string file_data; | 475 std::string file_data; |
| 476 base::ReadFileToString(file, &file_data); | 476 base::ReadFileToString(file, &file_data); |
| 477 search_engine_data->push_back(file_data); | 477 search_engine_data->push_back(file_data); |
| 478 } | 478 } |
| 479 } | 479 } |
| 480 | 480 |
| 481 void FirefoxImporter::GetSearchEnginesXMLDataFromJSON( | 481 void FirefoxImporter::GetSearchEnginesXMLDataFromJSON( |
| 482 std::vector<std::string>* search_engine_data) { | 482 std::vector<std::string>* search_engine_data) { |
| 483 // search-metadata.json contains keywords for search engines. This |
| 484 // file exists only if the user has set keywords for search engines. |
| 485 base::FilePath search_metadata_json_file = |
| 486 source_path_.AppendASCII("search-metadata.json"); |
| 487 JSONFileValueSerializer metadata_serializer(search_metadata_json_file); |
| 488 scoped_ptr<base::Value> metadata_root( |
| 489 metadata_serializer.Deserialize(NULL, NULL)); |
| 490 const base::DictionaryValue* search_metadata_root = NULL; |
| 491 if (metadata_root) |
| 492 metadata_root->GetAsDictionary(&search_metadata_root); |
| 493 |
| 494 // search.json contains information about search engines to import. |
| 483 base::FilePath search_json_file = source_path_.AppendASCII("search.json"); | 495 base::FilePath search_json_file = source_path_.AppendASCII("search.json"); |
| 484 if (!base::PathExists(search_json_file)) | 496 if (!base::PathExists(search_json_file)) |
| 485 return; | 497 return; |
| 486 | 498 |
| 487 JSONFileValueSerializer serializer(search_json_file); | 499 JSONFileValueSerializer serializer(search_json_file); |
| 488 scoped_ptr<base::Value> root(serializer.Deserialize(NULL, NULL)); | 500 scoped_ptr<base::Value> root(serializer.Deserialize(NULL, NULL)); |
| 489 const base::DictionaryValue* search_root = NULL; | 501 const base::DictionaryValue* search_root = NULL; |
| 490 if (!root || !root->GetAsDictionary(&search_root)) | 502 if (!root || !root->GetAsDictionary(&search_root)) |
| 491 return; | 503 return; |
| 492 | 504 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 549 file_path.substr(index + kAppPrefix.length())); | 561 file_path.substr(index + kAppPrefix.length())); |
| 550 } else if ((index = file_path.find(kProfilePrefix)) != | 562 } else if ((index = file_path.find(kProfilePrefix)) != |
| 551 std::string::npos) { | 563 std::string::npos) { |
| 552 // Replace '[profile]/' with actual profile path. | 564 // Replace '[profile]/' with actual profile path. |
| 553 xml_file = source_path_.AppendASCII("searchplugins").AppendASCII( | 565 xml_file = source_path_.AppendASCII("searchplugins").AppendASCII( |
| 554 file_path.substr(index + kProfilePrefix.length())); | 566 file_path.substr(index + kProfilePrefix.length())); |
| 555 } | 567 } |
| 556 | 568 |
| 557 std::string file_data; | 569 std::string file_data; |
| 558 base::ReadFileToString(xml_file, &file_data); | 570 base::ReadFileToString(xml_file, &file_data); |
| 571 |
| 572 // If a keyword is mentioned for this search engine, then add |
| 573 // it to the XML string as an <Alias> element and use this updated |
| 574 // string. |
| 575 const base::DictionaryValue* search_xml_path = NULL; |
| 576 if (search_metadata_root && search_metadata_root->HasKey(file_path) && |
| 577 search_metadata_root->GetDictionaryWithoutPathExpansion( |
| 578 file_path, &search_xml_path)) { |
| 579 std::string alias; |
| 580 search_xml_path->GetString("alias", &alias); |
| 581 |
| 582 // Add <Alias> element as the last child element. |
| 583 size_t end_of_parent = file_data.find("</SearchPlugin>"); |
| 584 if (end_of_parent != std::string::npos && !alias.empty()) |
| 585 file_data.insert(end_of_parent, "<Alias>" + alias + "</Alias> \n"); |
| 586 } |
| 559 search_engine_data->push_back(file_data); | 587 search_engine_data->push_back(file_data); |
| 560 } | 588 } |
| 561 } | 589 } |
| 562 } | 590 } |
| 563 } | 591 } |
| 564 | 592 |
| 565 void FirefoxImporter::LoadRootNodeID(sql::Connection* db, | 593 void FirefoxImporter::LoadRootNodeID(sql::Connection* db, |
| 566 int* toolbar_folder_id, | 594 int* toolbar_folder_id, |
| 567 int* menu_folder_id, | 595 int* menu_folder_id, |
| 568 int* unsorted_folder_id) { | 596 int* unsorted_folder_id) { |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 697 | 725 |
| 698 if (!importer::ReencodeFavicon(&data[0], data.size(), &usage.png_data)) | 726 if (!importer::ReencodeFavicon(&data[0], data.size(), &usage.png_data)) |
| 699 continue; // Unable to decode. | 727 continue; // Unable to decode. |
| 700 | 728 |
| 701 usage.urls = i->second; | 729 usage.urls = i->second; |
| 702 favicons->push_back(usage); | 730 favicons->push_back(usage); |
| 703 } | 731 } |
| 704 s.Reset(true); | 732 s.Reset(true); |
| 705 } | 733 } |
| 706 } | 734 } |
| OLD | NEW |