OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/browser/web_contents/navigation_entry_impl.h" | 5 #include "content/browser/web_contents/navigation_entry_impl.h" |
6 | 6 |
7 #include "base/metrics/histogram.h" | 7 #include "base/metrics/histogram.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "content/public/common/content_constants.h" | 10 #include "content/public/common/content_constants.h" |
11 #include "content/public/common/url_constants.h" | 11 #include "content/public/common/url_constants.h" |
12 #include "net/base/net_util.h" | 12 #include "net/base/net_util.h" |
13 #include "ui/base/text/text_elider.h" | 13 #include "ui/base/text/text_elider.h" |
14 | 14 |
15 // Use this to get a new unique ID for a NavigationEntry during construction. | 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). | 16 // The returned ID is guaranteed to be nonzero (which is the "no ID" indicator). |
17 static int GetUniqueIDInConstructor() { | 17 static int GetUniqueIDInConstructor() { |
18 static int unique_id_counter = 0; | 18 static int unique_id_counter = 0; |
19 return ++unique_id_counter; | 19 return ++unique_id_counter; |
20 } | 20 } |
21 | 21 |
22 namespace content { | 22 namespace content { |
23 | 23 |
| 24 int NavigationEntryImpl::kInvalidBindings = -1; |
| 25 |
24 NavigationEntry* NavigationEntry::Create() { | 26 NavigationEntry* NavigationEntry::Create() { |
25 return new NavigationEntryImpl(); | 27 return new NavigationEntryImpl(); |
26 } | 28 } |
27 | 29 |
28 NavigationEntry* NavigationEntry::Create(const NavigationEntry& copy) { | 30 NavigationEntry* NavigationEntry::Create(const NavigationEntry& copy) { |
29 return new NavigationEntryImpl(static_cast<const NavigationEntryImpl&>(copy)); | 31 return new NavigationEntryImpl(static_cast<const NavigationEntryImpl&>(copy)); |
30 } | 32 } |
31 | 33 |
32 NavigationEntryImpl* NavigationEntryImpl::FromNavigationEntry( | 34 NavigationEntryImpl* NavigationEntryImpl::FromNavigationEntry( |
33 NavigationEntry* entry) { | 35 NavigationEntry* entry) { |
34 return static_cast<NavigationEntryImpl*>(entry); | 36 return static_cast<NavigationEntryImpl*>(entry); |
35 } | 37 } |
36 | 38 |
37 NavigationEntryImpl::NavigationEntryImpl() | 39 NavigationEntryImpl::NavigationEntryImpl() |
38 : unique_id_(GetUniqueIDInConstructor()), | 40 : unique_id_(GetUniqueIDInConstructor()), |
39 site_instance_(NULL), | 41 site_instance_(NULL), |
| 42 bindings_(kInvalidBindings), |
40 page_type_(PAGE_TYPE_NORMAL), | 43 page_type_(PAGE_TYPE_NORMAL), |
41 update_virtual_url_with_url_(false), | 44 update_virtual_url_with_url_(false), |
42 page_id_(-1), | 45 page_id_(-1), |
43 transition_type_(PAGE_TRANSITION_LINK), | 46 transition_type_(PAGE_TRANSITION_LINK), |
44 has_post_data_(false), | 47 has_post_data_(false), |
45 post_id_(-1), | 48 post_id_(-1), |
46 restore_type_(RESTORE_NONE), | 49 restore_type_(RESTORE_NONE), |
47 is_overriding_user_agent_(false), | 50 is_overriding_user_agent_(false), |
48 is_renderer_initiated_(false), | 51 is_renderer_initiated_(false), |
49 should_replace_entry_(false), | 52 should_replace_entry_(false), |
50 can_load_local_resources_(false) { | 53 can_load_local_resources_(false) { |
51 } | 54 } |
52 | 55 |
53 NavigationEntryImpl::NavigationEntryImpl(SiteInstanceImpl* instance, | 56 NavigationEntryImpl::NavigationEntryImpl(SiteInstanceImpl* instance, |
54 int page_id, | 57 int page_id, |
55 const GURL& url, | 58 const GURL& url, |
56 const Referrer& referrer, | 59 const Referrer& referrer, |
57 const string16& title, | 60 const string16& title, |
58 PageTransition transition_type, | 61 PageTransition transition_type, |
59 bool is_renderer_initiated) | 62 bool is_renderer_initiated) |
60 : unique_id_(GetUniqueIDInConstructor()), | 63 : unique_id_(GetUniqueIDInConstructor()), |
61 site_instance_(instance), | 64 site_instance_(instance), |
| 65 bindings_(kInvalidBindings), |
62 page_type_(PAGE_TYPE_NORMAL), | 66 page_type_(PAGE_TYPE_NORMAL), |
63 url_(url), | 67 url_(url), |
64 referrer_(referrer), | 68 referrer_(referrer), |
65 update_virtual_url_with_url_(false), | 69 update_virtual_url_with_url_(false), |
66 title_(title), | 70 title_(title), |
67 page_id_(page_id), | 71 page_id_(page_id), |
68 transition_type_(transition_type), | 72 transition_type_(transition_type), |
69 has_post_data_(false), | 73 has_post_data_(false), |
70 post_id_(-1), | 74 post_id_(-1), |
71 restore_type_(RESTORE_NONE), | 75 restore_type_(RESTORE_NONE), |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 } | 146 } |
143 | 147 |
144 int32 NavigationEntryImpl::GetPageID() const { | 148 int32 NavigationEntryImpl::GetPageID() const { |
145 return page_id_; | 149 return page_id_; |
146 } | 150 } |
147 | 151 |
148 void NavigationEntryImpl::set_site_instance(SiteInstanceImpl* site_instance) { | 152 void NavigationEntryImpl::set_site_instance(SiteInstanceImpl* site_instance) { |
149 site_instance_ = site_instance; | 153 site_instance_ = site_instance; |
150 } | 154 } |
151 | 155 |
| 156 void NavigationEntryImpl::SetBindings(int bindings) { |
| 157 // Ensure this is set to a valid value, and that it stays the same once set. |
| 158 CHECK_NE(bindings, kInvalidBindings); |
| 159 CHECK(bindings_ == kInvalidBindings || bindings_ == bindings); |
| 160 bindings_ = bindings; |
| 161 } |
| 162 |
152 const string16& NavigationEntryImpl::GetTitleForDisplay( | 163 const string16& NavigationEntryImpl::GetTitleForDisplay( |
153 const std::string& languages) const { | 164 const std::string& languages) const { |
154 // Most pages have real titles. Don't even bother caching anything if this is | 165 // Most pages have real titles. Don't even bother caching anything if this is |
155 // the case. | 166 // the case. |
156 if (!title_.empty()) | 167 if (!title_.empty()) |
157 return title_; | 168 return title_; |
158 | 169 |
159 // More complicated cases will use the URLs as the title. This result we will | 170 // More complicated cases will use the URLs as the title. This result we will |
160 // cache since it's more complicated to compute. | 171 // cache since it's more complicated to compute. |
161 if (!cached_display_title_.empty()) | 172 if (!cached_display_title_.empty()) |
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 } | 310 } |
300 | 311 |
301 void NavigationEntryImpl::SetScreenshotPNGData( | 312 void NavigationEntryImpl::SetScreenshotPNGData( |
302 const std::vector<unsigned char>& png_data) { | 313 const std::vector<unsigned char>& png_data) { |
303 screenshot_ = png_data.empty() ? NULL : new base::RefCountedBytes(png_data); | 314 screenshot_ = png_data.empty() ? NULL : new base::RefCountedBytes(png_data); |
304 if (screenshot_) | 315 if (screenshot_) |
305 UMA_HISTOGRAM_MEMORY_KB("Overscroll.ScreenshotSize", screenshot_->size()); | 316 UMA_HISTOGRAM_MEMORY_KB("Overscroll.ScreenshotSize", screenshot_->size()); |
306 } | 317 } |
307 | 318 |
308 } // namespace content | 319 } // namespace content |
OLD | NEW |