Lazily build the app list model.
[chromium-blink-merge.git] / components / sessions / content / content_serialized_navigation_builder.cc
bloba033c64a4e5bc6315c02b75107861899ea8a3183
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
3 // found in the LICENSE file.
5 #include "components/sessions/content/content_serialized_navigation_builder.h"
7 #include "components/sessions/serialized_navigation_entry.h"
8 #include "content/public/browser/browser_context.h"
9 #include "content/public/browser/favicon_status.h"
10 #include "content/public/browser/navigation_controller.h"
11 #include "content/public/browser/navigation_entry.h"
12 #include "content/public/common/page_state.h"
13 #include "content/public/common/referrer.h"
15 namespace sessions {
17 // static
18 SerializedNavigationEntry
19 ContentSerializedNavigationBuilder::FromNavigationEntry(
20 int index,
21 const content::NavigationEntry& entry) {
22 SerializedNavigationEntry navigation;
23 navigation.index_ = index;
24 navigation.unique_id_ = entry.GetUniqueID();
25 navigation.referrer_url_ = entry.GetReferrer().url;
26 navigation.referrer_policy_ = entry.GetReferrer().policy;
27 navigation.virtual_url_ = entry.GetVirtualURL();
28 navigation.title_ = entry.GetTitle();
29 navigation.encoded_page_state_ = entry.GetPageState().ToEncodedData();
30 navigation.transition_type_ = entry.GetTransitionType();
31 navigation.has_post_data_ = entry.GetHasPostData();
32 navigation.post_id_ = entry.GetPostID();
33 navigation.original_request_url_ = entry.GetOriginalRequestURL();
34 navigation.is_overriding_user_agent_ = entry.GetIsOverridingUserAgent();
35 navigation.timestamp_ = entry.GetTimestamp();
36 navigation.is_restored_ = entry.IsRestored();
37 // If you want to navigate a named frame in Chrome, you will first need to
38 // add support for persisting it. It is currently only used for layout tests.
39 CHECK(entry.GetFrameToNavigate().empty());
40 entry.GetExtraData(kSearchTermsKey, &navigation.search_terms_);
41 if (entry.GetFavicon().valid)
42 navigation.favicon_url_ = entry.GetFavicon().url;
43 navigation.http_status_code_ = entry.GetHttpStatusCode();
44 navigation.redirect_chain_ = entry.GetRedirectChain();
46 return navigation;
49 // static
50 scoped_ptr<content::NavigationEntry>
51 ContentSerializedNavigationBuilder::ToNavigationEntry(
52 const SerializedNavigationEntry* navigation,
53 int page_id,
54 content::BrowserContext* browser_context) {
55 blink::WebReferrerPolicy policy =
56 static_cast<blink::WebReferrerPolicy>(navigation->referrer_policy_);
57 scoped_ptr<content::NavigationEntry> entry(
58 content::NavigationController::CreateNavigationEntry(
59 navigation->virtual_url_,
60 content::Referrer::SanitizeForRequest(
61 navigation->virtual_url_,
62 content::Referrer(navigation->referrer_url_, policy)),
63 // Use a transition type of reload so that we don't incorrectly
64 // increase the typed count.
65 ui::PAGE_TRANSITION_RELOAD, false,
66 // The extra headers are not sync'ed across sessions.
67 std::string(), browser_context));
69 entry->SetTitle(navigation->title_);
70 entry->SetPageState(content::PageState::CreateFromEncodedData(
71 navigation->encoded_page_state_));
72 entry->SetPageID(page_id);
73 entry->SetHasPostData(navigation->has_post_data_);
74 entry->SetPostID(navigation->post_id_);
75 entry->SetOriginalRequestURL(navigation->original_request_url_);
76 entry->SetIsOverridingUserAgent(navigation->is_overriding_user_agent_);
77 entry->SetTimestamp(navigation->timestamp_);
78 entry->SetExtraData(kSearchTermsKey, navigation->search_terms_);
79 entry->SetHttpStatusCode(navigation->http_status_code_);
80 entry->SetRedirectChain(navigation->redirect_chain_);
82 // These fields should have default values.
83 DCHECK_EQ(SerializedNavigationEntry::STATE_INVALID,
84 navigation->blocked_state_);
85 DCHECK_EQ(0u, navigation->content_pack_categories_.size());
87 return entry.Pass();
90 // static
91 ScopedVector<content::NavigationEntry>
92 ContentSerializedNavigationBuilder::ToNavigationEntries(
93 const std::vector<SerializedNavigationEntry>& navigations,
94 content::BrowserContext* browser_context) {
95 int page_id = 0;
96 ScopedVector<content::NavigationEntry> entries;
97 for (std::vector<SerializedNavigationEntry>::const_iterator
98 it = navigations.begin(); it != navigations.end(); ++it) {
99 entries.push_back(
100 ToNavigationEntry(&(*it), page_id, browser_context).release());
101 ++page_id;
103 return entries.Pass();
106 } // namespace sessions