summaryrefslogtreecommitdiffstats
path: root/chrome/browser/navigation_entry.h
blob: 10006cc09ae600974d692546a44fea00bd810e75 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_NAVIGATION_ENTRY_H__
#define CHROME_BROWSER_NAVIGATION_ENTRY_H__

#include "base/basictypes.h"
#include "base/scoped_ptr.h"
#include "chrome/app/theme/theme_resources.h"
#include "chrome/browser/security_style.h"
#include "chrome/browser/site_instance.h"
#include "chrome/browser/tab_contents_type.h"
#include "chrome/common/page_transition_types.h"
#include "googleurl/src/gurl.h"
#include "skia/include/SkBitmap.h"

////////////////////////////////////////////////////////////////////////////////
//
// NavigationEntry class
//
// A NavigationEntry is a data structure that captures all the information
// required to recreate a browsing state. This includes some opaque binary
// state as provided by the TabContents as well as some clear text title and
// URL which is used for our user interface.
//
////////////////////////////////////////////////////////////////////////////////
class NavigationEntry {
 public:
  // Collects the SSL information for this NavigationEntry.
  class SSLStatus {
   public:
    // Flags used for the page security content status.
    enum ContentStatusFlags {
      NORMAL_CONTENT = 0,       // Neither of the 2 cases below.
      MIXED_CONTENT  = 1 << 0,  // https page containing http resources.
      UNSAFE_CONTENT = 1 << 1   // https page containing broken https resources.
    };

    SSLStatus();

    void set_security_style(SecurityStyle security_style) {
      security_style_ = security_style;
    }
    SecurityStyle security_style() const {
      return security_style_;
    }

    void set_cert_id(int ssl_cert_id) {
      cert_id_ = ssl_cert_id;
    }
    int cert_id() const {
      return cert_id_;
    }

    void set_cert_status(int ssl_cert_status) {
      cert_status_ = ssl_cert_status;
    }
    int cert_status() const {
      return cert_status_;
    }

    void set_security_bits(int security_bits) {
      security_bits_ = security_bits;
    }
    int security_bits() const {
      return security_bits_;
    }

    // Mixed content means that this page which is served over https contains
    // http sub-resources.
    void set_has_mixed_content() {
      content_status_ |= MIXED_CONTENT;
    }
    bool has_mixed_content() const {
      return (content_status_ & MIXED_CONTENT) != 0;
    }

    // Unsafe content means that this page is served over https but contains
    // https sub-resources with cert errors.
    void set_has_unsafe_content() {
      content_status_ |= UNSAFE_CONTENT;
    }
    bool has_unsafe_content() const {
      return (content_status_ & UNSAFE_CONTENT) != 0;
    }

    // Raw accessors for all the content status flags. This is used by the UI
    // tests for checking and for certain copying. Use the per-status functions
    // for normal usage.
    void set_content_status(int content_status) {
      content_status_ = content_status;
    }
    int content_status() const {
      return content_status_;
    }

   private:
    SecurityStyle security_style_;
    int cert_id_;
    int cert_status_;
    int security_bits_;
    int content_status_;  // A combination of any of the ContentStatusFlags.

    // Copy and assignment is explicitly allowed for this class.
  };

  // The type of the page an entry corresponds to.  Used by ui tests.
  enum PageType {
    NORMAL_PAGE = 0,
    ERROR_PAGE,
    INTERSTITIAL_PAGE
  };

  // Use this to get a new unique ID during construction.
  static int GetUniqueID();

  // Create a new NavigationEntry.
  explicit NavigationEntry(TabContentsType type);
  NavigationEntry(TabContentsType type,
                  SiteInstance* instance,
                  int page_id,
                  const GURL& url,
                  const std::wstring& title,
                  PageTransition::Type transition_type);

  ~NavigationEntry() {
  }

  // Return the TabContents type required to display this entry. Immutable
  // because a tab can never change its type.
  TabContentsType GetType() const { return type_; }

  // Accessors for the unique ID of this entry.  A unique ID is preserved across
  // commits and redirects, which means that sometimes a NavigationEntry's
  // unique ID needs to be set (e.g. when creating a committed entry to
  // correspond to a to-be-deleted pending entry, the pending entry's ID must be
  // copied).
  int unique_id() const { return unique_id_; }
  void set_unique_id(int unique_id) { unique_id_ = unique_id; }

  void SetSiteInstance(SiteInstance* site_instance);
  SiteInstance* site_instance() const { return site_instance_; }

  void SetURL(const GURL& url) { url_ = url; }
  const GURL& GetURL() const { return url_; }

  // All the SSL flags.
  const SSLStatus& ssl() const {
    return ssl_;
  }
  SSLStatus& ssl() {
    return ssl_;
  }

