Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(247)

Side by Side Diff: content/browser/web_contents/navigation_entry_impl.cc

Issue 49823002: Move navigation and frame tree classes to a new frame_host/ directory. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixing gyp and adding TODO. Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(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/web_contents/navigation_entry_impl.h"
6
7 #include "base/metrics/histogram.h"
8 #include "base/strings/string_util.h"
9 #include "base/strings/utf_string_conversions.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/gfx/text_elider.h"
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
24 int NavigationEntryImpl::kInvalidBindings = -1;
25
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),
42 bindings_(kInvalidBindings),
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),
48 post_id_(-1),
49 restore_type_(RESTORE_NONE),
50 is_overriding_user_agent_(false),
51 http_status_code_(0),
52 is_renderer_initiated_(false),
53 should_replace_entry_(false),
54 should_clear_history_list_(false),
55 can_load_local_resources_(false) {
56 }
57
58 NavigationEntryImpl::NavigationEntryImpl(SiteInstanceImpl* instance,
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),
67 bindings_(kInvalidBindings),
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),
76 post_id_(-1),
77 restore_type_(RESTORE_NONE),
78 is_overriding_user_agent_(false),
79 http_status_code_(0),
80 is_renderer_initiated_(is_renderer_initiated),
81 should_replace_entry_(false),
82 should_clear_history_list_(false),
83 can_load_local_resources_(false) {
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
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
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
140 void NavigationEntryImpl::SetPageState(const PageState& state) {
141 page_state_ = state;
142 }
143
144 const PageState& NavigationEntryImpl::GetPageState() const {
145 return page_state_;
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
156 void NavigationEntryImpl::set_site_instance(SiteInstanceImpl* site_instance) {
157 site_instance_ = site_instance;
158 }
159
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
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
194 gfx::ElideString(title, kMaxTitleChars, &cached_display_title_);
195 return cached_display_title_;
196 }
197
198 bool NavigationEntryImpl::IsViewSourceMode() const {
199 return virtual_url_.SchemeIs(kViewSourceScheme);
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
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
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
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
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
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
274 void NavigationEntryImpl::SetTimestamp(base::Time timestamp) {
275 timestamp_ = timestamp;
276 }
277
278 base::Time NavigationEntryImpl::GetTimestamp() const {
279 return timestamp_;
280 }
281
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
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
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
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
324 void NavigationEntryImpl::SetScreenshotPNGData(
325 scoped_refptr<base::RefCountedBytes> png_data) {
326 screenshot_ = png_data;
327 if (screenshot_.get())
328 UMA_HISTOGRAM_MEMORY_KB("Overscroll.ScreenshotSize", screenshot_->size());
329 }
330
331 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/web_contents/navigation_entry_impl.h ('k') | content/browser/web_contents/navigation_entry_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698