| 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 "chrome/browser/tab_contents/navigation_entry.h" | 5 #include "chrome/browser/tab_contents/navigation_entry.h" |
| 6 | 6 |
| 7 #include "chrome/browser/tab_contents/navigation_controller.h" |
| 8 #include "chrome/common/gfx/text_elider.h" |
| 9 #include "chrome/common/pref_names.h" |
| 10 #include "chrome/common/pref_service.h" |
| 7 #include "chrome/common/url_constants.h" | 11 #include "chrome/common/url_constants.h" |
| 8 #include "chrome/common/resource_bundle.h" | 12 #include "chrome/common/resource_bundle.h" |
| 9 | 13 |
| 10 // Use this to get a new unique ID for a NavigationEntry during construction. | 14 // Use this to get a new unique ID for a NavigationEntry during construction. |
| 11 // The returned ID is guaranteed to be nonzero (which is the "no ID" indicator). | 15 // The returned ID is guaranteed to be nonzero (which is the "no ID" indicator). |
| 12 static int GetUniqueID() { | 16 static int GetUniqueID() { |
| 13 static int unique_id_counter = 0; | 17 static int unique_id_counter = 0; |
| 14 return ++unique_id_counter; | 18 return ++unique_id_counter; |
| 15 } | 19 } |
| 16 | 20 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 36 transition_type_(PageTransition::LINK), | 40 transition_type_(PageTransition::LINK), |
| 37 has_post_data_(false), | 41 has_post_data_(false), |
| 38 restored_(false) { | 42 restored_(false) { |
| 39 } | 43 } |
| 40 | 44 |
| 41 NavigationEntry::NavigationEntry(TabContentsType type, | 45 NavigationEntry::NavigationEntry(TabContentsType type, |
| 42 SiteInstance* instance, | 46 SiteInstance* instance, |
| 43 int page_id, | 47 int page_id, |
| 44 const GURL& url, | 48 const GURL& url, |
| 45 const GURL& referrer, | 49 const GURL& referrer, |
| 46 const std::wstring& title, | 50 const string16& title, |
| 47 PageTransition::Type transition_type) | 51 PageTransition::Type transition_type) |
| 48 : unique_id_(GetUniqueID()), | 52 : unique_id_(GetUniqueID()), |
| 49 tab_type_(type), | 53 tab_type_(type), |
| 50 site_instance_(instance), | 54 site_instance_(instance), |
| 51 page_type_(NORMAL_PAGE), | 55 page_type_(NORMAL_PAGE), |
| 52 url_(url), | 56 url_(url), |
| 53 referrer_(referrer), | 57 referrer_(referrer), |
| 54 title_(title), | 58 title_(title), |
| 55 page_id_(page_id), | 59 page_id_(page_id), |
| 56 transition_type_(transition_type), | 60 transition_type_(transition_type), |
| 57 has_post_data_(false), | 61 has_post_data_(false), |
| 58 restored_(false) { | 62 restored_(false) { |
| 59 } | 63 } |
| 60 | 64 |
| 61 const std::wstring& NavigationEntry::GetTitleForDisplay() { | 65 const string16& NavigationEntry::GetTitleForDisplay( |
| 62 if (title_.empty()) | 66 const NavigationController* navigation_controller) { |
| 63 return display_url_as_string_; | 67 // Most pages have real titles. Don't even bother caching anything if this is |
| 64 return title_; | 68 // the case. |
| 69 if (!title_.empty()) |
| 70 return title_; |
| 71 |
| 72 // More complicated cases will use the URLs as the title. This result we will |
| 73 // cache since it's more complicated to compute. |
| 74 if (!cached_display_title_.empty()) |
| 75 return cached_display_title_; |
| 76 |
| 77 // Use the display URL first if any, and fall back on using the real URL. |
| 78 std::wstring languages; |
| 79 if (navigation_controller) { |
| 80 languages = navigation_controller->profile()->GetPrefs()->GetString( |
| 81 prefs::kAcceptLanguages); |
| 82 } |
| 83 if (!display_url_.is_empty()) { |
| 84 cached_display_title_ = WideToUTF16Hack(gfx::GetCleanStringFromUrl( |
| 85 display_url_, languages, NULL, NULL)); |
| 86 } else if (!url_.is_empty()) { |
| 87 cached_display_title_ = WideToUTF16Hack(gfx::GetCleanStringFromUrl( |
| 88 display_url_, languages, NULL, NULL)); |
| 89 } |
| 90 return cached_display_title_; |
| 65 } | 91 } |
| 66 | 92 |
| 67 bool NavigationEntry::IsViewSourceMode() const { | 93 bool NavigationEntry::IsViewSourceMode() const { |
| 68 return display_url_.SchemeIs(chrome::kViewSourceScheme); | 94 return display_url_.SchemeIs(chrome::kViewSourceScheme); |
| 69 } | 95 } |
| OLD | NEW |