OLD | NEW |
| (Empty) |
1 // Copyright (c) 2011 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.h" | |
6 | |
7 #include "base/string_util.h" | |
8 #include "base/utf_string_conversions.h" | |
9 #include "content/browser/site_instance.h" | |
10 #include "content/public/common/content_constants.h" | |
11 #include "content/public/common/url_constants.h" | |
12 #include "net/base/net_util.h" | |
13 #include "ui/base/text/text_elider.h" | |
14 | |
15 using content::FaviconStatus; | |
16 using content::SSLStatus; | |
17 | |
18 // Use this to get a new unique ID for a NavigationEntry during construction. | |
19 // The returned ID is guaranteed to be nonzero (which is the "no ID" indicator). | |
20 static int GetUniqueIDInConstructor() { | |
21 static int unique_id_counter = 0; | |
22 return ++unique_id_counter; | |
23 } | |
24 | |
25 namespace content { | |
26 | |
27 NavigationEntry* NavigationEntry::Create() { | |
28 return new ::NavigationEntry(); | |
29 } | |
30 | |
31 NavigationEntry* NavigationEntry::Create(const NavigationEntry& copy) { | |
32 return new ::NavigationEntry(static_cast<const ::NavigationEntry&>(copy)); | |
33 } | |
34 | |
35 } | |
36 | |
37 NavigationEntry* NavigationEntry::FromNavigationEntry( | |
38 content::NavigationEntry* entry) { | |
39 return static_cast<NavigationEntry*>(entry); | |
40 } | |
41 | |
42 NavigationEntry::NavigationEntry() | |
43 : unique_id_(GetUniqueIDInConstructor()), | |
44 site_instance_(NULL), | |
45 page_type_(content::PAGE_TYPE_NORMAL), | |
46 update_virtual_url_with_url_(false), | |
47 page_id_(-1), | |
48 transition_type_(content::PAGE_TRANSITION_LINK), | |
49 has_post_data_(false), | |
50 restore_type_(RESTORE_NONE), | |
51 is_renderer_initiated_(false) { | |
52 } | |
53 | |
54 NavigationEntry::NavigationEntry(SiteInstance* instance, | |
55 int page_id, | |
56 const GURL& url, | |
57 const content::Referrer& referrer, | |
58 const string16& title, | |
59 content::PageTransition transition_type, | |
60 bool is_renderer_initiated) | |
61 : unique_id_(GetUniqueIDInConstructor()), | |
62 site_instance_(instance), | |
63 page_type_(content::PAGE_TYPE_NORMAL), | |
64 url_(url), | |
65 referrer_(referrer), | |
66 update_virtual_url_with_url_(false), | |
67 title_(title), | |
68 page_id_(page_id), | |
69 transition_type_(transition_type), | |
70 has_post_data_(false), | |
71 restore_type_(RESTORE_NONE), | |
72 is_renderer_initiated_(is_renderer_initiated) { | |
73 } | |
74 | |
75 NavigationEntry::~NavigationEntry() { | |
76 } | |
77 | |
78 int NavigationEntry::GetUniqueID() const { | |
79 return unique_id_; | |
80 } | |
81 | |
82 content::PageType NavigationEntry::GetPageType() const { | |
83 return page_type_; | |
84 } | |
85 | |
86 void NavigationEntry::SetURL(const GURL& url) { | |
87 url_ = url; | |
88 cached_display_title_.clear(); | |
89 } | |
90 | |
91 const GURL& NavigationEntry::GetURL() const { | |
92 return url_; | |
93 } | |
94 | |
95 void NavigationEntry::SetReferrer(const content::Referrer& referrer) { | |
96 referrer_ = referrer; | |
97 } | |
98 | |
99 const content::Referrer& NavigationEntry::GetReferrer() const { | |
100 return referrer_; | |
101 } | |
102 | |
103 void NavigationEntry::SetVirtualURL(const GURL& url) { | |
104 virtual_url_ = (url == url_) ? GURL() : url; | |
105 cached_display_title_.clear(); | |
106 } | |
107 | |
108 const GURL& NavigationEntry::GetVirtualURL() const { | |
109 return virtual_url_.is_empty() ? url_ : virtual_url_; | |
110 } | |
111 | |
112 void NavigationEntry::SetTitle(const string16& title) { | |
113 title_ = title; | |
114 cached_display_title_.clear(); | |
115 } | |
116 | |
117 const string16& NavigationEntry::GetTitle() const { | |
118 return title_; | |
119 } | |
120 | |
121 void NavigationEntry::SetContentState(const std::string& state) { | |
122 content_state_ = state; | |
123 } | |
124 | |
125 const std::string& NavigationEntry::GetContentState() const { | |
126 return content_state_; | |
127 } | |
128 | |
129 void NavigationEntry::SetPageID(int page_id) { | |
130 page_id_ = page_id; | |
131 } | |
132 | |
133 int32 NavigationEntry::GetPageID() const { | |
134 return page_id_; | |
135 } | |
136 | |
137 void NavigationEntry::set_site_instance(SiteInstance* site_instance) { | |
138 site_instance_ = site_instance; | |
139 } | |
140 | |
141 const string16& NavigationEntry::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, content::kMaxTitleChars, &cached_display_title_); | |
169 return cached_display_title_; | |
170 } | |
171 | |
172 bool NavigationEntry::IsViewSourceMode() const { | |
173 return virtual_url_.SchemeIs(chrome::kViewSourceScheme); | |
174 } | |
175 | |
176 void NavigationEntry::SetTransitionType( | |
177 content::PageTransition transition_type) { | |
178 transition_type_ = transition_type; | |
179 } | |
180 | |
181 content::PageTransition NavigationEntry::GetTransitionType() const { | |
182 return transition_type_; | |
183 } | |
184 | |
185 const GURL& NavigationEntry::GetUserTypedURL() const { | |
186 return user_typed_url_; | |
187 } | |
188 | |
189 void NavigationEntry::SetHasPostData(bool has_post_data) { | |
190 has_post_data_ = has_post_data; | |
191 } | |
192 | |
193 bool NavigationEntry::GetHasPostData() const { | |
194 return has_post_data_; | |
195 } | |
196 | |
197 const FaviconStatus& NavigationEntry::GetFavicon() const { | |
198 return favicon_; | |
199 } | |
200 | |
201 FaviconStatus& NavigationEntry::GetFavicon() { | |
202 return favicon_; | |
203 } | |
204 | |
205 const SSLStatus& NavigationEntry::GetSSL() const { | |
206 return ssl_; | |
207 } | |
208 | |
209 SSLStatus& NavigationEntry::GetSSL() { | |
210 return ssl_; | |
211 } | |
OLD | NEW |