OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/tab_contents/navigation_entry.h" | |
6 | |
7 #include "base/string_util.h" | |
8 #include "base/utf_string_conversions.h" | |
9 #include "chrome/browser/profiles/profile.h" | |
10 #include "chrome/browser/renderer_host/site_instance.h" | |
11 #include "chrome/browser/tab_contents/navigation_controller.h" | |
12 #include "chrome/common/chrome_constants.h" | |
13 #include "chrome/common/url_constants.h" | |
14 #include "grit/app_resources.h" | |
15 #include "net/base/net_util.h" | |
16 #include "ui/base/resource/resource_bundle.h" | |
17 #include "ui/base/text/text_elider.h" | |
18 | |
19 // Use this to get a new unique ID for a NavigationEntry during construction. | |
20 // The returned ID is guaranteed to be nonzero (which is the "no ID" indicator). | |
21 static int GetUniqueID() { | |
22 static int unique_id_counter = 0; | |
23 return ++unique_id_counter; | |
24 } | |
25 | |
26 NavigationEntry::SSLStatus::SSLStatus() | |
27 : security_style_(SECURITY_STYLE_UNKNOWN), | |
28 cert_id_(0), | |
29 cert_status_(0), | |
30 security_bits_(-1), | |
31 connection_status_(0), | |
32 content_status_(NORMAL_CONTENT) { | |
33 } | |
34 | |
35 NavigationEntry::FaviconStatus::FaviconStatus() : valid_(false) { | |
36 ResourceBundle &rb = ResourceBundle::GetSharedInstance(); | |
37 bitmap_ = *rb.GetBitmapNamed(IDR_DEFAULT_FAVICON); | |
38 } | |
39 | |
40 | |
41 NavigationEntry::NavigationEntry() | |
42 : unique_id_(GetUniqueID()), | |
43 site_instance_(NULL), | |
44 page_type_(NORMAL_PAGE), | |
45 update_virtual_url_with_url_(false), | |
46 page_id_(-1), | |
47 transition_type_(PageTransition::LINK), | |
48 has_post_data_(false), | |
49 restore_type_(RESTORE_NONE) { | |
50 } | |
51 | |
52 NavigationEntry::NavigationEntry(SiteInstance* instance, | |
53 int page_id, | |
54 const GURL& url, | |
55 const GURL& referrer, | |
56 const string16& title, | |
57 PageTransition::Type transition_type) | |
58 : unique_id_(GetUniqueID()), | |
59 site_instance_(instance), | |
60 page_type_(NORMAL_PAGE), | |
61 url_(url), | |
62 referrer_(referrer), | |
63 update_virtual_url_with_url_(false), | |
64 title_(title), | |
65 page_id_(page_id), | |
66 transition_type_(transition_type), | |
67 has_post_data_(false), | |
68 restore_type_(RESTORE_NONE) { | |
69 } | |
70 | |
71 NavigationEntry::~NavigationEntry() { | |
72 } | |
73 | |
74 void NavigationEntry::set_site_instance(SiteInstance* site_instance) { | |
75 site_instance_ = site_instance; | |
76 } | |
77 | |
78 const string16& NavigationEntry::GetTitleForDisplay( | |
79 const std::string& languages) { | |
80 // Most pages have real titles. Don't even bother caching anything if this is | |
81 // the case. | |
82 if (!title_.empty()) | |
83 return title_; | |
84 | |
85 // More complicated cases will use the URLs as the title. This result we will | |
86 // cache since it's more complicated to compute. | |
87 if (!cached_display_title_.empty()) | |
88 return cached_display_title_; | |
89 | |
90 // Use the virtual URL first if any, and fall back on using the real URL. | |
91 string16 title; | |
92 std::wstring elided_title; | |
93 if (!virtual_url_.is_empty()) { | |
94 title = net::FormatUrl(virtual_url_, languages); | |
95 } else if (!url_.is_empty()) { | |
96 title = net::FormatUrl(url_, languages); | |
97 } | |
98 ui::ElideString(UTF16ToWideHack(title), chrome::kMaxTitleChars, | |
99 &elided_title); | |
100 cached_display_title_ = WideToUTF16Hack(elided_title); | |
101 return cached_display_title_; | |
102 } | |
103 | |
104 bool NavigationEntry::IsViewSourceMode() const { | |
105 return virtual_url_.SchemeIs(chrome::kViewSourceScheme); | |
106 } | |
OLD | NEW |