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] | 1db6ff15 | 2009-10-12 15:32:07 | [diff] [blame] | 8 | #include "base/string_util.h" |
[email protected] | ce560f8 | 2009-06-03 09:39:44 | [diff] [blame] | 9 | #include "chrome/browser/profile.h" |
[email protected] | 1db6ff15 | 2009-10-12 15:32:07 | [diff] [blame] | 10 | #include "chrome/browser/renderer_host/site_instance.h" |
[email protected] | 4c4d8d2 | 2009-03-04 05:29:27 | [diff] [blame] | 11 | #include "chrome/browser/tab_contents/navigation_controller.h" |
[email protected] | 4c4d8d2 | 2009-03-04 05:29:27 | [diff] [blame] | 12 | #include "chrome/common/pref_names.h" |
| 13 | #include "chrome/common/pref_service.h" |
[email protected] | 6de7445 | 2009-02-25 18:04:59 | [diff] [blame] | 14 | #include "chrome/common/url_constants.h" |
[email protected] | 074f1056 | 2009-05-21 22:40:05 | [diff] [blame] | 15 | #include "grit/app_resources.h" |
[email protected] | f9fe863 | 2009-05-22 18:15:24 | [diff] [blame] | 16 | #include "net/base/net_util.h" |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 17 | |
[email protected] | 1e5645ff | 2008-08-27 18:09:07 | [diff] [blame] | 18 | // Use this to get a new unique ID for a NavigationEntry during construction. |
| 19 | // The returned ID is guaranteed to be nonzero (which is the "no ID" indicator). |
| 20 | static int GetUniqueID() { |
| 21 | static int unique_id_counter = 0; |
| 22 | return ++unique_id_counter; |
| 23 | } |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 24 | |
[email protected] | eb34392b | 2008-08-19 15:42:20 | [diff] [blame] | 25 | NavigationEntry::SSLStatus::SSLStatus() |
| 26 | : security_style_(SECURITY_STYLE_UNKNOWN), |
| 27 | cert_id_(0), |
| 28 | cert_status_(0), |
| 29 | security_bits_(-1), |
| 30 | content_status_(NORMAL_CONTENT) { |
| 31 | } |
| 32 | |
[email protected] | 1e5645ff | 2008-08-27 18:09:07 | [diff] [blame] | 33 | NavigationEntry::FaviconStatus::FaviconStatus() : valid_(false) { |
| 34 | ResourceBundle &rb = ResourceBundle::GetSharedInstance(); |
| 35 | bitmap_ = *rb.GetBitmapNamed(IDR_DEFAULT_FAVICON); |
| 36 | } |
| 37 | |
[email protected] | 965524b | 2009-04-04 21:32:40 | [diff] [blame] | 38 | |
| 39 | NavigationEntry::NavigationEntry() |
| 40 | : unique_id_(GetUniqueID()), |
[email protected] | 965524b | 2009-04-04 21:32:40 | [diff] [blame] | 41 | site_instance_(NULL), |
| 42 | page_type_(NORMAL_PAGE), |
| 43 | page_id_(-1), |
| 44 | transition_type_(PageTransition::LINK), |
| 45 | has_post_data_(false), |
[email protected] | 5e36967 | 2009-11-03 23:48:30 | [diff] [blame] | 46 | restore_type_(RESTORE_NONE) { |
[email protected] | 965524b | 2009-04-04 21:32:40 | [diff] [blame] | 47 | } |
| 48 | |
[email protected] | b680ad2 | 2009-04-15 23:19:42 | [diff] [blame] | 49 | NavigationEntry::NavigationEntry(SiteInstance* instance, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 50 | int page_id, |
| 51 | const GURL& url, |
[email protected] | c058805 | 2008-10-27 23:01:50 | [diff] [blame] | 52 | const GURL& referrer, |
[email protected] | 4c4d8d2 | 2009-03-04 05:29:27 | [diff] [blame] | 53 | const string16& title, |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 54 | PageTransition::Type transition_type) |
[email protected] | 1e5645ff | 2008-08-27 18:09:07 | [diff] [blame] | 55 | : unique_id_(GetUniqueID()), |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 56 | site_instance_(instance), |
[email protected] | 1e5645ff | 2008-08-27 18:09:07 | [diff] [blame] | 57 | page_type_(NORMAL_PAGE), |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 58 | url_(url), |
[email protected] | c058805 | 2008-10-27 23:01:50 | [diff] [blame] | 59 | referrer_(referrer), |
[email protected] | 38178a4 | 2009-12-17 18:58:32 | [diff] [blame^] | 60 | update_virtual_url_with_url_(false), |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 61 | title_(title), |
[email protected] | 1e5645ff | 2008-08-27 18:09:07 | [diff] [blame] | 62 | page_id_(page_id), |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 63 | transition_type_(transition_type), |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 64 | has_post_data_(false), |
[email protected] | 5e36967 | 2009-11-03 23:48:30 | [diff] [blame] | 65 | restore_type_(RESTORE_NONE) { |
initial.commit | 09911bf | 2008-07-26 23:55:29 | [diff] [blame] | 66 | } |
[email protected] | 3d627bbc | 2008-10-23 20:49:07 | [diff] [blame] | 67 | |
[email protected] | 1db6ff15 | 2009-10-12 15:32:07 | [diff] [blame] | 68 | NavigationEntry::~NavigationEntry() { |
| 69 | } |
| 70 | |
| 71 | void NavigationEntry::set_site_instance(SiteInstance* site_instance) { |
| 72 | site_instance_ = site_instance; |
| 73 | } |
| 74 | |
[email protected] | 4c4d8d2 | 2009-03-04 05:29:27 | [diff] [blame] | 75 | const string16& NavigationEntry::GetTitleForDisplay( |
| 76 | const NavigationController* navigation_controller) { |
| 77 | // Most pages have real titles. Don't even bother caching anything if this is |
| 78 | // the case. |
| 79 | if (!title_.empty()) |
| 80 | return title_; |
| 81 | |
| 82 | // More complicated cases will use the URLs as the title. This result we will |
| 83 | // cache since it's more complicated to compute. |
| 84 | if (!cached_display_title_.empty()) |
| 85 | return cached_display_title_; |
| 86 | |
[email protected] | ebe89e06 | 2009-08-13 23:16:54 | [diff] [blame] | 87 | // 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] | 88 | std::wstring languages; |
| 89 | if (navigation_controller) { |
| 90 | languages = navigation_controller->profile()->GetPrefs()->GetString( |
| 91 | prefs::kAcceptLanguages); |
| 92 | } |
[email protected] | ebe89e06 | 2009-08-13 23:16:54 | [diff] [blame] | 93 | if (!virtual_url_.is_empty()) { |
[email protected] | f9fe863 | 2009-05-22 18:15:24 | [diff] [blame] | 94 | cached_display_title_ = WideToUTF16Hack(net::FormatUrl( |
[email protected] | ebe89e06 | 2009-08-13 23:16:54 | [diff] [blame] | 95 | virtual_url_, languages)); |
[email protected] | 4c4d8d2 | 2009-03-04 05:29:27 | [diff] [blame] | 96 | } else if (!url_.is_empty()) { |
[email protected] | f9fe863 | 2009-05-22 18:15:24 | [diff] [blame] | 97 | cached_display_title_ = WideToUTF16Hack(net::FormatUrl(url_, languages)); |
[email protected] | 4c4d8d2 | 2009-03-04 05:29:27 | [diff] [blame] | 98 | } |
| 99 | return cached_display_title_; |
[email protected] | 97f756b | 2008-12-16 04:06:24 | [diff] [blame] | 100 | } |
[email protected] | 6de7445 | 2009-02-25 18:04:59 | [diff] [blame] | 101 | |
| 102 | bool NavigationEntry::IsViewSourceMode() const { |
[email protected] | ebe89e06 | 2009-08-13 23:16:54 | [diff] [blame] | 103 | return virtual_url_.SchemeIs(chrome::kViewSourceScheme); |
[email protected] | 6de7445 | 2009-02-25 18:04:59 | [diff] [blame] | 104 | } |