  // Set / Get the page type.
  void  SetPageType(PageType page_type) { page_type_ = page_type; }
  PageType GetPageType() const { return page_type_; }

  void SetDisplayURL(const GURL& url) {
    display_url_ = (url == url_) ? GURL() : url;
  }
  bool HasDisplayURL() const { return !display_url_.is_empty(); }
  const GURL& GetDisplayURL() const {
    return display_url_.is_empty() ? url_ : display_url_;
  }

  void SetTitle(const std::wstring& title) { title_ = title; }
  const std::wstring& GetTitle() const { return title_; }

  // WARNING: This state is saved to the database and used to restore previous
  // states. If you write a custom TabContents and provide your own state make
  // sure you have the ability to modify the format in the future while being
  // able to deal with older versions.
  void SetContentState(const std::string& state);
  const std::string& GetContentState() const { return state_; }

  void SetPageID(int page_id) { page_id_ = page_id; }
  int32 GetPageID() const { return page_id_; }

  void SetTransitionType(PageTransition::Type transition_type) {
    transition_type_ = transition_type;
  }
  PageTransition::Type GetTransitionType() const { return transition_type_; }

  // Sets the URL of the favicon.
  void SetFavIconURL(const GURL& favicon_url) { favicon_url_ = favicon_url; }

  // Returns the URL of the favicon. This may be empty if we don't know the
  // favicon, or didn't succesfully load it before navigating to another page.
  const GURL& GetFavIconURL() const { return favicon_url_; }

  // Sets the favicon for the page.
  void SetFavIcon(const SkBitmap& favicon) { favicon_ = favicon; }

  // Returns the favicon for the page. If the icon has not been explicitly set,
  // or is empty, this returns the default favicon.
  // As loading the favicon happens asynchronously, it is possible for this to
  // return the default favicon even though the page has a favicon other than
  // the default.
  const SkBitmap& GetFavIcon() const { return favicon_; }

  // Whether the favicon is valid. The favicon is valid if it represents the
  // true favicon of the site.
  void SetValidFavIcon(bool valid_fav_icon) {
    valid_fav_icon_ = valid_fav_icon;
  }
  bool IsValidFavIcon() const { return valid_fav_icon_; }

  void SetUserTypedURL(const GURL& user_typed_url) {
    user_typed_url_ = user_typed_url;
  }
  const GURL& GetUserTypedURL() const { return user_typed_url_; }

  // If the user typed url is valid it is returned, otherwise url is returned.
  const GURL& GetUserTypedURLOrURL() const {
    return user_typed_url_.is_valid() ? user_typed_url_ : url_;
  }

  bool HasPostData() const { return has_post_data_; }

  void SetHasPostData(bool has_post_data) { has_post_data_ = has_post_data; }

  // See comment above field.
  void set_restored(bool restored) { restored_ = restored; }
  bool restored() const { return restored_; }

 private:
  // WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
  // Session/Tab restore save portions of this class so that it can be recreated
  // later. If you add a new field that needs to be persisted you'll have to
  // update SessionService/TabRestoreService appropriately.
  // WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING

  // Unique IDs only really need to distinguish the various existing entries
  // from each other, rather than be unique over all time; so it doesn't matter
  // if this eventually wraps.
  static int unique_id_counter_;

  TabContentsType type_;

  int unique_id_;

  // If this entry is a TAB_CONTENTS_WEB, then keep a pointer to the
  // SiteInstance that it belongs to.  This allows us to reuse the same
  // process if the user goes Back across site boundaries.  If the process is
  // gone by the time the user clicks Back, a new process will be created.
  // This is NULL if this entry's type is not TAB_CONTENT_WEB.
  scoped_refptr<SiteInstance> site_instance_;

  // Describes the current page that the tab represents. This is not relevant
  // for all tab contents types.
  int32 page_id_;

  GURL url_;
  // The URL the user typed in.  May be invalid.
  GURL user_typed_url_;
  std::wstring title_;
  GURL favicon_url_;
  GURL display_url_;

  std::string state_;

  // The favorite icon for this entry.
  SkBitmap favicon_;

  PageType page_type_;

  SSLStatus ssl_;

  bool valid_fav_icon_;

  // True if this navigation needs to send post data in order to be displayed
  // properly.
  bool has_post_data_;

  // The transition type indicates what the user did to move to this page from
  // the previous page.
  PageTransition::Type transition_type_;

  // Was this entry created from session/tab restore? If so this is true and
  // gets set to false once we navigate to it
  // (NavigationControllerBase::DidNavigateToEntry).
  bool restored_;
};

#endif  //  CHROME_BROWSER_NAVIGATION_ENTRY_H__