blob: 4ce5bdae53cd74a14f1fe756508764e5d6b15405 [file] [log] [blame]
license.botbf09a502008-08-24 00:55:551// 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.commit09911bf2008-07-26 23:55:294
[email protected]f3ec7742009-01-15 00:59:165#include "chrome/browser/tab_contents/navigation_entry.h"
initial.commit09911bf2008-07-26 23:55:296
[email protected]9929da92009-05-05 02:05:117#include "app/resource_bundle.h"
[email protected]26943602010-04-01 05:51:578#include "base/string_util.h"
[email protected]1cb92b82010-03-08 23:12:159#include "base/utf_string_conversions.h"
[email protected]052313b2010-02-19 09:43:0810#include "chrome/browser/pref_service.h"
[email protected]ce560f82009-06-03 09:39:4411#include "chrome/browser/profile.h"
[email protected]1db6ff152009-10-12 15:32:0712#include "chrome/browser/renderer_host/site_instance.h"
[email protected]4c4d8d22009-03-04 05:29:2713#include "chrome/browser/tab_contents/navigation_controller.h"
[email protected]26943602010-04-01 05:51:5714#include "chrome/common/chrome_constants.h"
[email protected]4c4d8d22009-03-04 05:29:2715#include "chrome/common/pref_names.h"
[email protected]6de74452009-02-25 18:04:5916#include "chrome/common/url_constants.h"
[email protected]074f10562009-05-21 22:40:0517#include "grit/app_resources.h"
[email protected]f9fe8632009-05-22 18:15:2418#include "net/base/net_util.h"
initial.commit09911bf2008-07-26 23:55:2919
[email protected]1e5645ff2008-08-27 18:09:0720// 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).
22static int GetUniqueID() {
23 static int unique_id_counter = 0;
24 return ++unique_id_counter;
25}
initial.commit09911bf2008-07-26 23:55:2926
[email protected]eb34392b2008-08-19 15:42:2027NavigationEntry::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]1e5645ff2008-08-27 18:09:0735NavigationEntry::FaviconStatus::FaviconStatus() : valid_(false) {
36 ResourceBundle &rb = ResourceBundle::GetSharedInstance();
37 bitmap_ = *rb.GetBitmapNamed(IDR_DEFAULT_FAVICON);
38}
39
[email protected]965524b2009-04-04 21:32:4040
41NavigationEntry::NavigationEntry()
42 : unique_id_(GetUniqueID()),
[email protected]965524b2009-04-04 21:32:4043 site_instance_(NULL),
44 page_type_(NORMAL_PAGE),
[email protected]a1b508bd2009-12-17 20:40:4345 update_virtual_url_with_url_(false),
[email protected]965524b2009-04-04 21:32:4046 page_id_(-1),
47 transition_type_(PageTransition::LINK),
48 has_post_data_(false),
[email protected]5e369672009-11-03 23:48:3049 restore_type_(RESTORE_NONE) {
[email protected]965524b2009-04-04 21:32:4050}
51
[email protected]b680ad22009-04-15 23:19:4252NavigationEntry::NavigationEntry(SiteInstance* instance,
initial.commit09911bf2008-07-26 23:55:2953 int page_id,
54 const GURL& url,
[email protected]c0588052008-10-27 23:01:5055 const GURL& referrer,
[email protected]4c4d8d22009-03-04 05:29:2756 const string16& title,
initial.commit09911bf2008-07-26 23:55:2957 PageTransition::Type transition_type)
[email protected]1e5645ff2008-08-27 18:09:0758 : unique_id_(GetUniqueID()),
initial.commit09911bf2008-07-26 23:55:2959 site_instance_(instance),
[email protected]1e5645ff2008-08-27 18:09:0760 page_type_(NORMAL_PAGE),
initial.commit09911bf2008-07-26 23:55:2961 url_(url),
[email protected]c0588052008-10-27 23:01:5062 referrer_(referrer),
[email protected]38178a42009-12-17 18:58:3263 update_virtual_url_with_url_(false),
initial.commit09911bf2008-07-26 23:55:2964 title_(title),
[email protected]1e5645ff2008-08-27 18:09:0765 page_id_(page_id),
initial.commit09911bf2008-07-26 23:55:2966 transition_type_(transition_type),
initial.commit09911bf2008-07-26 23:55:2967 has_post_data_(false),
[email protected]5e369672009-11-03 23:48:3068 restore_type_(RESTORE_NONE) {
initial.commit09911bf2008-07-26 23:55:2969}
[email protected]3d627bbc2008-10-23 20:49:0770
[email protected]1db6ff152009-10-12 15:32:0771NavigationEntry::~NavigationEntry() {
72}
73
74void NavigationEntry::set_site_instance(SiteInstance* site_instance) {
75 site_instance_ = site_instance;
76}
77
[email protected]4c4d8d22009-03-04 05:29:2778const 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]ebe89e062009-08-13 23:16:5490 // Use the virtual URL first if any, and fall back on using the real URL.
[email protected]4c4d8d22009-03-04 05:29:2791 std::wstring languages;
92 if (navigation_controller) {
[email protected]ddd231e2010-06-29 20:35:1993 languages = UTF8ToWide(navigation_controller->profile()->GetPrefs()->
94 GetString(prefs::kAcceptLanguages));
[email protected]4c4d8d22009-03-04 05:29:2795 }
[email protected]26943602010-04-01 05:51:5796
97 std::wstring title;
98 std::wstring elided_title;
[email protected]ebe89e062009-08-13 23:16:5499 if (!virtual_url_.is_empty()) {
[email protected]26943602010-04-01 05:51:57100 title = net::FormatUrl(virtual_url_, languages);
[email protected]4c4d8d22009-03-04 05:29:27101 } else if (!url_.is_empty()) {
[email protected]26943602010-04-01 05:51:57102 title = net::FormatUrl(url_, languages);
[email protected]4c4d8d22009-03-04 05:29:27103 }
[email protected]26943602010-04-01 05:51:57104 ElideString(title, chrome::kMaxTitleChars, &elided_title);
105 cached_display_title_ = WideToUTF16Hack(elided_title);
[email protected]4c4d8d22009-03-04 05:29:27106 return cached_display_title_;
[email protected]97f756b2008-12-16 04:06:24107}
[email protected]6de74452009-02-25 18:04:59108
109bool NavigationEntry::IsViewSourceMode() const {
[email protected]ebe89e062009-08-13 23:16:54110 return virtual_url_.SchemeIs(chrome::kViewSourceScheme);
[email protected]6de74452009-02-25 18:04:59111}