blob: c8db03762799091cb04a67d45ff1b9dc3c623b33 [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]1db6ff152009-10-12 15:32:078#include "base/string_util.h"
[email protected]ce560f82009-06-03 09:39:449#include "chrome/browser/profile.h"
[email protected]1db6ff152009-10-12 15:32:0710#include "chrome/browser/renderer_host/site_instance.h"
[email protected]4c4d8d22009-03-04 05:29:2711#include "chrome/browser/tab_contents/navigation_controller.h"
[email protected]4c4d8d22009-03-04 05:29:2712#include "chrome/common/pref_names.h"
13#include "chrome/common/pref_service.h"
[email protected]6de74452009-02-25 18:04:5914#include "chrome/common/url_constants.h"
[email protected]074f10562009-05-21 22:40:0515#include "grit/app_resources.h"
[email protected]f9fe8632009-05-22 18:15:2416#include "net/base/net_util.h"
initial.commit09911bf2008-07-26 23:55:2917
[email protected]1e5645ff2008-08-27 18:09:0718// 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).
20static int GetUniqueID() {
21 static int unique_id_counter = 0;
22 return ++unique_id_counter;
23}
initial.commit09911bf2008-07-26 23:55:2924
[email protected]eb34392b2008-08-19 15:42:2025NavigationEntry::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]1e5645ff2008-08-27 18:09:0733NavigationEntry::FaviconStatus::FaviconStatus() : valid_(false) {
34 ResourceBundle &rb = ResourceBundle::GetSharedInstance();
35 bitmap_ = *rb.GetBitmapNamed(IDR_DEFAULT_FAVICON);
36}
37
[email protected]965524b2009-04-04 21:32:4038
39NavigationEntry::NavigationEntry()
40 : unique_id_(GetUniqueID()),
[email protected]965524b2009-04-04 21:32:4041 site_instance_(NULL),
42 page_type_(NORMAL_PAGE),
43 page_id_(-1),
44 transition_type_(PageTransition::LINK),
45 has_post_data_(false),
[email protected]5e369672009-11-03 23:48:3046 restore_type_(RESTORE_NONE) {
[email protected]965524b2009-04-04 21:32:4047}
48
[email protected]b680ad22009-04-15 23:19:4249NavigationEntry::NavigationEntry(SiteInstance* instance,
initial.commit09911bf2008-07-26 23:55:2950 int page_id,
51 const GURL& url,
[email protected]c0588052008-10-27 23:01:5052 const GURL& referrer,
[email protected]4c4d8d22009-03-04 05:29:2753 const string16& title,
initial.commit09911bf2008-07-26 23:55:2954 PageTransition::Type transition_type)
[email protected]1e5645ff2008-08-27 18:09:0755 : unique_id_(GetUniqueID()),
initial.commit09911bf2008-07-26 23:55:2956 site_instance_(instance),
[email protected]1e5645ff2008-08-27 18:09:0757 page_type_(NORMAL_PAGE),
initial.commit09911bf2008-07-26 23:55:2958 url_(url),
[email protected]c0588052008-10-27 23:01:5059 referrer_(referrer),
[email protected]38178a42009-12-17 18:58:3260 update_virtual_url_with_url_(false),
initial.commit09911bf2008-07-26 23:55:2961 title_(title),
[email protected]1e5645ff2008-08-27 18:09:0762 page_id_(page_id),
initial.commit09911bf2008-07-26 23:55:2963 transition_type_(transition_type),
initial.commit09911bf2008-07-26 23:55:2964 has_post_data_(false),
[email protected]5e369672009-11-03 23:48:3065 restore_type_(RESTORE_NONE) {
initial.commit09911bf2008-07-26 23:55:2966}
[email protected]3d627bbc2008-10-23 20:49:0767
[email protected]1db6ff152009-10-12 15:32:0768NavigationEntry::~NavigationEntry() {
69}
70
71void NavigationEntry::set_site_instance(SiteInstance* site_instance) {
72 site_instance_ = site_instance;
73}
74
[email protected]4c4d8d22009-03-04 05:29:2775const 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]ebe89e062009-08-13 23:16:5487 // Use the virtual URL first if any, and fall back on using the real URL.
[email protected]4c4d8d22009-03-04 05:29:2788 std::wstring languages;
89 if (navigation_controller) {
90 languages = navigation_controller->profile()->GetPrefs()->GetString(
91 prefs::kAcceptLanguages);
92 }
[email protected]ebe89e062009-08-13 23:16:5493 if (!virtual_url_.is_empty()) {
[email protected]f9fe8632009-05-22 18:15:2494 cached_display_title_ = WideToUTF16Hack(net::FormatUrl(
[email protected]ebe89e062009-08-13 23:16:5495 virtual_url_, languages));
[email protected]4c4d8d22009-03-04 05:29:2796 } else if (!url_.is_empty()) {
[email protected]f9fe8632009-05-22 18:15:2497 cached_display_title_ = WideToUTF16Hack(net::FormatUrl(url_, languages));
[email protected]4c4d8d22009-03-04 05:29:2798 }
99 return cached_display_title_;
[email protected]97f756b2008-12-16 04:06:24100}
[email protected]6de74452009-02-25 18:04:59101
102bool NavigationEntry::IsViewSourceMode() const {
[email protected]ebe89e062009-08-13 23:16:54103 return virtual_url_.SchemeIs(chrome::kViewSourceScheme);
[email protected]6de74452009-02-25 18:04:59104}