Chromium Code Reviews| 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 |