| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2012 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. | |
| 4 | |
| 5 #include "content/browser/tab_contents/navigation_entry_impl.h" | |
| 6 | |
| 7 #include "base/string_util.h" | |
| 8 #include "base/utf_string_conversions.h" | |
| 9 #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 | |
| 14 using content::SiteInstance; | |
| 15 | |
| 16 // 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). | |
| 18 static int GetUniqueIDInConstructor() { | |
| 19 static int unique_id_counter = 0; | |
| 20 return ++unique_id_counter; | |
| 21 } | |
| 22 | |
| 23 namespace content { | |
| 24 | |
| 25 NavigationEntry* NavigationEntry::Create() { | |
| 26 return new NavigationEntryImpl(); | |
| 27 } | |
| 28 | |
| 29 NavigationEntry* NavigationEntry::Create(const NavigationEntry& copy) { | |
| 30 return new NavigationEntryImpl(static_cast<const NavigationEntryImpl&>(copy)); | |
| 31 } | |
| 32 | |
| 33 NavigationEntryImpl* NavigationEntryImpl::FromNavigationEntry( | |
| 34 NavigationEntry* entry) { | |
| 35 return static_cast<NavigationEntryImpl*>(entry); | |
| 36 } | |
| 37 | |
| 38 NavigationEntryImpl::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), | |
| 46 post_id_(-1), | |
| 47 restore_type_(RESTORE_NONE), | |
| 48 is_renderer_initiated_(false), | |
| 49 is_cross_site_reload_(false) { | |
| 50 } | |
| 51 | |
| 52 NavigationEntryImpl::NavigationEntryImpl(SiteInstanceImpl* instance, | |
| 53 int page_id, | |
| 54 const GURL& url, | |
| 55 const Referrer& referrer, | |
| 56 const string16& title, | |
| 57 PageTransition transition_type, | |
| 58 bool is_renderer_initiated) | |
| 59 : unique_id_(GetUniqueIDInConstructor()), | |
| 60 site_instance_(instance), | |
| 61 page_type_(PAGE_TYPE_NORMAL), | |
| 62 url_(url), | |
| 63 referrer_(referrer), | |
| 64 update_virtual_url_with_url_(false), | |
| 65 title_(title), | |
| 66 page_id_(page_id), | |
| 67 transition_type_(transition_type), | |
| 68 has_post_data_(false), | |
| 69 post_id_(-1), | |
| 70 restore_type_(RESTORE_NONE), | |
| 71 is_renderer_initiated_(is_renderer_initiated), | |
| 72 is_cross_site_reload_(false) { | |
| 73 } | |
| 74 | |
| 75 NavigationEntryImpl::~NavigationEntryImpl() { | |
| 76 } | |
| 77 | |
| 78 int NavigationEntryImpl::GetUniqueID() const { | |
| 79 return unique_id_; | |
| 80 } | |
| 81 | |
| 82 PageType NavigationEntryImpl::GetPageType() const { | |
| 83 return page_type_; | |
| 84 } | |
| 85 | |
| 86 void NavigationEntryImpl::SetURL(const GURL& url) { | |
| 87 url_ = url; | |
| 88 cached_display_title_.clear(); | |
| 89 } | |
| 90 | |
| 91 const GURL& NavigationEntryImpl::GetURL() const { | |
| 92 return url_; | |
| 93 } | |
| 94 | |
| 95 void NavigationEntryImpl::SetReferrer(const Referrer& referrer) { | |
| 96 referrer_ = referrer; | |
| 97 } | |
| 98 | |
| 99 const Referrer& NavigationEntryImpl::GetReferrer() const { | |
| 100 return referrer_; | |
| 101 } | |
| 102 | |
| 103 void NavigationEntryImpl::SetVirtualURL(const GURL& url) { | |
| 104 virtual_url_ = (url == url_) ? GURL() : url; | |
| 105 cached_display_title_.clear(); | |
| 106 } | |
| 107 | |
| 108 const GURL& NavigationEntryImpl::GetVirtualURL() const { | |
| 109 return virtual_url_.is_empty() ? url_ : virtual_url_; | |
| 110 } | |
| 111 | |
| 112 void NavigationEntryImpl::SetTitle(const string16& title) { | |
| 113 title_ = title; | |
| 114 cached_display_title_.clear(); | |
| 115 } | |
| 116 | |
| 117 const string16& NavigationEntryImpl::GetTitle() const { | |
| 118 return title_; | |
| 119 } | |
| 120 | |
| 121 void NavigationEntryImpl::SetContentState(const std::string& state) { | |
| 122 content_state_ = state; | |
| 123 } | |
| 124 | |
| 125 const std::string& NavigationEntryImpl::GetContentState() const { | |
| 126 return content_state_; | |
| 127 } | |
| 128 | |
| 129 void NavigationEntryImpl::SetPageID(int page_id) { | |
| 130 page_id_ = page_id; | |
| 131 } | |
| 132 | |
| 133 int32 NavigationEntryImpl::GetPageID() const { | |
| 134 return page_id_; | |
| 135 } | |
| 136 | |
| 137 void NavigationEntryImpl::set_site_instance(SiteInstanceImpl* site_instance) { | |
| 138 site_instance_ = site_instance; | |
| 139 } | |
| 140 | |
| 141 const string16& NavigationEntryImpl::GetTitleForDisplay( | |
| 142 const std::string& languages) const { | |
| 143 // Most pages have real titles. Don't even bother caching anything if this is | |
| 144 // the case. | |
| 145 if (!title_.empty()) | |
| 146 return title_; | |
| 147 | |
| 148 // More complicated cases will use the URLs as the title. This result we will | |
| 149 // cache since it's more complicated to compute. | |
| 150 if (!cached_display_title_.empty()) | |
| 151 return cached_display_title_; | |
| 152 | |
| 153 // Use the virtual URL first if any, and fall back on using the real URL. | |
| 154 string16 title; | |
| 155 if (!virtual_url_.is_empty()) { | |
| 156 title = net::FormatUrl(virtual_url_, languages); | |
| 157 } else if (!url_.is_empty()) { | |
| 158 title = net::FormatUrl(url_, languages); | |
| 159 } | |
| 160 | |
| 161 // For file:// URLs use the filename as the title, not the full path. | |
| 162 if (url_.SchemeIsFile()) { | |
| 163 string16::size_type slashpos = title.rfind('/'); | |
| 164 if (slashpos != string16::npos) | |
| 165 title = title.substr(slashpos + 1); | |
| 166 } | |
| 167 | |
| 168 ui::ElideString(title, kMaxTitleChars, &cached_display_title_); | |
| 169 return cached_display_title_; | |
| 170 } | |
| 171 | |
| 172 bool NavigationEntryImpl::IsViewSourceMode() const { | |
| 173 return virtual_url_.SchemeIs(chrome::kViewSourceScheme); | |
| 174 } | |
| 175 | |
| 176 void NavigationEntryImpl::SetTransitionType( | |
| 177 PageTransition transition_type) { | |
| 178 transition_type_ = transition_type; | |
| 179 } | |
| 180 | |
| 181 PageTransition NavigationEntryImpl::GetTransitionType() const { | |
| 182 return transition_type_; | |
| 183 } | |
| 184 | |
| 185 const GURL& NavigationEntryImpl::GetUserTypedURL() const { | |
| 186 return user_typed_url_; | |
| 187 } | |
| 188 | |
| 189 void NavigationEntryImpl::SetHasPostData(bool has_post_data) { | |
| 190 has_post_data_ = has_post_data; | |
| 191 } | |
| 192 | |
| 193 bool NavigationEntryImpl::GetHasPostData() const { | |
| 194 return has_post_data_; | |
| 195 } | |
| 196 | |
| 197 void NavigationEntryImpl::SetPostID(int64 post_id) { | |
| 198 post_id_ = post_id; | |
| 199 } | |
| 200 | |
| 201 int64 NavigationEntryImpl::GetPostID() const { | |
| 202 return post_id_; | |
| 203 } | |
| 204 | |
| 205 const FaviconStatus& NavigationEntryImpl::GetFavicon() const { | |
| 206 return favicon_; | |
| 207 } | |
| 208 | |
| 209 FaviconStatus& NavigationEntryImpl::GetFavicon() { | |
| 210 return favicon_; | |
| 211 } | |
| 212 | |
| 213 const SSLStatus& NavigationEntryImpl::GetSSL() const { | |
| 214 return ssl_; | |
| 215 } | |
| 216 | |
| 217 SSLStatus& NavigationEntryImpl::GetSSL() { | |
| 218 return ssl_; | |
| 219 } | |
| 220 | |
| 221 } // namespace content | |
| OLD | NEW |