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

Side by Side Diff: ios/web/navigation/navigation_item_impl.mm

Issue 2722983003: Reland Tab History and BrowserViewController CRWSessionEntry removal. (Closed)
Patch Set: fixes Created 3 years, 9 months 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
OLDNEW
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 #import "ios/web/navigation/navigation_item_impl.h" 5 #import "ios/web/navigation/navigation_item_impl.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <utility> 10 #include <utility>
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 // Most pages have real titles. Don't even bother caching anything if this is 147 // Most pages have real titles. Don't even bother caching anything if this is
148 // the case. 148 // the case.
149 if (!title_.empty()) 149 if (!title_.empty())
150 return title_; 150 return title_;
151 151
152 // More complicated cases will use the URLs as the title. This result we will 152 // More complicated cases will use the URLs as the title. This result we will
153 // cache since it's more complicated to compute. 153 // cache since it's more complicated to compute.
154 if (!cached_display_title_.empty()) 154 if (!cached_display_title_.empty())
155 return cached_display_title_; 155 return cached_display_title_;
156 156
157 // Use the virtual URL first if any, and fall back on using the real URL. 157 cached_display_title_ =
158 base::string16 title; 158 NavigationItemImpl::GetDisplayTitleForURL(GetVirtualURL());
159 if (!virtual_url_.is_empty()) {
160 title = url_formatter::FormatUrl(virtual_url_);
161 } else if (!url_.is_empty()) {
162 title = url_formatter::FormatUrl(url_);
163 }
164
165 // For file:// URLs use the filename as the title, not the full path.
166 if (url_.SchemeIsFile()) {
167 base::string16::size_type slashpos = title.rfind('/');
168 if (slashpos != base::string16::npos)
169 title = title.substr(slashpos + 1);
170 }
171
172 const size_t kMaxTitleChars = 4 * 1024;
173 gfx::ElideString(title, kMaxTitleChars, &cached_display_title_);
174 return cached_display_title_; 159 return cached_display_title_;
175 } 160 }
176 161
177 void NavigationItemImpl::SetTransitionType(ui::PageTransition transition_type) { 162 void NavigationItemImpl::SetTransitionType(ui::PageTransition transition_type) {
178 transition_type_ = transition_type; 163 transition_type_ = transition_type;
179 } 164 }
180 165
181 ui::PageTransition NavigationItemImpl::GetTransitionType() const { 166 ui::PageTransition NavigationItemImpl::GetTransitionType() const {
182 return transition_type_; 167 return transition_type_;
183 } 168 }
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 void NavigationItemImpl::ResetHttpRequestHeaders() { 288 void NavigationItemImpl::ResetHttpRequestHeaders() {
304 http_request_headers_.reset(); 289 http_request_headers_.reset();
305 } 290 }
306 291
307 void NavigationItemImpl::ResetForCommit() { 292 void NavigationItemImpl::ResetForCommit() {
308 // Navigation initiation type is only valid for pending navigations, thus 293 // Navigation initiation type is only valid for pending navigations, thus
309 // always reset to NONE after the item is committed. 294 // always reset to NONE after the item is committed.
310 SetNavigationInitiationType(web::NavigationInitiationType::NONE); 295 SetNavigationInitiationType(web::NavigationInitiationType::NONE);
311 } 296 }
312 297
298 // static
299 base::string16 NavigationItemImpl::GetDisplayTitleForURL(const GURL& url) {
300 DCHECK(!url.is_empty());
Eugene But (OOO till 7-30) 2017/03/01 22:45:44 Is this DCHECK valid?
kkhorimoto 2017/03/01 23:23:47 I've updated to an early return for code robustnes
301 base::string16 title = url_formatter::FormatUrl(url);
302
303 // For file:// URLs use the filename as the title, not the full path.
304 if (url.SchemeIsFile()) {
Eugene But (OOO till 7-30) 2017/03/01 22:45:44 Old code used url, new code uses virtualURL. Is th
kkhorimoto 2017/03/01 23:23:47 Yes, since the virtual URL is what's displayed to
305 base::string16::size_type slashpos = title.rfind('/');
306 if (slashpos != base::string16::npos)
307 title = title.substr(slashpos + 1);
308 }
309
310 const size_t kMaxTitleChars = 4 * 1024;
311 gfx::ElideString(title, kMaxTitleChars, &title);
312 return title;
313 }
314
313 } // namespace web 315 } // namespace web
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698