| Index: components/sessions/content/content_serialized_navigation_builder.cc
|
| diff --git a/components/sessions/content/content_serialized_navigation_builder.cc b/components/sessions/content/content_serialized_navigation_builder.cc
|
| index 59df5cc2d016730fa5a64ff1c9875b12ad3cd696..90829d5131504482211a6bb6c23be85d1cf6f438 100644
|
| --- a/components/sessions/content/content_serialized_navigation_builder.cc
|
| +++ b/components/sessions/content/content_serialized_navigation_builder.cc
|
| @@ -4,6 +4,9 @@
|
|
|
| #include "components/sessions/content/content_serialized_navigation_builder.h"
|
|
|
| +#include "base/macros.h"
|
| +#include "base/strings/string_tokenizer.h"
|
| +#include "base/strings/string_util.h"
|
| #include "components/sessions/content/content_record_password_state.h"
|
| #include "components/sessions/core/serialized_navigation_entry.h"
|
| #include "content/public/browser/browser_context.h"
|
| @@ -15,6 +18,37 @@
|
|
|
| namespace sessions {
|
|
|
| +namespace {
|
| +
|
| +const char kOfflinePageHeader[] = "X-Chrome-offline: ";
|
| +
|
| +// Returns the offline page info that needs to be persisted, based on extra
|
| +// headers.
|
| +// TODO(jianli): Move this logic to components/offline_pages/request.
|
| +std::string GetOfflinePageInfo(const content::NavigationEntry& entry) {
|
| + std::string extra_headers = entry.GetExtraHeaders();
|
| + if (extra_headers.empty())
|
| + return std::string();
|
| + // The offline header will be the only extra header if it is present.
|
| + if (!base::StartsWith(extra_headers,
|
| + kOfflinePageHeader,
|
| + base::CompareCase::INSENSITIVE_ASCII)) {
|
| + return std::string();
|
| + }
|
| + std::string value = extra_headers.substr(arraysize(kOfflinePageHeader) - 1);
|
| + if (value.find("\n") != std::string::npos) {
|
| + return std::string();
|
| + }
|
| + base::StringTokenizer tokenizer(value, ", ");
|
| + while (tokenizer.GetNext()) {
|
| + if (tokenizer.token() == "persist=1")
|
| + return value;
|
| + }
|
| + return std::string();
|
| +}
|
| +
|
| +} // namespace
|
| +
|
| // static
|
| SerializedNavigationEntry
|
| ContentSerializedNavigationBuilder::FromNavigationEntry(
|
| @@ -41,6 +75,7 @@ ContentSerializedNavigationBuilder::FromNavigationEntry(
|
| navigation.http_status_code_ = entry.GetHttpStatusCode();
|
| navigation.redirect_chain_ = entry.GetRedirectChain();
|
| navigation.password_state_ = GetPasswordStateFromNavigation(entry);
|
| + navigation.offline_page_info_ = GetOfflinePageInfo(entry);
|
|
|
| return navigation;
|
| }
|
| @@ -53,6 +88,11 @@ ContentSerializedNavigationBuilder::ToNavigationEntry(
|
| content::BrowserContext* browser_context) {
|
| blink::WebReferrerPolicy policy =
|
| static_cast<blink::WebReferrerPolicy>(navigation->referrer_policy_);
|
| + // The extra headers, except the one used for offline page support, are not
|
| + // sync'ed across sessions.
|
| + std::string extra_headers;
|
| + if (!navigation->offline_page_info_.empty())
|
| + extra_headers = kOfflinePageHeader + navigation->offline_page_info_;
|
| std::unique_ptr<content::NavigationEntry> entry(
|
| content::NavigationController::CreateNavigationEntry(
|
| navigation->virtual_url_,
|
| @@ -62,8 +102,7 @@ ContentSerializedNavigationBuilder::ToNavigationEntry(
|
| // Use a transition type of reload so that we don't incorrectly
|
| // increase the typed count.
|
| ui::PAGE_TRANSITION_RELOAD, false,
|
| - // The extra headers are not sync'ed across sessions.
|
| - std::string(), browser_context));
|
| + extra_headers, browser_context));
|
|
|
| entry->SetTitle(navigation->title_);
|
| entry->SetPageState(content::PageState::CreateFromEncodedData(
|
|
|