OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/sessions/content/content_serialized_navigation_builder.h" | 5 #include "components/sessions/content/content_serialized_navigation_builder.h" |
6 | 6 |
| 7 #include "base/macros.h" |
| 8 #include "base/strings/string_tokenizer.h" |
| 9 #include "base/strings/string_util.h" |
7 #include "components/sessions/content/content_record_password_state.h" | 10 #include "components/sessions/content/content_record_password_state.h" |
| 11 #include "components/sessions/content/extended_info_handler.h" |
| 12 #include "components/sessions/core/serialized_navigation_driver.h" |
8 #include "components/sessions/core/serialized_navigation_entry.h" | 13 #include "components/sessions/core/serialized_navigation_entry.h" |
9 #include "content/public/browser/browser_context.h" | 14 #include "content/public/browser/browser_context.h" |
10 #include "content/public/browser/favicon_status.h" | 15 #include "content/public/browser/favicon_status.h" |
11 #include "content/public/browser/navigation_controller.h" | 16 #include "content/public/browser/navigation_controller.h" |
12 #include "content/public/browser/navigation_entry.h" | 17 #include "content/public/browser/navigation_entry.h" |
13 #include "content/public/common/page_state.h" | 18 #include "content/public/common/page_state.h" |
14 #include "content/public/common/referrer.h" | 19 #include "content/public/common/referrer.h" |
15 | 20 |
16 namespace sessions { | 21 namespace sessions { |
17 | 22 |
(...skipping 17 matching lines...) Expand all Loading... |
35 navigation.is_overriding_user_agent_ = entry.GetIsOverridingUserAgent(); | 40 navigation.is_overriding_user_agent_ = entry.GetIsOverridingUserAgent(); |
36 navigation.timestamp_ = entry.GetTimestamp(); | 41 navigation.timestamp_ = entry.GetTimestamp(); |
37 navigation.is_restored_ = entry.IsRestored(); | 42 navigation.is_restored_ = entry.IsRestored(); |
38 entry.GetExtraData(kSearchTermsKey, &navigation.search_terms_); | 43 entry.GetExtraData(kSearchTermsKey, &navigation.search_terms_); |
39 if (entry.GetFavicon().valid) | 44 if (entry.GetFavicon().valid) |
40 navigation.favicon_url_ = entry.GetFavicon().url; | 45 navigation.favicon_url_ = entry.GetFavicon().url; |
41 navigation.http_status_code_ = entry.GetHttpStatusCode(); | 46 navigation.http_status_code_ = entry.GetHttpStatusCode(); |
42 navigation.redirect_chain_ = entry.GetRedirectChain(); | 47 navigation.redirect_chain_ = entry.GetRedirectChain(); |
43 navigation.password_state_ = GetPasswordStateFromNavigation(entry); | 48 navigation.password_state_ = GetPasswordStateFromNavigation(entry); |
44 | 49 |
| 50 for (const auto& handler_entry : |
| 51 SerializedNavigationDriver::Get()->GetAllExtendedInfoHandlers()) { |
| 52 ExtendedInfoHandler* handler = handler_entry.second.get(); |
| 53 DCHECK(handler); |
| 54 navigation.extended_info_map_[handler_entry.first] = |
| 55 handler->GetExtendedInfo(entry); |
| 56 } |
| 57 |
45 return navigation; | 58 return navigation; |
46 } | 59 } |
47 | 60 |
48 // static | 61 // static |
49 std::unique_ptr<content::NavigationEntry> | 62 std::unique_ptr<content::NavigationEntry> |
50 ContentSerializedNavigationBuilder::ToNavigationEntry( | 63 ContentSerializedNavigationBuilder::ToNavigationEntry( |
51 const SerializedNavigationEntry* navigation, | 64 const SerializedNavigationEntry* navigation, |
52 int page_id, | 65 int page_id, |
53 content::BrowserContext* browser_context) { | 66 content::BrowserContext* browser_context) { |
54 blink::WebReferrerPolicy policy = | 67 blink::WebReferrerPolicy policy = |
(...skipping 16 matching lines...) Expand all Loading... |
71 entry->SetPageID(page_id); | 84 entry->SetPageID(page_id); |
72 entry->SetHasPostData(navigation->has_post_data_); | 85 entry->SetHasPostData(navigation->has_post_data_); |
73 entry->SetPostID(navigation->post_id_); | 86 entry->SetPostID(navigation->post_id_); |
74 entry->SetOriginalRequestURL(navigation->original_request_url_); | 87 entry->SetOriginalRequestURL(navigation->original_request_url_); |
75 entry->SetIsOverridingUserAgent(navigation->is_overriding_user_agent_); | 88 entry->SetIsOverridingUserAgent(navigation->is_overriding_user_agent_); |
76 entry->SetTimestamp(navigation->timestamp_); | 89 entry->SetTimestamp(navigation->timestamp_); |
77 entry->SetExtraData(kSearchTermsKey, navigation->search_terms_); | 90 entry->SetExtraData(kSearchTermsKey, navigation->search_terms_); |
78 entry->SetHttpStatusCode(navigation->http_status_code_); | 91 entry->SetHttpStatusCode(navigation->http_status_code_); |
79 entry->SetRedirectChain(navigation->redirect_chain_); | 92 entry->SetRedirectChain(navigation->redirect_chain_); |
80 | 93 |
| 94 for (const auto& handler_entry : |
| 95 SerializedNavigationDriver::Get()->GetAllExtendedInfoHandlers()) { |
| 96 const std::string& key = handler_entry.first; |
| 97 if (!navigation->extended_info_map_.count(key)) |
| 98 continue; |
| 99 ExtendedInfoHandler* handler = handler_entry.second.get(); |
| 100 DCHECK(handler); |
| 101 const std::string& value = navigation->extended_info_map_.at(key); |
| 102 handler->RestoreExtendedInfo(value, entry.get()); |
| 103 } |
| 104 |
81 // These fields should have default values. | 105 // These fields should have default values. |
82 DCHECK_EQ(SerializedNavigationEntry::STATE_INVALID, | 106 DCHECK_EQ(SerializedNavigationEntry::STATE_INVALID, |
83 navigation->blocked_state_); | 107 navigation->blocked_state_); |
84 DCHECK_EQ(0u, navigation->content_pack_categories_.size()); | 108 DCHECK_EQ(0u, navigation->content_pack_categories_.size()); |
85 | 109 |
86 return entry; | 110 return entry; |
87 } | 111 } |
88 | 112 |
89 // static | 113 // static |
90 std::vector<std::unique_ptr<content::NavigationEntry>> | 114 std::vector<std::unique_ptr<content::NavigationEntry>> |
91 ContentSerializedNavigationBuilder::ToNavigationEntries( | 115 ContentSerializedNavigationBuilder::ToNavigationEntries( |
92 const std::vector<SerializedNavigationEntry>& navigations, | 116 const std::vector<SerializedNavigationEntry>& navigations, |
93 content::BrowserContext* browser_context) { | 117 content::BrowserContext* browser_context) { |
94 int page_id = 0; | 118 int page_id = 0; |
95 std::vector<std::unique_ptr<content::NavigationEntry>> entries; | 119 std::vector<std::unique_ptr<content::NavigationEntry>> entries; |
96 entries.reserve(navigations.size()); | 120 entries.reserve(navigations.size()); |
97 for (const auto& navigation : navigations) { | 121 for (const auto& navigation : navigations) { |
98 entries.push_back(ToNavigationEntry(&navigation, page_id, browser_context)); | 122 entries.push_back(ToNavigationEntry(&navigation, page_id, browser_context)); |
99 ++page_id; | 123 ++page_id; |
100 } | 124 } |
101 return entries; | 125 return entries; |
102 } | 126 } |
103 | 127 |
104 } // namespace sessions | 128 } // namespace sessions |
OLD | NEW |