license.bot | bf09a50 | 2008-08-24 00:55:55 | [diff] [blame] | 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. |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 4 | |
[email protected] | f3ec774 | 2009-01-15 00:59:16 | [diff] [blame] | 5 | #include "chrome/browser/tab_contents/navigation_entry.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 6 | |
[email protected] | 9929da9 | 2009-05-05 02:05:11 | [diff] [blame] | 7 | #include "app/resource_bundle.h" |
[email protected] | 2694360 | 2010-04-01 05:51:57 | [diff] [blame] | 8 | #include "base/string_util.h" |
[email protected] | 1cb92b8 | 2010-03-08 23:12:15 | [diff] [blame] | 9 | #include "base/utf_string_conversions.h" |
[email protected] | 052313b | 2010-02-19 09:43:08 | [diff] [blame] | 10 | #include "chrome/browser/pref_service.h" |
[email protected] | ce560f8 | 2009-06-03 09:39:44 | [diff] [blame] | 11 | #include "chrome/browser/profile.h" |
[email protected] | 1db6ff15 | 2009-10-12 15:32:07 | [diff] [blame] | 12 | #include "chrome/browser/renderer_host/site_instance.h" |
[email protected] | 4c4d8d2 | 2009-03-04 05:29:27 | [diff] [blame] | 13 | #include "chrome/browser/tab_contents/navigation_controller.h" |
[email protected] | 2694360 | 2010-04-01 05:51:57 | [diff] [blame] | 14 | #include "chrome/common/chrome_constants.h" |
[email protected] | 4c4d8d2 | 2009-03-04 05:29:27 | [diff] [blame] | 15 | #include "chrome/common/pref_names.h" |
[email protected] | 6de7445 | 2009-02-25 18:04:59 | [diff] [blame] | 16 | #include "chrome/common/url_constants.h" |
[email protected] | 074f1056 | 2009-05-21 22:40:05 | [diff] [blame] | 17 | #include "grit/app_resources.h" |
[email protected] | f9fe863 | 2009-05-22 18:15:24 | [diff] [blame] | 18 | #include "net/base/net_util.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 19 | |
[email protected] | 1e5645ff | 2008-08-27 18:09:07 | [diff] [blame] | 20 | // Use this to get a new unique ID for a NavigationEntry during construction. |
| 21 | // The returned ID is guaranteed to be nonzero (which is the "no ID" indicator). |
| 22 | static int GetUniqueID() { |
| 23 | static int unique_id_counter = 0; |
| 24 | return ++unique_id_counter; |
| 25 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 26 | |
[email protected] | eb34392b | 2008-08-19 15:42:20 | [diff] [blame] | 27 | NavigationEntry::SSLStatus::SSLStatus() |
| 28 | : security_style_(SECURITY_STYLE_UNKNOWN), |
| 29 | cert_id_(0), |
| 30 | cert_status_(0), |
| 31 | security_bits_(-1), |
| 32 | content_status_(NORMAL_CONTENT) { |
| 33 | } |
| 34 | |
[email protected] | 1e5645ff | 2008-08-27 18:09:07 | [diff] [blame] | 35 | NavigationEntry::FaviconStatus::FaviconStatus() : valid_(false) { |
| 36 | ResourceBundle &rb = ResourceBundle::GetSharedInstance(); |
| 37 | bitmap_ = *rb.GetBitmapNamed(IDR_DEFAULT_FAVICON); |
| 38 | } |
| 39 | |
[email protected] | 965524b | 2009-04-04 21:32:40 | [diff] [blame] | 40 | |
| 41 | NavigationEntry::NavigationEntry() |
| 42 | : unique_id_(GetUniqueID()), |
[email protected] | 965524b | 2009-04-04 21:32:40 | [diff] [blame] | 43 | site_instance_(NULL), |
| 44 | page_type_(NORMAL_PAGE), |
[email protected] | a1b508bd | 2009-12-17 20:40:43 | [diff] [blame] | 45 | update_virtual_url_with_url_(false), |
[email protected] | 965524b | 2009-04-04 21:32:40 | [diff] [blame] | 46 | page_id_(-1), |
| 47 | transition_type_(PageTransition::LINK), |
| 48 | has_post_data_(false), |
[email protected] | 5e36967 | 2009-11-03 23:48:30 | [diff] [blame] | 49 | restore_type_(RESTORE_NONE) { |
[email protected] | 965524b | 2009-04-04 21:32:40 | [diff] [blame] | 50 | } |
| 51 | |
[email protected] | b680ad2 | 2009-04-15 23:19:42 | [diff] [blame] | 52 | NavigationEntry::NavigationEntry(SiteInstance* instance, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 53 | int page_id, |
| 54 | const GURL& url, |
[email protected] | c058805 | 2008-10-27 23:01:50 | [diff] [blame] | 55 | const GURL& referrer, |
[email protected] | 4c4d8d2 | 2009-03-04 05:29:27 | [diff] [blame] | 56 | const string16& title, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 57 | PageTransition::Type transition_type) |
[email protected] | 1e5645ff | 2008-08-27 18:09:07 | [diff] [blame] | 58 | : unique_id_(GetUniqueID()), |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 59 | site_instance_(instance), |
[email protected] | 1e5645ff | 2008-08-27 18:09:07 | [diff] [blame] | 60 | page_type_(NORMAL_PAGE), |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 61 | url_(url), |
[email protected] | c058805 | 2008-10-27 23:01:50 | [diff] [blame] | 62 | referrer_(referrer), |
[email protected] | 38178a4 | 2009-12-17 18:58:32 | [diff] [blame] | 63 | update_virtual_url_with_url_(false), |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 64 | title_(title), |
[email protected] | 1e5645ff | 2008-08-27 18:09:07 | [diff] [blame] | 65 | page_id_(page_id), |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 66 | transition_type_(transition_type), |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 67 | has_post_data_(false), |
[email protected] | 5e36967 | 2009-11-03 23:48:30 | [diff] [blame] | 68 | restore_type_(RESTORE_NONE) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 69 | } |
[email protected] | 3d627bbc | 2008-10-23 20:49:07 | [diff] [blame] | 70 | |
[email protected] | 1db6ff15 | 2009-10-12 15:32:07 | [diff] [blame] | 71 | NavigationEntry::~NavigationEntry() { |
| 72 | } |
| 73 | |
| 74 | void NavigationEntry::set_site_instance(SiteInstance* site_instance) { |
| 75 | site_instance_ = site_instance; |
| 76 | } |
| 77 | |
[email protected] | 4c4d8d2 | 2009-03-04 05:29:27 | [diff] [blame] | 78 | const string16& NavigationEntry::GetTitleForDisplay( |
| 79 | const NavigationController* navigation_controller) { |
| 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 | |
[email protected] | ebe89e06 | 2009-08-13 23:16:54 | [diff] [blame] | 90 | // Use the virtual URL first if any, and fall back on using the real URL. |
[email protected] | 4c4d8d2 | 2009-03-04 05:29:27 | [diff] [blame] | 91 | std::wstring languages; |
| 92 | if (navigation_controller) { |
[email protected] | ddd231e | 2010-06-29 20:35:19 | [diff] [blame] | 93 | languages = UTF8ToWide(navigation_controller->profile()->GetPrefs()-> |
| 94 | GetString(prefs::kAcceptLanguages)); |
[email protected] | 4c4d8d2 | 2009-03-04 05:29:27 | [diff] [blame] | 95 | } |
[email protected] | 2694360 | 2010-04-01 05:51:57 | [diff] [blame] | 96 | |
| 97 | std::wstring title; |
| 98 | std::wstring elided_title; |
[email protected] | ebe89e06 | 2009-08-13 23:16:54 | [diff] [blame] | 99 | if (!virtual_url_.is_empty()) { |
[email protected] | 2694360 | 2010-04-01 05:51:57 | [diff] [blame] | 100 | title = net::FormatUrl(virtual_url_, languages); |
[email protected] | 4c4d8d2 | 2009-03-04 05:29:27 | [diff] [blame] | 101 | } else if (!url_.is_empty()) { |
[email protected] | 2694360 | 2010-04-01 05:51:57 | [diff] [blame] | 102 | title = net::FormatUrl(url_, languages); |
[email protected] | 4c4d8d2 | 2009-03-04 05:29:27 | [diff] [blame] | 103 | } |
[email protected] | 2694360 | 2010-04-01 05:51:57 | [diff] [blame] | 104 | ElideString(title, chrome::kMaxTitleChars, &elided_title); |
| 105 | cached_display_title_ = WideToUTF16Hack(elided_title); |
[email protected] | 4c4d8d2 | 2009-03-04 05:29:27 | [diff] [blame] | 106 | return cached_display_title_; |
[email protected] | 97f756b | 2008-12-16 04:06:24 | [diff] [blame] | 107 | } |
[email protected] | 6de7445 | 2009-02-25 18:04:59 | [diff] [blame] | 108 | |
| 109 | bool NavigationEntry::IsViewSourceMode() const { |
[email protected] | ebe89e06 | 2009-08-13 23:16:54 | [diff] [blame] | 110 | return virtual_url_.SchemeIs(chrome::kViewSourceScheme); |
[email protected] | 6de7445 | 2009-02-25 18:04:59 | [diff] [blame] | 111 | } |