Chromium Code Reviews| 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/strings/string_tokenizer.h" | |
| 8 #include "base/strings/string_util.h" | |
| 7 #include "components/sessions/content/content_record_password_state.h" | 9 #include "components/sessions/content/content_record_password_state.h" |
| 8 #include "components/sessions/core/serialized_navigation_entry.h" | 10 #include "components/sessions/core/serialized_navigation_entry.h" |
| 9 #include "content/public/browser/browser_context.h" | 11 #include "content/public/browser/browser_context.h" |
| 10 #include "content/public/browser/favicon_status.h" | 12 #include "content/public/browser/favicon_status.h" |
| 11 #include "content/public/browser/navigation_controller.h" | 13 #include "content/public/browser/navigation_controller.h" |
| 12 #include "content/public/browser/navigation_entry.h" | 14 #include "content/public/browser/navigation_entry.h" |
| 13 #include "content/public/common/page_state.h" | 15 #include "content/public/common/page_state.h" |
| 14 #include "content/public/common/referrer.h" | 16 #include "content/public/common/referrer.h" |
| 15 | 17 |
| 16 namespace sessions { | 18 namespace sessions { |
| 17 | 19 |
| 20 namespace { | |
| 21 | |
| 22 const char kOfflinePageHeader[] = "X-Chrome-offline"; | |
|
nasko
2016/09/09 21:42:48
Doesn't the full header value include ":" as well?
jianli
2016/09/09 22:32:48
Done.
| |
| 23 | |
| 24 // Returns the offline page info that needs to be persisted, based on extra | |
| 25 // headers. | |
| 26 // TODO(jianli): Move this logic to components/offline_pages/request. | |
|
nasko
2016/09/09 21:42:48
Is this TODO supposed to be resolved in later patc
jianli
2016/09/09 22:32:48
It will be in a different CL since doing it now in
| |
| 27 std::string GetOfflinePageInfo(const content::NavigationEntry& entry) { | |
| 28 std::string extra_headers = entry.GetExtraHeaders(); | |
| 29 if (extra_headers.empty()) | |
| 30 return std::string(); | |
| 31 // The offline header will be the only extra header if it is present. | |
|
nasko
2016/09/09 21:42:48
There is no code that enforces that. Wouldn't addi
jianli
2016/09/09 22:32:48
Most of time extra request header will not be sent
| |
| 32 if (!base::StartsWith(extra_headers, | |
| 33 kOfflinePageHeader, | |
| 34 base::CompareCase::INSENSITIVE_ASCII)) { | |
| 35 return std::string(); | |
| 36 } | |
| 37 std::string value = extra_headers.substr(arraysize(kOfflinePageHeader) - 1); | |
|
nasko
2016/09/09 21:42:48
Doesn't arraysize require including base/macros.h?
jianli
2016/09/09 22:32:48
Done.
| |
| 38 base::StringTokenizer tokenizer(value, ", "); | |
| 39 while (tokenizer.GetNext()) { | |
| 40 if (tokenizer.token() == "persist=1") | |
| 41 return value; | |
| 42 } | |
| 43 return std::string(); | |
| 44 } | |
| 45 | |
| 46 } // namespace | |
| 47 | |
| 18 // static | 48 // static |
| 19 SerializedNavigationEntry | 49 SerializedNavigationEntry |
| 20 ContentSerializedNavigationBuilder::FromNavigationEntry( | 50 ContentSerializedNavigationBuilder::FromNavigationEntry( |
| 21 int index, | 51 int index, |
| 22 const content::NavigationEntry& entry) { | 52 const content::NavigationEntry& entry) { |
| 23 SerializedNavigationEntry navigation; | 53 SerializedNavigationEntry navigation; |
| 24 navigation.index_ = index; | 54 navigation.index_ = index; |
| 25 navigation.unique_id_ = entry.GetUniqueID(); | 55 navigation.unique_id_ = entry.GetUniqueID(); |
| 26 navigation.referrer_url_ = entry.GetReferrer().url; | 56 navigation.referrer_url_ = entry.GetReferrer().url; |
| 27 navigation.referrer_policy_ = entry.GetReferrer().policy; | 57 navigation.referrer_policy_ = entry.GetReferrer().policy; |
| 28 navigation.virtual_url_ = entry.GetVirtualURL(); | 58 navigation.virtual_url_ = entry.GetVirtualURL(); |
| 29 navigation.title_ = entry.GetTitle(); | 59 navigation.title_ = entry.GetTitle(); |
| 30 navigation.encoded_page_state_ = entry.GetPageState().ToEncodedData(); | 60 navigation.encoded_page_state_ = entry.GetPageState().ToEncodedData(); |
| 31 navigation.transition_type_ = entry.GetTransitionType(); | 61 navigation.transition_type_ = entry.GetTransitionType(); |
| 32 navigation.has_post_data_ = entry.GetHasPostData(); | 62 navigation.has_post_data_ = entry.GetHasPostData(); |
| 33 navigation.post_id_ = entry.GetPostID(); | 63 navigation.post_id_ = entry.GetPostID(); |
| 34 navigation.original_request_url_ = entry.GetOriginalRequestURL(); | 64 navigation.original_request_url_ = entry.GetOriginalRequestURL(); |
| 35 navigation.is_overriding_user_agent_ = entry.GetIsOverridingUserAgent(); | 65 navigation.is_overriding_user_agent_ = entry.GetIsOverridingUserAgent(); |
| 36 navigation.timestamp_ = entry.GetTimestamp(); | 66 navigation.timestamp_ = entry.GetTimestamp(); |
| 37 navigation.is_restored_ = entry.IsRestored(); | 67 navigation.is_restored_ = entry.IsRestored(); |
| 38 entry.GetExtraData(kSearchTermsKey, &navigation.search_terms_); | 68 entry.GetExtraData(kSearchTermsKey, &navigation.search_terms_); |
| 39 if (entry.GetFavicon().valid) | 69 if (entry.GetFavicon().valid) |
| 40 navigation.favicon_url_ = entry.GetFavicon().url; | 70 navigation.favicon_url_ = entry.GetFavicon().url; |
| 41 navigation.http_status_code_ = entry.GetHttpStatusCode(); | 71 navigation.http_status_code_ = entry.GetHttpStatusCode(); |
| 42 navigation.redirect_chain_ = entry.GetRedirectChain(); | 72 navigation.redirect_chain_ = entry.GetRedirectChain(); |
| 43 navigation.password_state_ = GetPasswordStateFromNavigation(entry); | 73 navigation.password_state_ = GetPasswordStateFromNavigation(entry); |
| 74 navigation.offline_page_info_ = GetOfflinePageInfo(entry); | |
| 44 | 75 |
| 45 return navigation; | 76 return navigation; |
| 46 } | 77 } |
| 47 | 78 |
| 48 // static | 79 // static |
| 49 std::unique_ptr<content::NavigationEntry> | 80 std::unique_ptr<content::NavigationEntry> |
| 50 ContentSerializedNavigationBuilder::ToNavigationEntry( | 81 ContentSerializedNavigationBuilder::ToNavigationEntry( |
| 51 const SerializedNavigationEntry* navigation, | 82 const SerializedNavigationEntry* navigation, |
| 52 int page_id, | 83 int page_id, |
| 53 content::BrowserContext* browser_context) { | 84 content::BrowserContext* browser_context) { |
| 54 blink::WebReferrerPolicy policy = | 85 blink::WebReferrerPolicy policy = |
| 55 static_cast<blink::WebReferrerPolicy>(navigation->referrer_policy_); | 86 static_cast<blink::WebReferrerPolicy>(navigation->referrer_policy_); |
| 87 // The extra headers, except the one used for offline page support, are not | |
| 88 // sync'ed across sessions. | |
| 89 std::string extra_headers; | |
| 90 if (!navigation->offline_page_info_.empty()) | |
| 91 extra_headers = kOfflinePageHeader + navigation->offline_page_info_; | |
|
nasko
2016/09/09 21:42:48
Shouldn't header name and value be separated by ":
jianli
2016/09/09 22:32:48
Done.
| |
| 56 std::unique_ptr<content::NavigationEntry> entry( | 92 std::unique_ptr<content::NavigationEntry> entry( |
| 57 content::NavigationController::CreateNavigationEntry( | 93 content::NavigationController::CreateNavigationEntry( |
| 58 navigation->virtual_url_, | 94 navigation->virtual_url_, |
| 59 content::Referrer::SanitizeForRequest( | 95 content::Referrer::SanitizeForRequest( |
| 60 navigation->virtual_url_, | 96 navigation->virtual_url_, |
| 61 content::Referrer(navigation->referrer_url_, policy)), | 97 content::Referrer(navigation->referrer_url_, policy)), |
| 62 // Use a transition type of reload so that we don't incorrectly | 98 // Use a transition type of reload so that we don't incorrectly |
| 63 // increase the typed count. | 99 // increase the typed count. |
| 64 ui::PAGE_TRANSITION_RELOAD, false, | 100 ui::PAGE_TRANSITION_RELOAD, false, |
| 65 // The extra headers are not sync'ed across sessions. | 101 extra_headers, browser_context)); |
| 66 std::string(), browser_context)); | |
| 67 | 102 |
| 68 entry->SetTitle(navigation->title_); | 103 entry->SetTitle(navigation->title_); |
| 69 entry->SetPageState(content::PageState::CreateFromEncodedData( | 104 entry->SetPageState(content::PageState::CreateFromEncodedData( |
| 70 navigation->encoded_page_state_)); | 105 navigation->encoded_page_state_)); |
| 71 entry->SetPageID(page_id); | 106 entry->SetPageID(page_id); |
| 72 entry->SetHasPostData(navigation->has_post_data_); | 107 entry->SetHasPostData(navigation->has_post_data_); |
| 73 entry->SetPostID(navigation->post_id_); | 108 entry->SetPostID(navigation->post_id_); |
| 74 entry->SetOriginalRequestURL(navigation->original_request_url_); | 109 entry->SetOriginalRequestURL(navigation->original_request_url_); |
| 75 entry->SetIsOverridingUserAgent(navigation->is_overriding_user_agent_); | 110 entry->SetIsOverridingUserAgent(navigation->is_overriding_user_agent_); |
| 76 entry->SetTimestamp(navigation->timestamp_); | 111 entry->SetTimestamp(navigation->timestamp_); |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 95 std::vector<std::unique_ptr<content::NavigationEntry>> entries; | 130 std::vector<std::unique_ptr<content::NavigationEntry>> entries; |
| 96 entries.reserve(navigations.size()); | 131 entries.reserve(navigations.size()); |
| 97 for (const auto& navigation : navigations) { | 132 for (const auto& navigation : navigations) { |
| 98 entries.push_back(ToNavigationEntry(&navigation, page_id, browser_context)); | 133 entries.push_back(ToNavigationEntry(&navigation, page_id, browser_context)); |
| 99 ++page_id; | 134 ++page_id; |
| 100 } | 135 } |
| 101 return entries; | 136 return entries; |
| 102 } | 137 } |
| 103 | 138 |
| 104 } // namespace sessions | 139 } // namespace sessions |
| OLD | NEW |