blob: 8c8bbbb5c96019f60e8aa143a22e599baad0e831 [file] [log] [blame]
[email protected]bcd904482012-02-01 01:54:221// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]10f417c52011-12-28 21:04:232// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]f9e4dae2012-04-10 21:26:375#include "content/browser/web_contents/navigation_entry_impl.h"
[email protected]10f417c52011-12-28 21:04:236
7#include "base/string_util.h"
8#include "base/utf_string_conversions.h"
[email protected]10f417c52011-12-28 21:04:239#include "content/public/common/content_constants.h"
10#include "content/public/common/url_constants.h"
11#include "net/base/net_util.h"
12#include "ui/base/text/text_elider.h"
13
[email protected]b6583592012-01-25 19:52:3314using content::SiteInstance;
15
[email protected]10f417c52011-12-28 21:04:2316// Use this to get a new unique ID for a NavigationEntry during construction.
17// The returned ID is guaranteed to be nonzero (which is the "no ID" indicator).
18static int GetUniqueIDInConstructor() {
19 static int unique_id_counter = 0;
20 return ++unique_id_counter;
21}
22
23namespace content {
24
25NavigationEntry* NavigationEntry::Create() {
26 return new NavigationEntryImpl();
27}
28
29NavigationEntry* NavigationEntry::Create(const NavigationEntry& copy) {
30 return new NavigationEntryImpl(static_cast<const NavigationEntryImpl&>(copy));
31}
32
33NavigationEntryImpl* NavigationEntryImpl::FromNavigationEntry(
34 NavigationEntry* entry) {
35 return static_cast<NavigationEntryImpl*>(entry);
36}
37
38NavigationEntryImpl::NavigationEntryImpl()
39 : unique_id_(GetUniqueIDInConstructor()),
40 site_instance_(NULL),
41 page_type_(PAGE_TYPE_NORMAL),
42 update_virtual_url_with_url_(false),
43 page_id_(-1),
44 transition_type_(PAGE_TRANSITION_LINK),
45 has_post_data_(false),
[email protected]86cd9472012-02-03 19:51:0546 post_id_(-1),
[email protected]10f417c52011-12-28 21:04:2347 restore_type_(RESTORE_NONE),
[email protected]86ef6a392012-05-11 22:03:1148 is_overriding_user_agent_(false),
[email protected]bcd904482012-02-01 01:54:2249 is_renderer_initiated_(false),
50 is_cross_site_reload_(false) {
[email protected]10f417c52011-12-28 21:04:2351}
52
[email protected]b6583592012-01-25 19:52:3353NavigationEntryImpl::NavigationEntryImpl(SiteInstanceImpl* instance,
[email protected]10f417c52011-12-28 21:04:2354 int page_id,
55 const GURL& url,
56 const Referrer& referrer,
57 const string16& title,
58 PageTransition transition_type,
59 bool is_renderer_initiated)
60 : unique_id_(GetUniqueIDInConstructor()),
61 site_instance_(instance),
62 page_type_(PAGE_TYPE_NORMAL),
63 url_(url),
64 referrer_(referrer),
65 update_virtual_url_with_url_(false),
66 title_(title),
67 page_id_(page_id),
68 transition_type_(transition_type),
69 has_post_data_(false),
[email protected]86cd9472012-02-03 19:51:0570 post_id_(-1),
[email protected]10f417c52011-12-28 21:04:2371 restore_type_(RESTORE_NONE),
[email protected]86ef6a392012-05-11 22:03:1172 is_overriding_user_agent_(false),
[email protected]bcd904482012-02-01 01:54:2273 is_renderer_initiated_(is_renderer_initiated),
74 is_cross_site_reload_(false) {
[email protected]10f417c52011-12-28 21:04:2375}
76
77NavigationEntryImpl::~NavigationEntryImpl() {
78}
79
80int NavigationEntryImpl::GetUniqueID() const {
81 return unique_id_;
82}
83
84PageType NavigationEntryImpl::GetPageType() const {
85 return page_type_;
86}
87
88void NavigationEntryImpl::SetURL(const GURL& url) {
89 url_ = url;
90 cached_display_title_.clear();
91}
92
93const GURL& NavigationEntryImpl::GetURL() const {
94 return url_;
95}
96
97void NavigationEntryImpl::SetReferrer(const Referrer& referrer) {
98 referrer_ = referrer;
99}
100
101const Referrer& NavigationEntryImpl::GetReferrer() const {
102 return referrer_;
103}
104
105void NavigationEntryImpl::SetVirtualURL(const GURL& url) {
106 virtual_url_ = (url == url_) ? GURL() : url;
107 cached_display_title_.clear();
108}
109
110const GURL& NavigationEntryImpl::GetVirtualURL() const {
111 return virtual_url_.is_empty() ? url_ : virtual_url_;
112}
113
114void NavigationEntryImpl::SetTitle(const string16& title) {
115 title_ = title;
116 cached_display_title_.clear();
117}
118
119const string16& NavigationEntryImpl::GetTitle() const {
120 return title_;
121}
122
123void NavigationEntryImpl::SetContentState(const std::string& state) {
124 content_state_ = state;
125}
126
127const std::string& NavigationEntryImpl::GetContentState() const {
128 return content_state_;
129}
130
131void NavigationEntryImpl::SetPageID(int page_id) {
132 page_id_ = page_id;
133}
134
135int32 NavigationEntryImpl::GetPageID() const {
136 return page_id_;
137}
138
[email protected]b6583592012-01-25 19:52:33139void NavigationEntryImpl::set_site_instance(SiteInstanceImpl* site_instance) {
[email protected]10f417c52011-12-28 21:04:23140 site_instance_ = site_instance;
141}
142
143const string16& NavigationEntryImpl::GetTitleForDisplay(
144 const std::string& languages) const {
145 // Most pages have real titles. Don't even bother caching anything if this is
146 // the case.
147 if (!title_.empty())
148 return title_;
149
150 // More complicated cases will use the URLs as the title. This result we will
151 // cache since it's more complicated to compute.
152 if (!cached_display_title_.empty())
153 return cached_display_title_;
154
155 // Use the virtual URL first if any, and fall back on using the real URL.
156 string16 title;
157 if (!virtual_url_.is_empty()) {
158 title = net::FormatUrl(virtual_url_, languages);
159 } else if (!url_.is_empty()) {
160 title = net::FormatUrl(url_, languages);
161 }
162
163 // For file:// URLs use the filename as the title, not the full path.
164 if (url_.SchemeIsFile()) {
165 string16::size_type slashpos = title.rfind('/');
166 if (slashpos != string16::npos)
167 title = title.substr(slashpos + 1);
168 }
169
170 ui::ElideString(title, kMaxTitleChars, &cached_display_title_);
171 return cached_display_title_;
172}
173
174bool NavigationEntryImpl::IsViewSourceMode() const {
175 return virtual_url_.SchemeIs(chrome::kViewSourceScheme);
176}
177
178void NavigationEntryImpl::SetTransitionType(
179 PageTransition transition_type) {
180 transition_type_ = transition_type;
181}
182
183PageTransition NavigationEntryImpl::GetTransitionType() const {
184 return transition_type_;
185}
186
187const GURL& NavigationEntryImpl::GetUserTypedURL() const {
188 return user_typed_url_;
189}
190
191void NavigationEntryImpl::SetHasPostData(bool has_post_data) {
192 has_post_data_ = has_post_data;
193}
194
195bool NavigationEntryImpl::GetHasPostData() const {
196 return has_post_data_;
197}
198
[email protected]86cd9472012-02-03 19:51:05199void NavigationEntryImpl::SetPostID(int64 post_id) {
200 post_id_ = post_id;
201}
202
203int64 NavigationEntryImpl::GetPostID() const {
204 return post_id_;
205}
206
[email protected]10f417c52011-12-28 21:04:23207const FaviconStatus& NavigationEntryImpl::GetFavicon() const {
208 return favicon_;
209}
210
211FaviconStatus& NavigationEntryImpl::GetFavicon() {
212 return favicon_;
213}
214
215const SSLStatus& NavigationEntryImpl::GetSSL() const {
216 return ssl_;
217}
218
219SSLStatus& NavigationEntryImpl::GetSSL() {
220 return ssl_;
221}
222
[email protected]074269f2012-04-17 21:12:42223void NavigationEntryImpl::SetOriginalRequestURL(const GURL& original_url) {
224 original_request_url_ = original_url;
225}
226
227const GURL& NavigationEntryImpl::GetOriginalRequestURL() const {
228 return original_request_url_;
229}
230
[email protected]86ef6a392012-05-11 22:03:11231void NavigationEntryImpl::SetIsOverridingUserAgent(bool override) {
232 is_overriding_user_agent_ = override;
233}
234
235bool NavigationEntryImpl::GetIsOverridingUserAgent() const {
236 return is_overriding_user_agent_;
237}
238
[email protected]10f417c52011-12-28 21:04:23239} // namespace content