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