| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/toolbar_importer.h" | 5 #include "chrome/browser/importer/toolbar_importer.h" |
| 6 | 6 |
| 7 #include <limits> | 7 #include <limits> |
| 8 | 8 |
| 9 #include "base/rand_util.h" | 9 #include "base/rand_util.h" |
| 10 #include "base/string_number_conversions.h" | 10 #include "base/string_number_conversions.h" |
| 11 #include "base/string_split.h" | 11 #include "base/string_split.h" |
| 12 #include "base/string_util.h" | |
| 13 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 14 #include "base/values.h" | |
| 15 #include "chrome/browser/first_run/first_run.h" | 13 #include "chrome/browser/first_run/first_run.h" |
| 16 #include "chrome/browser/importer/importer_bridge.h" | 14 #include "chrome/browser/importer/importer_bridge.h" |
| 17 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
| 18 #include "chrome/common/libxml_utils.h" | 16 #include "chrome/common/libxml_utils.h" |
| 19 #include "chrome/common/net/url_request_context_getter.h" | |
| 20 #include "content/browser/browser_thread.h" | 17 #include "content/browser/browser_thread.h" |
| 21 #include "grit/generated_resources.h" | 18 #include "grit/generated_resources.h" |
| 22 #include "net/base/cookie_monster.h" | |
| 23 #include "net/base/data_url.h" | |
| 24 #include "net/url_request/url_request_context.h" | |
| 25 | 19 |
| 26 // ToolbarImporterUtils | |
| 27 static const char* kGoogleDomainUrl = "http://.google.com/"; | |
| 28 static const wchar_t kSplitStringToken = L';'; | |
| 29 static const char* kGoogleDomainSecureCookieId = "SID="; | |
| 30 | |
| 31 bool toolbar_importer_utils::IsGoogleGAIACookieInstalled() { | |
| 32 net::CookieStore* store = | |
| 33 Profile::GetDefaultRequestContext()->GetCookieStore(); | |
| 34 GURL url(kGoogleDomainUrl); | |
| 35 net::CookieOptions options; | |
| 36 options.set_include_httponly(); // The SID cookie might be httponly. | |
| 37 std::string cookies = store->GetCookiesWithOptions(url, options); | |
| 38 std::vector<std::string> cookie_list; | |
| 39 base::SplitString(cookies, kSplitStringToken, &cookie_list); | |
| 40 for (std::vector<std::string>::iterator current = cookie_list.begin(); | |
| 41 current != cookie_list.end(); | |
| 42 ++current) { | |
| 43 size_t position = (*current).find(kGoogleDomainSecureCookieId); | |
| 44 if (0 == position) | |
| 45 return true; | |
| 46 } | |
| 47 return false; | |
| 48 } | |
| 49 | |
| 50 // | |
| 51 // Toolbar5Importer | 20 // Toolbar5Importer |
| 52 // | |
| 53 const char Toolbar5Importer::kXmlApiReplyXmlTag[] = "xml_api_reply"; | 21 const char Toolbar5Importer::kXmlApiReplyXmlTag[] = "xml_api_reply"; |
| 54 const char Toolbar5Importer::kBookmarksXmlTag[] = "bookmarks"; | 22 const char Toolbar5Importer::kBookmarksXmlTag[] = "bookmarks"; |
| 55 const char Toolbar5Importer::kBookmarkXmlTag[] = "bookmark"; | 23 const char Toolbar5Importer::kBookmarkXmlTag[] = "bookmark"; |
| 56 const char Toolbar5Importer::kTitleXmlTag[] = "title"; | 24 const char Toolbar5Importer::kTitleXmlTag[] = "title"; |
| 57 const char Toolbar5Importer::kUrlXmlTag[] = "url"; | 25 const char Toolbar5Importer::kUrlXmlTag[] = "url"; |
| 58 const char Toolbar5Importer::kTimestampXmlTag[] = "timestamp"; | 26 const char Toolbar5Importer::kTimestampXmlTag[] = "timestamp"; |
| 59 const char Toolbar5Importer::kLabelsXmlTag[] = "labels"; | 27 const char Toolbar5Importer::kLabelsXmlTag[] = "labels"; |
| 60 const char Toolbar5Importer::kLabelsXmlCloseTag[] = "/labels"; | 28 const char Toolbar5Importer::kLabelsXmlCloseTag[] = "/labels"; |
| 61 const char Toolbar5Importer::kLabelXmlTag[] = "label"; | 29 const char Toolbar5Importer::kLabelXmlTag[] = "label"; |
| 62 const char Toolbar5Importer::kAttributesXmlTag[] = "attributes"; | 30 const char Toolbar5Importer::kAttributesXmlTag[] = "attributes"; |
| (...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 584 void Toolbar5Importer::AddBookmarksToChrome( | 552 void Toolbar5Importer::AddBookmarksToChrome( |
| 585 const std::vector<ProfileWriter::BookmarkEntry>& bookmarks) { | 553 const std::vector<ProfileWriter::BookmarkEntry>& bookmarks) { |
| 586 if (!bookmarks.empty() && !cancelled()) { | 554 if (!bookmarks.empty() && !cancelled()) { |
| 587 const std::wstring& first_folder_name = UTF16ToWideHack( | 555 const std::wstring& first_folder_name = UTF16ToWideHack( |
| 588 bridge_->GetLocalizedString(IDS_BOOKMARK_GROUP_FROM_GOOGLE_TOOLBAR)); | 556 bridge_->GetLocalizedString(IDS_BOOKMARK_GROUP_FROM_GOOGLE_TOOLBAR)); |
| 589 int options = ProfileWriter::ADD_IF_UNIQUE | | 557 int options = ProfileWriter::ADD_IF_UNIQUE | |
| 590 (import_to_bookmark_bar() ? ProfileWriter::IMPORT_TO_BOOKMARK_BAR : 0); | 558 (import_to_bookmark_bar() ? ProfileWriter::IMPORT_TO_BOOKMARK_BAR : 0); |
| 591 bridge_->AddBookmarkEntries(bookmarks, first_folder_name, options); | 559 bridge_->AddBookmarkEntries(bookmarks, first_folder_name, options); |
| 592 } | 560 } |
| 593 } | 561 } |
| OLD | NEW |