blob: b2235bca6a04dd8efde7c315fe3049ac00e0087f [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]4c4d8d22009-03-04 05:29:278#include "chrome/browser/tab_contents/navigation_controller.h"
[email protected]4c4d8d22009-03-04 05:29:279#include "chrome/common/pref_names.h"
10#include "chrome/common/pref_service.h"
[email protected]6de74452009-02-25 18:04:5911#include "chrome/common/url_constants.h"
[email protected]074f10562009-05-21 22:40:0512#include "grit/app_resources.h"
[email protected]f9fe8632009-05-22 18:15:2413#include "net/base/net_util.h"
initial.commit09911bf2008-07-26 23:55:2914
[email protected]1e5645ff2008-08-27 18:09:0715// Use this to get a new unique ID for a NavigationEntry during construction.
16// The returned ID is guaranteed to be nonzero (which is the "no ID" indicator).
17static int GetUniqueID() {
18 static int unique_id_counter = 0;
19 return ++unique_id_counter;
20}
initial.commit09911bf2008-07-26 23:55:2921
[email protected]eb34392b2008-08-19 15:42:2022NavigationEntry::SSLStatus::SSLStatus()
23 : security_style_(SECURITY_STYLE_UNKNOWN),
24 cert_id_(0),
25 cert_status_(0),
26 security_bits_(-1),
27 content_status_(NORMAL_CONTENT) {
28}
29
[email protected]1e5645ff2008-08-27 18:09:0730NavigationEntry::FaviconStatus::FaviconStatus() : valid_(false) {
31 ResourceBundle &rb = ResourceBundle::GetSharedInstance();
32 bitmap_ = *rb.GetBitmapNamed(IDR_DEFAULT_FAVICON);
33}
34
[email protected]965524b2009-04-04 21:32:4035
36NavigationEntry::NavigationEntry()
37 : unique_id_(GetUniqueID()),
[email protected]965524b2009-04-04 21:32:4038 site_instance_(NULL),
39 page_type_(NORMAL_PAGE),
40 page_id_(-1),
41 transition_type_(PageTransition::LINK),
42 has_post_data_(false),
43 restored_(false) {
44}
45
[email protected]b680ad22009-04-15 23:19:4246NavigationEntry::NavigationEntry(SiteInstance* instance,
initial.commit09911bf2008-07-26 23:55:2947 int page_id,
48 const GURL& url,
[email protected]c0588052008-10-27 23:01:5049 const GURL& referrer,
[email protected]4c4d8d22009-03-04 05:29:2750 const string16& title,
initial.commit09911bf2008-07-26 23:55:2951 PageTransition::Type transition_type)
[email protected]1e5645ff2008-08-27 18:09:0752 : unique_id_(GetUniqueID()),
initial.commit09911bf2008-07-26 23:55:2953 site_instance_(instance),
[email protected]1e5645ff2008-08-27 18:09:0754 page_type_(NORMAL_PAGE),
initial.commit09911bf2008-07-26 23:55:2955 url_(url),
[email protected]c0588052008-10-27 23:01:5056 referrer_(referrer),
initial.commit09911bf2008-07-26 23:55:2957 title_(title),
[email protected]1e5645ff2008-08-27 18:09:0758 page_id_(page_id),
initial.commit09911bf2008-07-26 23:55:2959 transition_type_(transition_type),
initial.commit09911bf2008-07-26 23:55:2960 has_post_data_(false),
61 restored_(false) {
initial.commit09911bf2008-07-26 23:55:2962}
[email protected]3d627bbc2008-10-23 20:49:0763
[email protected]4c4d8d22009-03-04 05:29:2764const string16& NavigationEntry::GetTitleForDisplay(
65 const NavigationController* navigation_controller) {
66 // Most pages have real titles. Don't even bother caching anything if this is
67 // the case.
68 if (!title_.empty())
69 return title_;
70
71 // More complicated cases will use the URLs as the title. This result we will
72 // cache since it's more complicated to compute.
73 if (!cached_display_title_.empty())
74 return cached_display_title_;
75
76 // Use the display URL first if any, and fall back on using the real URL.
77 std::wstring languages;
78 if (navigation_controller) {
79 languages = navigation_controller->profile()->GetPrefs()->GetString(
80 prefs::kAcceptLanguages);
81 }
82 if (!display_url_.is_empty()) {
[email protected]f9fe8632009-05-22 18:15:2483 cached_display_title_ = WideToUTF16Hack(net::FormatUrl(
84 display_url_, languages));
[email protected]4c4d8d22009-03-04 05:29:2785 } else if (!url_.is_empty()) {
[email protected]f9fe8632009-05-22 18:15:2486 cached_display_title_ = WideToUTF16Hack(net::FormatUrl(url_, languages));
[email protected]4c4d8d22009-03-04 05:29:2787 }
88 return cached_display_title_;
[email protected]97f756b2008-12-16 04:06:2489}
[email protected]6de74452009-02-25 18:04:5990
91bool NavigationEntry::IsViewSourceMode() const {
92 return display_url_.SchemeIs(chrome::kViewSourceScheme);
93}