| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "ios/web/navigation/navigation_item_impl.h" | 5 #include "ios/web/navigation/navigation_item_impl.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 120 | 120 |
| 121 void NavigationItemImpl::SetPageDisplayState( | 121 void NavigationItemImpl::SetPageDisplayState( |
| 122 const web::PageDisplayState& display_state) { | 122 const web::PageDisplayState& display_state) { |
| 123 page_display_state_ = display_state; | 123 page_display_state_ = display_state; |
| 124 } | 124 } |
| 125 | 125 |
| 126 const PageDisplayState& NavigationItemImpl::GetPageDisplayState() const { | 126 const PageDisplayState& NavigationItemImpl::GetPageDisplayState() const { |
| 127 return page_display_state_; | 127 return page_display_state_; |
| 128 } | 128 } |
| 129 | 129 |
| 130 const base::string16& NavigationItemImpl::GetTitleForDisplay( | 130 const base::string16& NavigationItemImpl::GetTitleForDisplay() const { |
| 131 const std::string& languages) const { | |
| 132 // Most pages have real titles. Don't even bother caching anything if this is | 131 // Most pages have real titles. Don't even bother caching anything if this is |
| 133 // the case. | 132 // the case. |
| 134 if (!title_.empty()) | 133 if (!title_.empty()) |
| 135 return title_; | 134 return title_; |
| 136 | 135 |
| 137 // More complicated cases will use the URLs as the title. This result we will | 136 // More complicated cases will use the URLs as the title. This result we will |
| 138 // cache since it's more complicated to compute. | 137 // cache since it's more complicated to compute. |
| 139 if (!cached_display_title_.empty()) | 138 if (!cached_display_title_.empty()) |
| 140 return cached_display_title_; | 139 return cached_display_title_; |
| 141 | 140 |
| 142 // Use the virtual URL first if any, and fall back on using the real URL. | 141 // Use the virtual URL first if any, and fall back on using the real URL. |
| 143 base::string16 title; | 142 base::string16 title; |
| 144 if (!virtual_url_.is_empty()) { | 143 if (!virtual_url_.is_empty()) { |
| 145 title = url_formatter::FormatUrl(virtual_url_, languages); | 144 title = url_formatter::FormatUrl(virtual_url_); |
| 146 } else if (!url_.is_empty()) { | 145 } else if (!url_.is_empty()) { |
| 147 title = url_formatter::FormatUrl(url_, languages); | 146 title = url_formatter::FormatUrl(url_); |
| 148 } | 147 } |
| 149 | 148 |
| 150 // For file:// URLs use the filename as the title, not the full path. | 149 // For file:// URLs use the filename as the title, not the full path. |
| 151 if (url_.SchemeIsFile()) { | 150 if (url_.SchemeIsFile()) { |
| 152 base::string16::size_type slashpos = title.rfind('/'); | 151 base::string16::size_type slashpos = title.rfind('/'); |
| 153 if (slashpos != base::string16::npos) | 152 if (slashpos != base::string16::npos) |
| 154 title = title.substr(slashpos + 1); | 153 title = title.substr(slashpos + 1); |
| 155 } | 154 } |
| 156 | 155 |
| 157 const size_t kMaxTitleChars = 4 * 1024; | 156 const size_t kMaxTitleChars = 4 * 1024; |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 271 http_request_headers_.reset(); | 270 http_request_headers_.reset(); |
| 272 } | 271 } |
| 273 | 272 |
| 274 void NavigationItemImpl::ResetForCommit() { | 273 void NavigationItemImpl::ResetForCommit() { |
| 275 // Any state that only matters when a navigation item is pending should be | 274 // Any state that only matters when a navigation item is pending should be |
| 276 // cleared here. | 275 // cleared here. |
| 277 set_is_renderer_initiated(false); | 276 set_is_renderer_initiated(false); |
| 278 } | 277 } |
| 279 | 278 |
| 280 } // namespace web | 279 } // namespace web |
| OLD | NEW |