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

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

Issue 2876053002: Fixed NavigationItemImpl::GetDisplayTitleForURL for 'file://' URL. (Closed)
Patch Set: Created 3 years, 7 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
« no previous file with comments | « no previous file | ios/web/navigation/navigation_item_impl_unittest.mm » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 279 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 // static 290 // static
291 base::string16 NavigationItemImpl::GetDisplayTitleForURL(const GURL& url) { 291 base::string16 NavigationItemImpl::GetDisplayTitleForURL(const GURL& url) {
292 if (url.is_empty()) 292 if (url.is_empty())
293 return base::string16(); 293 return base::string16();
294 294
295 base::string16 title = url_formatter::FormatUrl(url); 295 base::string16 title = url_formatter::FormatUrl(url);
296 296
297 // For file:// URLs use the filename as the title, not the full path. 297 // For file:// URLs use the filename as the title, not the full path.
298 if (url.SchemeIsFile()) { 298 if (url.SchemeIsFile()) {
299 base::string16::size_type slashpos = title.rfind('/'); 299 base::string16::size_type slashpos = title.rfind('/');
300 if (slashpos != base::string16::npos) 300 if (slashpos != base::string16::npos && slashpos != (title.size() - 1))
301 title = title.substr(slashpos + 1); 301 title = title.substr(slashpos + 1);
302 } 302 }
303 303
304 const size_t kMaxTitleChars = 4 * 1024; 304 const size_t kMaxTitleChars = 4 * 1024;
305 gfx::ElideString(title, kMaxTitleChars, &title); 305 gfx::ElideString(title, kMaxTitleChars, &title);
306 return title; 306 return title;
307 } 307 }
308 308
309 #ifndef NDEBUG 309 #ifndef NDEBUG
310 NSString* NavigationItemImpl::GetDescription() const { 310 NSString* NavigationItemImpl::GetDescription() const {
311 return [NSString 311 return [NSString
312 stringWithFormat: 312 stringWithFormat:
313 @"url:%s originalurl:%s title:%s transition:%d displayState:%@ " 313 @"url:%s originalurl:%s title:%s transition:%d displayState:%@ "
314 @"userAgentType:%s", 314 @"userAgentType:%s",
315 url_.spec().c_str(), original_request_url_.spec().c_str(), 315 url_.spec().c_str(), original_request_url_.spec().c_str(),
316 base::UTF16ToUTF8(title_).c_str(), transition_type_, 316 base::UTF16ToUTF8(title_).c_str(), transition_type_,
317 page_display_state_.GetDescription(), 317 page_display_state_.GetDescription(),
318 GetUserAgentTypeDescription(user_agent_type_).c_str()]; 318 GetUserAgentTypeDescription(user_agent_type_).c_str()];
319 } 319 }
320 #endif 320 #endif
321 321
322 } // namespace web 322 } // namespace web
OLDNEW
« no previous file with comments | « no previous file | ios/web/navigation/navigation_item_impl_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698