[email protected] | d4a8ca48 | 2013-10-30 21:06:40 | [diff] [blame^] | 1 | // Copyright 2013 The Chromium Authors. All rights reserved. |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | d4a8ca48 | 2013-10-30 21:06:40 | [diff] [blame^] | 5 | #include "content/browser/frame_host/navigation_entry_impl.h" |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 6 | |
[email protected] | ce137a26 | 2013-02-11 18:40:07 | [diff] [blame] | 7 | #include "base/metrics/histogram.h" |
[email protected] | 348fbaac | 2013-06-11 06:31:51 | [diff] [blame] | 8 | #include "base/strings/string_util.h" |
[email protected] | 74ebfb1 | 2013-06-07 20:48:00 | [diff] [blame] | 9 | #include "base/strings/utf_string_conversions.h" |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 10 | #include "content/public/common/content_constants.h" |
| 11 | #include "content/public/common/url_constants.h" |
| 12 | #include "net/base/net_util.h" |
[email protected] | dbb97ba | 2013-09-09 22:15:25 | [diff] [blame] | 13 | #include "ui/gfx/text_elider.h" |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 14 | |
| 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). |
| 17 | static int GetUniqueIDInConstructor() { |
| 18 | static int unique_id_counter = 0; |
| 19 | return ++unique_id_counter; |
| 20 | } |
| 21 | |
| 22 | namespace content { |
| 23 | |
[email protected] | b26de07 | 2013-02-23 02:33:44 | [diff] [blame] | 24 | int NavigationEntryImpl::kInvalidBindings = -1; |
| 25 | |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 26 | NavigationEntry* NavigationEntry::Create() { |
| 27 | return new NavigationEntryImpl(); |
| 28 | } |
| 29 | |
| 30 | NavigationEntry* NavigationEntry::Create(const NavigationEntry& copy) { |
| 31 | return new NavigationEntryImpl(static_cast<const NavigationEntryImpl&>(copy)); |
| 32 | } |
| 33 | |
| 34 | NavigationEntryImpl* NavigationEntryImpl::FromNavigationEntry( |
| 35 | NavigationEntry* entry) { |
| 36 | return static_cast<NavigationEntryImpl*>(entry); |
| 37 | } |
| 38 | |
| 39 | NavigationEntryImpl::NavigationEntryImpl() |
| 40 | : unique_id_(GetUniqueIDInConstructor()), |
| 41 | site_instance_(NULL), |
[email protected] | b26de07 | 2013-02-23 02:33:44 | [diff] [blame] | 42 | bindings_(kInvalidBindings), |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 43 | 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] | 86cd947 | 2012-02-03 19:51:05 | [diff] [blame] | 48 | post_id_(-1), |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 49 | restore_type_(RESTORE_NONE), |
[email protected] | 86ef6a39 | 2012-05-11 22:03:11 | [diff] [blame] | 50 | is_overriding_user_agent_(false), |
[email protected] | f49737b3 | 2013-08-28 07:51:44 | [diff] [blame] | 51 | http_status_code_(0), |
[email protected] | bcd90448 | 2012-02-01 01:54:22 | [diff] [blame] | 52 | is_renderer_initiated_(false), |
[email protected] | e2caa03 | 2012-11-15 23:29:18 | [diff] [blame] | 53 | should_replace_entry_(false), |
[email protected] | 60d6cca | 2013-04-30 08:47:13 | [diff] [blame] | 54 | should_clear_history_list_(false), |
[email protected] | 951a6483 | 2012-10-11 16:26:37 | [diff] [blame] | 55 | can_load_local_resources_(false) { |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 56 | } |
| 57 | |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 58 | NavigationEntryImpl::NavigationEntryImpl(SiteInstanceImpl* instance, |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 59 | 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] | b26de07 | 2013-02-23 02:33:44 | [diff] [blame] | 67 | bindings_(kInvalidBindings), |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 68 | 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] | 86cd947 | 2012-02-03 19:51:05 | [diff] [blame] | 76 | post_id_(-1), |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 77 | restore_type_(RESTORE_NONE), |
[email protected] | 86ef6a39 | 2012-05-11 22:03:11 | [diff] [blame] | 78 | is_overriding_user_agent_(false), |
[email protected] | f49737b3 | 2013-08-28 07:51:44 | [diff] [blame] | 79 | http_status_code_(0), |
[email protected] | bcd90448 | 2012-02-01 01:54:22 | [diff] [blame] | 80 | is_renderer_initiated_(is_renderer_initiated), |
[email protected] | e2caa03 | 2012-11-15 23:29:18 | [diff] [blame] | 81 | should_replace_entry_(false), |
[email protected] | 60d6cca | 2013-04-30 08:47:13 | [diff] [blame] | 82 | should_clear_history_list_(false), |
[email protected] | e38019e8 | 2012-10-19 01:31:22 | [diff] [blame] | 83 | can_load_local_resources_(false) { |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | NavigationEntryImpl::~NavigationEntryImpl() { |
| 87 | } |
| 88 | |
| 89 | int NavigationEntryImpl::GetUniqueID() const { |
| 90 | return unique_id_; |
| 91 | } |
| 92 | |
| 93 | PageType NavigationEntryImpl::GetPageType() const { |
| 94 | return page_type_; |
| 95 | } |
| 96 | |
| 97 | void NavigationEntryImpl::SetURL(const GURL& url) { |
| 98 | url_ = url; |
| 99 | cached_display_title_.clear(); |
| 100 | } |
| 101 | |
| 102 | const GURL& NavigationEntryImpl::GetURL() const { |
| 103 | return url_; |
| 104 | } |
| 105 | |
[email protected] | d1ef81d | 2012-07-24 11:39:36 | [diff] [blame] | 106 | void NavigationEntryImpl::SetBaseURLForDataURL(const GURL& url) { |
| 107 | base_url_for_data_url_ = url; |
| 108 | } |
| 109 | |
| 110 | const GURL& NavigationEntryImpl::GetBaseURLForDataURL() const { |
| 111 | return base_url_for_data_url_; |
| 112 | } |
| 113 | |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 114 | void NavigationEntryImpl::SetReferrer(const Referrer& referrer) { |
| 115 | referrer_ = referrer; |
| 116 | } |
| 117 | |
| 118 | const Referrer& NavigationEntryImpl::GetReferrer() const { |
| 119 | return referrer_; |
| 120 | } |
| 121 | |
| 122 | void NavigationEntryImpl::SetVirtualURL(const GURL& url) { |
| 123 | virtual_url_ = (url == url_) ? GURL() : url; |
| 124 | cached_display_title_.clear(); |
| 125 | } |
| 126 | |
| 127 | const GURL& NavigationEntryImpl::GetVirtualURL() const { |
| 128 | return virtual_url_.is_empty() ? url_ : virtual_url_; |
| 129 | } |
| 130 | |
| 131 | void NavigationEntryImpl::SetTitle(const string16& title) { |
| 132 | title_ = title; |
| 133 | cached_display_title_.clear(); |
| 134 | } |
| 135 | |
| 136 | const string16& NavigationEntryImpl::GetTitle() const { |
| 137 | return title_; |
| 138 | } |
| 139 | |
[email protected] | 691aa2f | 2013-05-28 22:52:04 | [diff] [blame] | 140 | void NavigationEntryImpl::SetPageState(const PageState& state) { |
| 141 | page_state_ = state; |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 142 | } |
| 143 | |
[email protected] | 691aa2f | 2013-05-28 22:52:04 | [diff] [blame] | 144 | const PageState& NavigationEntryImpl::GetPageState() const { |
| 145 | return page_state_; |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | void NavigationEntryImpl::SetPageID(int page_id) { |
| 149 | page_id_ = page_id; |
| 150 | } |
| 151 | |
| 152 | int32 NavigationEntryImpl::GetPageID() const { |
| 153 | return page_id_; |
| 154 | } |
| 155 | |
[email protected] | b658359 | 2012-01-25 19:52:33 | [diff] [blame] | 156 | void NavigationEntryImpl::set_site_instance(SiteInstanceImpl* site_instance) { |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 157 | site_instance_ = site_instance; |
| 158 | } |
| 159 | |
[email protected] | b26de07 | 2013-02-23 02:33:44 | [diff] [blame] | 160 | void 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] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 167 | const 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] | dbb97ba | 2013-09-09 22:15:25 | [diff] [blame] | 194 | gfx::ElideString(title, kMaxTitleChars, &cached_display_title_); |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 195 | return cached_display_title_; |
| 196 | } |
| 197 | |
| 198 | bool NavigationEntryImpl::IsViewSourceMode() const { |
[email protected] | dbdda540 | 2013-05-30 22:13:48 | [diff] [blame] | 199 | return virtual_url_.SchemeIs(kViewSourceScheme); |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | void NavigationEntryImpl::SetTransitionType( |
| 203 | PageTransition transition_type) { |
| 204 | transition_type_ = transition_type; |
| 205 | } |
| 206 | |
| 207 | PageTransition NavigationEntryImpl::GetTransitionType() const { |
| 208 | return transition_type_; |
| 209 | } |
| 210 | |
| 211 | const GURL& NavigationEntryImpl::GetUserTypedURL() const { |
| 212 | return user_typed_url_; |
| 213 | } |
| 214 | |
| 215 | void NavigationEntryImpl::SetHasPostData(bool has_post_data) { |
| 216 | has_post_data_ = has_post_data; |
| 217 | } |
| 218 | |
| 219 | bool NavigationEntryImpl::GetHasPostData() const { |
| 220 | return has_post_data_; |
| 221 | } |
| 222 | |
[email protected] | 86cd947 | 2012-02-03 19:51:05 | [diff] [blame] | 223 | void NavigationEntryImpl::SetPostID(int64 post_id) { |
| 224 | post_id_ = post_id; |
| 225 | } |
| 226 | |
| 227 | int64 NavigationEntryImpl::GetPostID() const { |
| 228 | return post_id_; |
| 229 | } |
| 230 | |
[email protected] | 132e281a | 2012-07-31 18:32:44 | [diff] [blame] | 231 | void NavigationEntryImpl::SetBrowserInitiatedPostData( |
| 232 | const base::RefCountedMemory* data) { |
| 233 | browser_initiated_post_data_ = data; |
| 234 | } |
| 235 | |
| 236 | const base::RefCountedMemory* |
| 237 | NavigationEntryImpl::GetBrowserInitiatedPostData() const { |
| 238 | return browser_initiated_post_data_.get(); |
| 239 | } |
| 240 | |
| 241 | |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 242 | const FaviconStatus& NavigationEntryImpl::GetFavicon() const { |
| 243 | return favicon_; |
| 244 | } |
| 245 | |
| 246 | FaviconStatus& NavigationEntryImpl::GetFavicon() { |
| 247 | return favicon_; |
| 248 | } |
| 249 | |
| 250 | const SSLStatus& NavigationEntryImpl::GetSSL() const { |
| 251 | return ssl_; |
| 252 | } |
| 253 | |
| 254 | SSLStatus& NavigationEntryImpl::GetSSL() { |
| 255 | return ssl_; |
| 256 | } |
| 257 | |
[email protected] | 074269f | 2012-04-17 21:12:42 | [diff] [blame] | 258 | void NavigationEntryImpl::SetOriginalRequestURL(const GURL& original_url) { |
| 259 | original_request_url_ = original_url; |
| 260 | } |
| 261 | |
| 262 | const GURL& NavigationEntryImpl::GetOriginalRequestURL() const { |
| 263 | return original_request_url_; |
| 264 | } |
| 265 | |
[email protected] | 86ef6a39 | 2012-05-11 22:03:11 | [diff] [blame] | 266 | void NavigationEntryImpl::SetIsOverridingUserAgent(bool override) { |
| 267 | is_overriding_user_agent_ = override; |
| 268 | } |
| 269 | |
| 270 | bool NavigationEntryImpl::GetIsOverridingUserAgent() const { |
| 271 | return is_overriding_user_agent_; |
| 272 | } |
| 273 | |
[email protected] | 688aa65c6 | 2012-09-28 04:32:22 | [diff] [blame] | 274 | void NavigationEntryImpl::SetTimestamp(base::Time timestamp) { |
| 275 | timestamp_ = timestamp; |
| 276 | } |
| 277 | |
| 278 | base::Time NavigationEntryImpl::GetTimestamp() const { |
| 279 | return timestamp_; |
| 280 | } |
| 281 | |
[email protected] | f49737b3 | 2013-08-28 07:51:44 | [diff] [blame] | 282 | void NavigationEntryImpl::SetHttpStatusCode(int http_status_code) { |
| 283 | http_status_code_ = http_status_code; |
| 284 | } |
| 285 | |
| 286 | int NavigationEntryImpl::GetHttpStatusCode() const { |
| 287 | return http_status_code_; |
| 288 | } |
| 289 | |
[email protected] | 951a6483 | 2012-10-11 16:26:37 | [diff] [blame] | 290 | void NavigationEntryImpl::SetCanLoadLocalResources(bool allow) { |
| 291 | can_load_local_resources_ = allow; |
| 292 | } |
| 293 | |
| 294 | bool NavigationEntryImpl::GetCanLoadLocalResources() const { |
| 295 | return can_load_local_resources_; |
| 296 | } |
| 297 | |
[email protected] | 3027cf0 | 2013-01-24 08:16:58 | [diff] [blame] | 298 | void NavigationEntryImpl::SetFrameToNavigate(const std::string& frame_name) { |
| 299 | frame_to_navigate_ = frame_name; |
| 300 | } |
| 301 | |
| 302 | const std::string& NavigationEntryImpl::GetFrameToNavigate() const { |
| 303 | return frame_to_navigate_; |
| 304 | } |
| 305 | |
[email protected] | 261cf89 | 2013-02-01 00:42:36 | [diff] [blame] | 306 | void NavigationEntryImpl::SetExtraData(const std::string& key, |
| 307 | const string16& data) { |
| 308 | extra_data_[key] = data; |
| 309 | } |
| 310 | |
| 311 | bool 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 | |
| 320 | void NavigationEntryImpl::ClearExtraData(const std::string& key) { |
| 321 | extra_data_.erase(key); |
| 322 | } |
| 323 | |
[email protected] | 97d8f0d | 2013-10-29 16:49:21 | [diff] [blame] | 324 | void 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] | f887290 | 2013-10-30 03:18:57 | [diff] [blame] | 331 | redirect_chain_.clear(); |
[email protected] | 97d8f0d | 2013-10-29 16:49:21 | [diff] [blame] | 332 | set_should_clear_history_list(false); |
| 333 | } |
| 334 | |
[email protected] | 9677a3c | 2012-12-22 04:18:58 | [diff] [blame] | 335 | void NavigationEntryImpl::SetScreenshotPNGData( |
[email protected] | e6961e7 | 2013-04-27 02:06:32 | [diff] [blame] | 336 | scoped_refptr<base::RefCountedBytes> png_data) { |
| 337 | screenshot_ = png_data; |
[email protected] | fc72bb1 | 2013-06-02 21:13:46 | [diff] [blame] | 338 | if (screenshot_.get()) |
[email protected] | ce137a26 | 2013-02-11 18:40:07 | [diff] [blame] | 339 | UMA_HISTOGRAM_MEMORY_KB("Overscroll.ScreenshotSize", screenshot_->size()); |
[email protected] | 9677a3c | 2012-12-22 04:18:58 | [diff] [blame] | 340 | } |
| 341 | |
[email protected] | 10f417c5 | 2011-12-28 21:04:23 | [diff] [blame] | 342 | } // namespace content |