Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(248)

Unified Diff: components/sessions/content/content_serialized_navigation_builder.cc

Issue 2310363002: Persist offline page info in a navigation entry if needed (Closed)
Patch Set: Address feedback Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..77e38dfff9ba2faa489b834fc67ad666ba97d120 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,34 @@
namespace sessions {
+namespace {
+
+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
+
+// 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.
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
+ if (!base::StartsWith(extra_headers,
+ kOfflinePageHeader,
+ base::CompareCase::INSENSITIVE_ASCII)) {
+ return std::string();
+ }
+ std::string value = extra_headers.substr(arraysize(kOfflinePageHeader) - 1);
+ base::StringTokenizer tokenizer(value, ", ");
+ while (tokenizer.GetNext()) {
+ if (tokenizer.token() == "persist=1")
+ return value;
+ }
+ return std::string();
+}
+
+} // namespace
+
// static
SerializedNavigationEntry
ContentSerializedNavigationBuilder::FromNavigationEntry(
@@ -41,6 +72,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 +85,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 +99,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(

Powered by Google App Engine
This is Rietveld 408576698