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

Unified Diff: ios/web/navigation/navigation_item_impl.mm

Issue 2722983003: Reland Tab History and BrowserViewController CRWSessionEntry removal. (Closed)
Patch Set: fixes Created 3 years, 10 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 side-by-side diff with in-line comments
Download patch
Index: ios/web/navigation/navigation_item_impl.mm
diff --git a/ios/web/navigation/navigation_item_impl.mm b/ios/web/navigation/navigation_item_impl.mm
index 31f357566080a0b3b5613312130691500edc34bc..604c87a7a8d06027dce7578582b214edde910936 100644
--- a/ios/web/navigation/navigation_item_impl.mm
+++ b/ios/web/navigation/navigation_item_impl.mm
@@ -154,23 +154,8 @@ static int GetUniqueIDInConstructor() {
if (!cached_display_title_.empty())
return cached_display_title_;
- // Use the virtual URL first if any, and fall back on using the real URL.
- base::string16 title;
- if (!virtual_url_.is_empty()) {
- title = url_formatter::FormatUrl(virtual_url_);
- } else if (!url_.is_empty()) {
- title = url_formatter::FormatUrl(url_);
- }
-
- // For file:// URLs use the filename as the title, not the full path.
- if (url_.SchemeIsFile()) {
- base::string16::size_type slashpos = title.rfind('/');
- if (slashpos != base::string16::npos)
- title = title.substr(slashpos + 1);
- }
-
- const size_t kMaxTitleChars = 4 * 1024;
- gfx::ElideString(title, kMaxTitleChars, &cached_display_title_);
+ cached_display_title_ =
+ NavigationItemImpl::GetDisplayTitleForURL(GetVirtualURL());
return cached_display_title_;
}
@@ -310,4 +295,21 @@ static int GetUniqueIDInConstructor() {
SetNavigationInitiationType(web::NavigationInitiationType::NONE);
}
+// static
+base::string16 NavigationItemImpl::GetDisplayTitleForURL(const GURL& url) {
+ 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
+ base::string16 title = url_formatter::FormatUrl(url);
+
+ // For file:// URLs use the filename as the title, not the full path.
+ 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
+ base::string16::size_type slashpos = title.rfind('/');
+ if (slashpos != base::string16::npos)
+ title = title.substr(slashpos + 1);
+ }
+
+ const size_t kMaxTitleChars = 4 * 1024;
+ gfx::ElideString(title, kMaxTitleChars, &title);
+ return title;
+}
+
} // namespace web

Powered by Google App Engine
This is Rietveld 408576698