Don't preload rarely seen large images
[chromium-blink-merge.git] / components / sessions / content / content_serialized_navigation_builder.cc
blobb097769bf3e8f7d0b019d1bb7e06ca57bd244da3
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 entry.GetExtraData(kSearchTermsKey, &navigation.search_terms_);
38 if (entry.GetFavicon().valid)
39 navigation.favicon_url_ = entry.GetFavicon().url;
40 navigation.http_status_code_ = entry.GetHttpStatusCode();
41 navigation.redirect_chain_ = entry.GetRedirectChain();
43 return navigation;
46 // static
47 scoped_ptr<content::NavigationEntry>
48 ContentSerializedNavigationBuilder::ToNavigationEntry(
49 const SerializedNavigationEntry* navigation,
50 int page_id,
51 content::BrowserContext* browser_context) {
52 blink::WebReferrerPolicy policy =
53 static_cast<blink::WebReferrerPolicy>(navigation->referrer_policy_);
54 scoped_ptr<content::NavigationEntry> entry(
55 content::NavigationController::CreateNavigationEntry(
56 navigation->virtual_url_,
57 content::Referrer::SanitizeForRequest(
58 navigation->virtual_url_,
59 content::Referrer(navigation->referrer_url_, policy)),
60 // Use a transition type of reload so that we don't incorrectly
61 // increase the typed count.
62 ui::PAGE_TRANSITION_RELOAD, false,
63 // The extra headers are not sync'ed across sessions.
64 std::string(), browser_context));
66 entry->SetTitle(navigation->title_);
67 entry->SetPageState(content::PageState::CreateFromEncodedData(
68 navigation->encoded_page_state_));
69 entry->SetPageID(page_id);
70 entry->SetHasPostData(navigation->has_post_data_);
71 entry->SetPostID(navigation->post_id_);
72 entry->SetOriginalRequestURL(navigation->original_request_url_);
73 entry->SetIsOverridingUserAgent(navigation->is_overriding_user_agent_);
74 entry->SetTimestamp(navigation->timestamp_);
75 entry->SetExtraData(kSearchTermsKey, navigation->search_terms_);
76 entry->SetHttpStatusCode(navigation->http_status_code_);
77 entry->SetRedirectChain(navigation->redirect_chain_);
79 // These fields should have default values.
80 DCHECK_EQ(SerializedNavigationEntry::STATE_INVALID,
81 navigation->blocked_state_);
82 DCHECK_EQ(0u, navigation->content_pack_categories_.size());
84 return entry.Pass();
87 // static
88 ScopedVector<content::NavigationEntry>
89 ContentSerializedNavigationBuilder::ToNavigationEntries(
90 const std::vector<SerializedNavigationEntry>& navigations,
91 content::BrowserContext* browser_context) {
92 int page_id = 0;
93 ScopedVector<content::NavigationEntry> entries;
94 for (std::vector<SerializedNavigationEntry>::const_iterator
95 it = navigations.begin(); it != navigations.end(); ++it) {
96 entries.push_back(
97 ToNavigationEntry(&(*it), page_id, browser_context).release());
98 ++page_id;
100 return entries.Pass();
103 } // namespace sessions