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

Side by Side Diff: chrome/browser/android/offline_pages/offline_page_info_handler.cc

Issue 2310363002: Persist offline page info in a navigation entry if needed (Closed)
Patch Set: Add extended info support Created 4 years, 2 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "chrome/browser/android/offline_pages/offline_page_info_handler.h"
6
7 #include "base/strings/string_util.h"
8 #include "components/offline_pages/request_header/offline_page_header.h"
9 #include "content/public/browser/navigation_entry.h"
10
11 namespace offline_pages {
12
13 namespace {
14 const char kOfflinePageInfoKey[] = "offline";
15 }
16
17 // static
18 void OfflinePageInfoHandler::Register() {
19 std::unique_ptr<OfflinePageInfoHandler> instance(new OfflinePageInfoHandler);
20 sessions::SerializedNavigationDriver::Get()->RegisterExtendedInfoHandler(
21 kOfflinePageInfoKey, std::move(instance));
22 }
23
24 OfflinePageInfoHandler::OfflinePageInfoHandler() {}
25
26 OfflinePageInfoHandler::~OfflinePageInfoHandler() {}
27
28 std::string OfflinePageInfoHandler::GetExtendedInfo(
29 const content::NavigationEntry& entry) const {
30 std::string extra_headers = entry.GetExtraHeaders();
31 if (extra_headers.empty())
32 return std::string();
33
34 // The offline header will be the only extra header if it is present.
35 std::string offline_header_key(offline_pages::kOfflinePageHeader);
36 offline_header_key += ": ";
37 if (!base::StartsWith(extra_headers,
38 offline_header_key,
39 base::CompareCase::INSENSITIVE_ASCII)) {
40 return std::string();
41 }
42 std::string header_value = extra_headers.substr(offline_header_key.length());
43 if (header_value.find("\n") != std::string::npos)
44 return std::string();
45
46 OfflinePageHeader header(header_value);
47 if (!header.need_to_persist)
48 return std::string();
49
50 return header_value;
51 }
52
53 void OfflinePageInfoHandler::RestoreExtendedInfo(
54 const std::string& info, content::NavigationEntry* entry) {
55 OfflinePageHeader header(info);
56 // Some sanity check.
57 if (header.reason == OfflinePageHeader::Reason::NONE ||
58 !header.need_to_persist)
59 return;
60 entry->AddExtraHeaders(header.GetCompleteHeaderString());
61 }
62
63 } // namespace offline_pages
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698