| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "content/browser/tab_contents/navigation_entry.h" | 5 #include "content/browser/tab_contents/navigation_entry.h" |
| 6 | 6 |
| 7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
| 8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
| 10 #include "chrome/common/chrome_constants.h" | 10 #include "chrome/common/chrome_constants.h" |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 47 page_id_(-1), | 47 page_id_(-1), |
| 48 transition_type_(PageTransition::LINK), | 48 transition_type_(PageTransition::LINK), |
| 49 has_post_data_(false), | 49 has_post_data_(false), |
| 50 restore_type_(RESTORE_NONE) { | 50 restore_type_(RESTORE_NONE) { |
| 51 } | 51 } |
| 52 | 52 |
| 53 NavigationEntry::NavigationEntry(SiteInstance* instance, | 53 NavigationEntry::NavigationEntry(SiteInstance* instance, |
| 54 int page_id, | 54 int page_id, |
| 55 const GURL& url, | 55 const GURL& url, |
| 56 const GURL& referrer, | 56 const GURL& referrer, |
| 57 const string16& title, | 57 const base::i18n::String16WithDirection& title, |
| 58 PageTransition::Type transition_type) | 58 PageTransition::Type transition_type) |
| 59 : unique_id_(GetUniqueID()), | 59 : unique_id_(GetUniqueID()), |
| 60 site_instance_(instance), | 60 site_instance_(instance), |
| 61 page_type_(NORMAL_PAGE), | 61 page_type_(NORMAL_PAGE), |
| 62 url_(url), | 62 url_(url), |
| 63 referrer_(referrer), | 63 referrer_(referrer), |
| 64 update_virtual_url_with_url_(false), | 64 update_virtual_url_with_url_(false), |
| 65 title_(title), | 65 title_(title), |
| 66 page_id_(page_id), | 66 page_id_(page_id), |
| 67 transition_type_(transition_type), | 67 transition_type_(transition_type), |
| 68 has_post_data_(false), | 68 has_post_data_(false), |
| 69 restore_type_(RESTORE_NONE) { | 69 restore_type_(RESTORE_NONE) { |
| 70 } | 70 } |
| 71 | 71 |
| 72 NavigationEntry::~NavigationEntry() { | 72 NavigationEntry::~NavigationEntry() { |
| 73 } | 73 } |
| 74 | 74 |
| 75 void NavigationEntry::set_site_instance(SiteInstance* site_instance) { | 75 void NavigationEntry::set_site_instance(SiteInstance* site_instance) { |
| 76 site_instance_ = site_instance; | 76 site_instance_ = site_instance; |
| 77 } | 77 } |
| 78 | 78 |
| 79 const string16& NavigationEntry::GetTitleForDisplay( | 79 const base::i18n::String16WithDirection& NavigationEntry::GetTitleForDisplay( |
| 80 const std::string& languages) { | 80 const std::string& languages) { |
| 81 // Most pages have real titles. Don't even bother caching anything if this is | 81 // Most pages have real titles. Don't even bother caching anything if this is |
| 82 // the case. | 82 // the case. |
| 83 if (!title_.empty()) | 83 if (!title_.is_empty()) |
| 84 return title_; | 84 return title_; |
| 85 | 85 |
| 86 // More complicated cases will use the URLs as the title. This result we will | 86 // More complicated cases will use the URLs as the title. This result we will |
| 87 // cache since it's more complicated to compute. | 87 // cache since it's more complicated to compute. |
| 88 if (!cached_display_title_.empty()) | 88 if (!cached_display_title_.is_empty()) |
| 89 return cached_display_title_; | 89 return cached_display_title_; |
| 90 | 90 |
| 91 // Use the virtual URL first if any, and fall back on using the real URL. | 91 // Use the virtual URL first if any, and fall back on using the real URL. |
| 92 string16 title; | 92 string16 title; |
| 93 if (!virtual_url_.is_empty()) { | 93 if (!virtual_url_.is_empty()) { |
| 94 title = net::FormatUrl(virtual_url_, languages); | 94 title = net::FormatUrl(virtual_url_, languages); |
| 95 } else if (!url_.is_empty()) { | 95 } else if (!url_.is_empty()) { |
| 96 title = net::FormatUrl(url_, languages); | 96 title = net::FormatUrl(url_, languages); |
| 97 } | 97 } |
| 98 | 98 |
| 99 // For file:// URLs use the filename as the title, not the full path. | 99 // For file:// URLs use the filename as the title, not the full path. |
| 100 if (url_.SchemeIsFile()) { | 100 if (url_.SchemeIsFile()) { |
| 101 string16::size_type slashpos = title.rfind('/'); | 101 string16::size_type slashpos = title.rfind('/'); |
| 102 if (slashpos != string16::npos) | 102 if (slashpos != string16::npos) |
| 103 title = title.substr(slashpos + 1); | 103 title = title.substr(slashpos + 1); |
| 104 } | 104 } |
| 105 | 105 |
| 106 ui::ElideString(title, content::kMaxTitleChars, &cached_display_title_); | 106 string16 elided_title; |
| 107 ui::ElideString(title, content::kMaxTitleChars, &elided_title); |
| 108 |
| 109 // The computed title is a URL or a filename; assume it's LTR. |
| 110 cached_display_title_ = |
| 111 base::i18n::String16WithDirection(elided_title, |
| 112 base::i18n::LEFT_TO_RIGHT); |
| 107 return cached_display_title_; | 113 return cached_display_title_; |
| 108 } | 114 } |
| 109 | 115 |
| 110 bool NavigationEntry::IsViewSourceMode() const { | 116 bool NavigationEntry::IsViewSourceMode() const { |
| 111 return virtual_url_.SchemeIs(chrome::kViewSourceScheme); | 117 return virtual_url_.SchemeIs(chrome::kViewSourceScheme); |
| 112 } | 118 } |
| OLD | NEW |