blob: 58dbaf46f5405153b6cd18abf5ed369ef31e66eb [file] [log] [blame]
[email protected]d4a8ca482013-10-30 21:06:401// Copyright 2013 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]d4a8ca482013-10-30 21:06:405#include "content/browser/frame_host/navigation_entry_impl.h"
[email protected]10f417c52011-12-28 21:04:236
[email protected]ce137a262013-02-11 18:40:077#include "base/metrics/histogram.h"
[email protected]348fbaac2013-06-11 06:31:518#include "base/strings/string_util.h"
[email protected]74ebfb12013-06-07 20:48:009#include "base/strings/utf_string_conversions.h"
[email protected]10f417c52011-12-28 21:04:2310#include "content/public/common/content_constants.h"
11#include "content/public/common/url_constants.h"
12#include "net/base/net_util.h"
[email protected]dbb97ba2013-09-09 22:15:2513#include "ui/gfx/text_elider.h"
[email protected]10f417c52011-12-28 21:04:2314
15// Use this to get a new unique ID for a NavigationEntry during construction.
16// The returned ID is guaranteed to be nonzero (which is the "no ID" indicator).
17static int GetUniqueIDInConstructor() {
18 static int unique_id_counter = 0;
19 return ++unique_id_counter;
20}
21
22namespace content {
23
[email protected]b26de072013-02-23 02:33:4424int NavigationEntryImpl::kInvalidBindings = -1;
25
[email protected]10f417c52011-12-28 21:04:2326NavigationEntry* NavigationEntry::Create() {
27 return new NavigationEntryImpl();
28}
29
30NavigationEntry* NavigationEntry::Create(const NavigationEntry& copy) {
31 return new NavigationEntryImpl(static_cast<const NavigationEntryImpl&>(copy));
32}
33
34NavigationEntryImpl* NavigationEntryImpl::FromNavigationEntry(
35 NavigationEntry* entry) {
36 return static_cast<NavigationEntryImpl*>(entry);
37}
38
39NavigationEntryImpl::NavigationEntryImpl()
40 : unique_id_(GetUniqueIDInConstructor()),
41 site_instance_(NULL),
[email protected]b26de072013-02-23 02:33:4442 bindings_(kInvalidBindings),
[email protected]10f417c52011-12-28 21:04:2343 page_type_(PAGE_TYPE_NORMAL),
44 update_virtual_url_with_url_(false),
45 page_id_(-1),
46 transition_type_(PAGE_TRANSITION_LINK),
47 has_post_data_(false),
[email protected]86cd9472012-02-03 19:51:0548 post_id_(-1),
[email protected]10f417c52011-12-28 21:04:2349 restore_type_(RESTORE_NONE),
[email protected]86ef6a392012-05-11 22:03:1150 is_overriding_user_agent_(false),
[email protected]f49737b32013-08-28 07:51:4451 http_status_code_(0),
[email protected]bcd904482012-02-01 01:54:2252 is_renderer_initiated_(false),
[email protected]e2caa032012-11-15 23:29:1853 should_replace_entry_(false),
[email protected]60d6cca2013-04-30 08:47:1354 should_clear_history_list_(false),
[email protected]951a64832012-10-11 16:26:3755 can_load_local_resources_(false) {
[email protected]10f417c52011-12-28 21:04:2356}
57
[email protected]b6583592012-01-25 19:52:3358NavigationEntryImpl::NavigationEntryImpl(SiteInstanceImpl* instance,
[email protected]10f417c52011-12-28 21:04:2359 int page_id,
60 const GURL& url,
61 const Referrer& referrer,
62 const string16& title,
63 PageTransition transition_type,
64 bool is_renderer_initiated)
65 : unique_id_(GetUniqueIDInConstructor()),
66 site_instance_(instance),
[email protected]b26de072013-02-23 02:33:4467 bindings_(kInvalidBindings),
[email protected]10f417c52011-12-28 21:04:2368 page_type_(PAGE_TYPE_NORMAL),
69 url_(url),
70 referrer_(referrer),
71 update_virtual_url_with_url_(false),
72 title_(title),
73 page_id_(page_id),
74 transition_type_(transition_type),
75 has_post_data_(false),
[email protected]86cd9472012-02-03 19:51:0576 post_id_(-1),
[email protected]10f417c52011-12-28 21:04:2377 restore_type_(RESTORE_NONE),
[email protected]86ef6a392012-05-11 22:03:1178 is_overriding_user_agent_(false),
[email protected]f49737b32013-08-28 07:51:4479 http_status_code_(0),
[email protected]bcd904482012-02-01 01:54:2280 is_renderer_initiated_(is_renderer_initiated),
[email protected]e2caa032012-11-15 23:29:1881 should_replace_entry_(false),
[email protected]60d6cca2013-04-30 08:47:1382 should_clear_history_list_(false),
[email protected]e38019e82012-10-19 01:31:2283 can_load_local_resources_(false) {
[email protected]10f417c52011-12-28 21:04:2384}
85
86NavigationEntryImpl::~NavigationEntryImpl() {
87}
88
89int NavigationEntryImpl::GetUniqueID() const {
90 return unique_id_;
91}
92
93PageType NavigationEntryImpl::GetPageType() const {
94 return page_type_;
95}
96
97void NavigationEntryImpl::SetURL(const GURL& url) {
98 url_ = url;
99 cached_display_title_.clear();
100}
101
102const GURL& NavigationEntryImpl::GetURL() const {
103 return url_;
104}
105
[email protected]d1ef81d2012-07-24 11:39:36106void NavigationEntryImpl::SetBaseURLForDataURL(const GURL& url) {
107 base_url_for_data_url_ = url;
108}
109
110const GURL& NavigationEntryImpl::GetBaseURLForDataURL() const {
111 return base_url_for_data_url_;
112}
113
[email protected]10f417c52011-12-28 21:04:23114void NavigationEntryImpl::SetReferrer(const Referrer& referrer) {
115 referrer_ = referrer;
116}
117
118const Referrer& NavigationEntryImpl::GetReferrer() const {
119 return referrer_;
120}
121
122void NavigationEntryImpl::SetVirtualURL(const GURL& url) {
123 virtual_url_ = (url == url_) ? GURL() : url;
124 cached_display_title_.clear();
125}
126
127const GURL& NavigationEntryImpl::GetVirtualURL() const {
128 return virtual_url_.is_empty() ? url_ : virtual_url_;
129}
130
131void NavigationEntryImpl::SetTitle(const string16& title) {
132 title_ = title;
133 cached_display_title_.clear();
134}
135
136const string16& NavigationEntryImpl::GetTitle() const {
137 return title_;
138}
139
[email protected]691aa2f2013-05-28 22:52:04140void NavigationEntryImpl::SetPageState(const PageState& state) {
141 page_state_ = state;
[email protected]10f417c52011-12-28 21:04:23142}
143
[email protected]691aa2f2013-05-28 22:52:04144const PageState& NavigationEntryImpl::GetPageState() const {
145 return page_state_;
[email protected]10f417c52011-12-28 21:04:23146}
147
148void NavigationEntryImpl::SetPageID(int page_id) {
149 page_id_ = page_id;
150}
151
152int32 NavigationEntryImpl::GetPageID() const {
153 return page_id_;
154}
155
[email protected]b6583592012-01-25 19:52:33156void NavigationEntryImpl::set_site_instance(SiteInstanceImpl* site_instance) {
[email protected]10f417c52011-12-28 21:04:23157 site_instance_ = site_instance;
158}
159
[email protected]b26de072013-02-23 02:33:44160void NavigationEntryImpl::SetBindings(int bindings) {
161 // Ensure this is set to a valid value, and that it stays the same once set.
162 CHECK_NE(bindings, kInvalidBindings);
163 CHECK(bindings_ == kInvalidBindings || bindings_ == bindings);
164 bindings_ = bindings;
165}
166
[email protected]10f417c52011-12-28 21:04:23167const string16& NavigationEntryImpl::GetTitleForDisplay(
168 const std::string& languages) const {
169 // Most pages have real titles. Don't even bother caching anything if this is
170 // the case.
171 if (!title_.empty())
172 return title_;
173
174 // More complicated cases will use the URLs as the title. This result we will
175 // cache since it's more complicated to compute.
176 if (!cached_display_title_.empty())
177 return cached_display_title_;
178
179 // Use the virtual URL first if any, and fall back on using the real URL.
180 string16 title;
181 if (!virtual_url_.is_empty()) {
182 title = net::FormatUrl(virtual_url_, languages);
183 } else if (!url_.is_empty()) {
184 title = net::FormatUrl(url_, languages);
185 }
186
187 // For file:// URLs use the filename as the title, not the full path.
188 if (url_.SchemeIsFile()) {
189 string16::size_type slashpos = title.rfind('/');
190 if (slashpos != string16::npos)
191 title = title.substr(slashpos + 1);
192 }
193
[email protected]dbb97ba2013-09-09 22:15:25194 gfx::ElideString(title, kMaxTitleChars, &cached_display_title_);
[email protected]10f417c52011-12-28 21:04:23195 return cached_display_title_;
196}
197
198bool NavigationEntryImpl::IsViewSourceMode() const {
[email protected]dbdda5402013-05-30 22:13:48199 return virtual_url_.SchemeIs(kViewSourceScheme);
[email protected]10f417c52011-12-28 21:04:23200}
201
202void NavigationEntryImpl::SetTransitionType(
203 PageTransition transition_type) {
204 transition_type_ = transition_type;
205}
206
207PageTransition NavigationEntryImpl::GetTransitionType() const {
208 return transition_type_;
209}
210
211const GURL& NavigationEntryImpl::GetUserTypedURL() const {
212 return user_typed_url_;
213}
214
215void NavigationEntryImpl::SetHasPostData(bool has_post_data) {
216 has_post_data_ = has_post_data;
217}
218
219bool NavigationEntryImpl::GetHasPostData() const {
220 return has_post_data_;
221}
222
[email protected]86cd9472012-02-03 19:51:05223void NavigationEntryImpl::SetPostID(int64 post_id) {
224 post_id_ = post_id;
225}
226
227int64 NavigationEntryImpl::GetPostID() const {
228 return post_id_;
229}
230
[email protected]132e281a2012-07-31 18:32:44231void NavigationEntryImpl::SetBrowserInitiatedPostData(
232 const base::RefCountedMemory* data) {
233 browser_initiated_post_data_ = data;
234}
235
236const base::RefCountedMemory*
237NavigationEntryImpl::GetBrowserInitiatedPostData() const {
238 return browser_initiated_post_data_.get();
239}
240
241
[email protected]10f417c52011-12-28 21:04:23242const FaviconStatus& NavigationEntryImpl::GetFavicon() const {
243 return favicon_;
244}
245
246FaviconStatus& NavigationEntryImpl::GetFavicon() {
247 return favicon_;
248}
249
250const SSLStatus& NavigationEntryImpl::GetSSL() const {
251 return ssl_;
252}
253
254SSLStatus& NavigationEntryImpl::GetSSL() {
255 return ssl_;
256}
257
[email protected]074269f2012-04-17 21:12:42258void NavigationEntryImpl::SetOriginalRequestURL(const GURL& original_url) {
259 original_request_url_ = original_url;
260}
261
262const GURL& NavigationEntryImpl::GetOriginalRequestURL() const {
263 return original_request_url_;
264}
265
[email protected]86ef6a392012-05-11 22:03:11266void NavigationEntryImpl::SetIsOverridingUserAgent(bool override) {
267 is_overriding_user_agent_ = override;
268}
269
270bool NavigationEntryImpl::GetIsOverridingUserAgent() const {
271 return is_overriding_user_agent_;
272}
273
[email protected]688aa65c62012-09-28 04:32:22274void NavigationEntryImpl::SetTimestamp(base::Time timestamp) {
275 timestamp_ = timestamp;
276}
277
278base::Time NavigationEntryImpl::GetTimestamp() const {
279 return timestamp_;
280}
281
[email protected]f49737b32013-08-28 07:51:44282void NavigationEntryImpl::SetHttpStatusCode(int http_status_code) {
283 http_status_code_ = http_status_code;
284}
285
286int NavigationEntryImpl::GetHttpStatusCode() const {
287 return http_status_code_;
288}
289
[email protected]951a64832012-10-11 16:26:37290void NavigationEntryImpl::SetCanLoadLocalResources(bool allow) {
291 can_load_local_resources_ = allow;
292}
293
294bool NavigationEntryImpl::GetCanLoadLocalResources() const {
295 return can_load_local_resources_;
296}
297
[email protected]3027cf02013-01-24 08:16:58298void NavigationEntryImpl::SetFrameToNavigate(const std::string& frame_name) {
299 frame_to_navigate_ = frame_name;
300}
301
302const std::string& NavigationEntryImpl::GetFrameToNavigate() const {
303 return frame_to_navigate_;
304}
305
[email protected]261cf892013-02-01 00:42:36306void NavigationEntryImpl::SetExtraData(const std::string& key,
307 const string16& data) {
308 extra_data_[key] = data;
309}
310
311bool NavigationEntryImpl::GetExtraData(const std::string& key,
312 string16* data) const {
313 std::map<std::string, string16>::const_iterator iter = extra_data_.find(key);
314 if (iter == extra_data_.end())
315 return false;
316 *data = iter->second;
317 return true;
318}
319
320void NavigationEntryImpl::ClearExtraData(const std::string& key) {
321 extra_data_.erase(key);
322}
323
[email protected]97d8f0d2013-10-29 16:49:21324void NavigationEntryImpl::ResetForCommit() {
325 // Any state that only matters when a navigation entry is pending should be
326 // cleared here.
327 SetBrowserInitiatedPostData(NULL);
328 set_is_renderer_initiated(false);
329 set_transferred_global_request_id(GlobalRequestID());
330 set_should_replace_entry(false);
[email protected]f8872902013-10-30 03:18:57331 redirect_chain_.clear();
[email protected]97d8f0d2013-10-29 16:49:21332 set_should_clear_history_list(false);
333}
334
[email protected]9677a3c2012-12-22 04:18:58335void NavigationEntryImpl::SetScreenshotPNGData(
[email protected]e6961e72013-04-27 02:06:32336 scoped_refptr<base::RefCountedBytes> png_data) {
337 screenshot_ = png_data;
[email protected]fc72bb12013-06-02 21:13:46338 if (screenshot_.get())
[email protected]ce137a262013-02-11 18:40:07339 UMA_HISTOGRAM_MEMORY_KB("Overscroll.ScreenshotSize", screenshot_->size());
[email protected]9677a3c2012-12-22 04:18:58340}
341
[email protected]10f417c52011-12-28 21:04:23342} // namespace content