OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef CHROME_BROWSER_TAB_CONTENTS_NAVIGATION_ENTRY_H_ | 5 #ifndef CHROME_BROWSER_TAB_CONTENTS_NAVIGATION_ENTRY_H_ |
6 #define CHROME_BROWSER_TAB_CONTENTS_NAVIGATION_ENTRY_H_ | 6 #define CHROME_BROWSER_TAB_CONTENTS_NAVIGATION_ENTRY_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include <string> | 9 // TODO(jam): remove this file when all files have been converted. |
10 | 10 #include "content/browser/tab_contents/navigation_entry.h" |
11 #include "base/basictypes.h" | |
12 #include "base/ref_counted.h" | |
13 #include "chrome/common/page_type.h" | |
14 #include "chrome/common/page_transition_types.h" | |
15 #include "chrome/common/security_style.h" | |
16 #include "googleurl/src/gurl.h" | |
17 #include "third_party/skia/include/core/SkBitmap.h" | |
18 | |
19 class SiteInstance; | |
20 | |
21 //////////////////////////////////////////////////////////////////////////////// | |
22 // | |
23 // NavigationEntry class | |
24 // | |
25 // A NavigationEntry is a data structure that captures all the information | |
26 // required to recreate a browsing state. This includes some opaque binary | |
27 // state as provided by the TabContents as well as some clear text title and | |
28 // URL which is used for our user interface. | |
29 // | |
30 //////////////////////////////////////////////////////////////////////////////// | |
31 class NavigationEntry { | |
32 public: | |
33 // SSL ----------------------------------------------------------------------- | |
34 | |
35 // Collects the SSL information for this NavigationEntry. | |
36 class SSLStatus { | |
37 public: | |
38 // Flags used for the page security content status. | |
39 enum ContentStatusFlags { | |
40 // HTTP page, or HTTPS page with no insecure content. | |
41 NORMAL_CONTENT = 0, | |
42 | |
43 // HTTPS page containing "displayed" HTTP resources (e.g. images, CSS). | |
44 DISPLAYED_INSECURE_CONTENT = 1 << 0, | |
45 | |
46 // HTTPS page containing "executed" HTTP resources (i.e. script). | |
47 // Also currently used for HTTPS page containing broken-HTTPS resources; | |
48 // this is wrong and should be fixed (see comments in | |
49 // SSLPolicy::OnRequestStarted()). | |
50 RAN_INSECURE_CONTENT = 1 << 1, | |
51 }; | |
52 | |
53 SSLStatus(); | |
54 | |
55 bool Equals(const SSLStatus& status) const { | |
56 return security_style_ == status.security_style_ && | |
57 cert_id_ == status.cert_id_ && | |
58 cert_status_ == status.cert_status_ && | |
59 security_bits_ == status.security_bits_ && | |
60 content_status_ == status.content_status_; | |
61 } | |
62 | |
63 void set_security_style(SecurityStyle security_style) { | |
64 security_style_ = security_style; | |
65 } | |
66 SecurityStyle security_style() const { | |
67 return security_style_; | |
68 } | |
69 | |
70 void set_cert_id(int ssl_cert_id) { | |
71 cert_id_ = ssl_cert_id; | |
72 } | |
73 int cert_id() const { | |
74 return cert_id_; | |
75 } | |
76 | |
77 void set_cert_status(int ssl_cert_status) { | |
78 cert_status_ = ssl_cert_status; | |
79 } | |
80 int cert_status() const { | |
81 return cert_status_; | |
82 } | |
83 | |
84 void set_security_bits(int security_bits) { | |
85 security_bits_ = security_bits; | |
86 } | |
87 int security_bits() const { | |
88 return security_bits_; | |
89 } | |
90 | |
91 void set_displayed_insecure_content() { | |
92 content_status_ |= DISPLAYED_INSECURE_CONTENT; | |
93 } | |
94 bool displayed_insecure_content() const { | |
95 return (content_status_ & DISPLAYED_INSECURE_CONTENT) != 0; | |
96 } | |
97 | |
98 void set_ran_insecure_content() { | |
99 content_status_ |= RAN_INSECURE_CONTENT; | |
100 } | |
101 bool ran_insecure_content() const { | |
102 return (content_status_ & RAN_INSECURE_CONTENT) != 0; | |
103 } | |
104 | |
105 void set_connection_status(int connection_status) { | |
106 connection_status_ = connection_status; | |
107 } | |
108 int connection_status() const { | |
109 return connection_status_; | |
110 } | |
111 | |
112 // Raw accessors for all the content status flags. This contains a | |
113 // combination of any of the ContentStatusFlags defined above. It is used | |
114 // by some tests for checking and for certain copying. Use the per-status | |
115 // functions for normal usage. | |
116 void set_content_status(int content_status) { | |
117 content_status_ = content_status; | |
118 } | |
119 int content_status() const { | |
120 return content_status_; | |
121 } | |
122 | |
123 private: | |
124 // See the accessors above for descriptions. | |
125 SecurityStyle security_style_; | |
126 int cert_id_; | |
127 int cert_status_; | |
128 int security_bits_; | |
129 int connection_status_; | |
130 int content_status_; | |
131 | |
132 // Copy and assignment is explicitly allowed for this class. | |
133 }; | |
134 | |
135 // Favicon ------------------------------------------------------------------- | |
136 | |
137 // Collects the favicon related information for a NavigationEntry. | |
138 class FaviconStatus { | |
139 public: | |
140 FaviconStatus(); | |
141 | |
142 // Indicates whether we've gotten an official favicon for the page, or are | |
143 // just using the default favicon. | |
144 void set_is_valid(bool is_valid) { | |
145 valid_ = is_valid; | |
146 } | |
147 bool is_valid() const { | |
148 return valid_; | |
149 } | |
150 | |
151 // The URL of the favicon which was used to load it off the web. | |
152 void set_url(const GURL& favicon_url) { | |
153 url_ = favicon_url; | |
154 } | |
155 const GURL& url() const { | |
156 return url_; | |
157 } | |
158 | |
159 // The favicon bitmap for the page. If the favicon has not been explicitly | |
160 // set or it empty, it will return the default favicon. Note that this is | |
161 // loaded asynchronously, so even if the favicon URL is valid we may return | |
162 // the default favicon if we haven't gotten the data yet. | |
163 void set_bitmap(const SkBitmap& bitmap) { | |
164 bitmap_ = bitmap; | |
165 } | |
166 const SkBitmap& bitmap() const { | |
167 return bitmap_; | |
168 } | |
169 | |
170 private: | |
171 // See the accessors above for descriptions. | |
172 bool valid_; | |
173 GURL url_; | |
174 SkBitmap bitmap_; | |
175 | |
176 // Copy and assignment is explicitly allowed for this class. | |
177 }; | |
178 | |
179 // --------------------------------------------------------------------------- | |
180 | |
181 NavigationEntry(); | |
182 NavigationEntry(SiteInstance* instance, | |
183 int page_id, | |
184 const GURL& url, | |
185 const GURL& referrer, | |
186 const string16& title, | |
187 PageTransition::Type transition_type); | |
188 ~NavigationEntry(); | |
189 | |
190 // Page-related stuff -------------------------------------------------------- | |
191 | |
192 // A unique ID is preserved across commits and redirects, which means that | |
193 // sometimes a NavigationEntry's unique ID needs to be set (e.g. when | |
194 // creating a committed entry to correspond to a to-be-deleted pending entry, | |
195 // the pending entry's ID must be copied). | |
196 void set_unique_id(int unique_id) { | |
197 unique_id_ = unique_id; | |
198 } | |
199 int unique_id() const { | |
200 return unique_id_; | |
201 } | |
202 | |
203 // The SiteInstance tells us how to share sub-processes when the tab type is | |
204 // TAB_CONTENTS_WEB. This will be NULL otherwise. This is a reference counted | |
205 // pointer to a shared site instance. | |
206 // | |
207 // Note that the SiteInstance should usually not be changed after it is set, | |
208 // but this may happen if the NavigationEntry was cloned and needs to use a | |
209 // different SiteInstance. | |
210 void set_site_instance(SiteInstance* site_instance); | |
211 SiteInstance* site_instance() const { | |
212 return site_instance_; | |
213 } | |
214 | |
215 // The page type tells us if this entry is for an interstitial or error page. | |
216 // See the PageType enum above. | |
217 void set_page_type(PageType page_type) { | |
218 page_type_ = page_type; | |
219 } | |
220 PageType page_type() const { | |
221 return page_type_; | |
222 } | |
223 | |
224 // The actual URL of the page. For some about pages, this may be a scary | |
225 // data: URL or something like that. Use virtual_url() below for showing to | |
226 // the user. | |
227 void set_url(const GURL& url) { | |
228 url_ = url; | |
229 cached_display_title_.clear(); | |
230 } | |
231 const GURL& url() const { | |
232 return url_; | |
233 } | |
234 | |
235 // The referring URL. Can be empty. | |
236 void set_referrer(const GURL& referrer) { | |
237 referrer_ = referrer; | |
238 } | |
239 const GURL& referrer() const { | |
240 return referrer_; | |
241 } | |
242 | |
243 // The virtual URL, when nonempty, will override the actual URL of the page | |
244 // when we display it to the user. This allows us to have nice and friendly | |
245 // URLs that the user sees for things like about: URLs, but actually feed | |
246 // the renderer a data URL that results in the content loading. | |
247 // | |
248 // virtual_url() will return the URL to display to the user in all cases, so | |
249 // if there is no overridden display URL, it will return the actual one. | |
250 void set_virtual_url(const GURL& url) { | |
251 virtual_url_ = (url == url_) ? GURL() : url; | |
252 cached_display_title_.clear(); | |
253 } | |
254 bool has_virtual_url() const { | |
255 return !virtual_url_.is_empty(); | |
256 } | |
257 const GURL& virtual_url() const { | |
258 return virtual_url_.is_empty() ? url_ : virtual_url_; | |
259 } | |
260 | |
261 bool update_virtual_url_with_url() const { | |
262 return update_virtual_url_with_url_; | |
263 } | |
264 void set_update_virtual_url_with_url(bool update) { | |
265 update_virtual_url_with_url_ = update; | |
266 } | |
267 | |
268 // The title as set by the page. This will be empty if there is no title set. | |
269 // The caller is responsible for detecting when there is no title and | |
270 // displaying the appropriate "Untitled" label if this is being displayed to | |
271 // the user. | |
272 void set_title(const string16& title) { | |
273 title_ = title; | |
274 cached_display_title_.clear(); | |
275 } | |
276 const string16& title() const { | |
277 return title_; | |
278 } | |
279 | |
280 // The favicon data and tracking information. See FaviconStatus above. | |
281 const FaviconStatus& favicon() const { | |
282 return favicon_; | |
283 } | |
284 FaviconStatus& favicon() { | |
285 return favicon_; | |
286 } | |
287 | |
288 // Content state is an opaque blob created by WebKit that represents the | |
289 // state of the page. This includes form entries and scroll position for each | |
290 // frame. We store it so that we can supply it back to WebKit to restore form | |
291 // state properly when the user goes back and forward. | |
292 // | |
293 // WARNING: This state is saved to the file and used to restore previous | |
294 // states. If the format is modified in the future, we should still be able to | |
295 // deal with older versions. | |
296 void set_content_state(const std::string& state) { | |
297 content_state_ = state; | |
298 } | |
299 const std::string& content_state() const { | |
300 return content_state_; | |
301 } | |
302 | |
303 // Describes the current page that the tab represents. For web pages | |
304 // (TAB_CONTENTS_WEB) this is the ID that the renderer generated for the page | |
305 // and is how we can tell new versus renavigations. | |
306 void set_page_id(int page_id) { | |
307 page_id_ = page_id; | |
308 } | |
309 int32 page_id() const { | |
310 return page_id_; | |
311 } | |
312 | |
313 // All the SSL flags and state. See SSLStatus above. | |
314 const SSLStatus& ssl() const { | |
315 return ssl_; | |
316 } | |
317 SSLStatus& ssl() { | |
318 return ssl_; | |
319 } | |
320 | |
321 // Page-related helpers ------------------------------------------------------ | |
322 | |
323 // Returns the title to be displayed on the tab. This could be the title of | |
324 // the page if it is available or the URL. |languages| is the list of | |
325 // accpeted languages (e.g., prefs::kAcceptLanguages) or empty if proper | |
326 // URL formatting isn't needed (e.g., unit tests). | |
327 const string16& GetTitleForDisplay(const std::string& languages); | |
328 | |
329 // Returns true if the current tab is in view source mode. This will be false | |
330 // if there is no navigation. | |
331 bool IsViewSourceMode() const; | |
332 | |
333 // Tracking stuff ------------------------------------------------------------ | |
334 | |
335 // The transition type indicates what the user did to move to this page from | |
336 // the previous page. | |
337 void set_transition_type(PageTransition::Type transition_type) { | |
338 transition_type_ = transition_type; | |
339 } | |
340 PageTransition::Type transition_type() const { | |
341 return transition_type_; | |
342 } | |
343 | |
344 // The user typed URL was the URL that the user initiated the navigation | |
345 // with, regardless of any redirects. This is used to generate keywords, for | |
346 // example, based on "what the user thinks the site is called" rather than | |
347 // what it's actually called. For example, if the user types "foo.com", that | |
348 // may redirect somewhere arbitrary like "bar.com/foo", and we want to use | |
349 // the name that the user things of the site as having. | |
350 // | |
351 // This URL will be is_empty() if the URL was navigated to some other way. | |
352 // Callers should fall back on using the regular or display URL in this case. | |
353 void set_user_typed_url(const GURL& user_typed_url) { | |
354 user_typed_url_ = user_typed_url; | |
355 } | |
356 const GURL& user_typed_url() const { | |
357 return user_typed_url_; | |
358 } | |
359 | |
360 // Post data is form data that was posted to get to this page. The data will | |
361 // have to be reposted to reload the page properly. This flag indicates | |
362 // whether the page had post data. | |
363 // | |
364 // The actual post data is stored in the content_state and is extracted by | |
365 // WebKit to actually make the request. | |
366 void set_has_post_data(bool has_post_data) { | |
367 has_post_data_ = has_post_data; | |
368 } | |
369 bool has_post_data() const { | |
370 return has_post_data_; | |
371 } | |
372 | |
373 // Enumerations of the possible restore types. | |
374 enum RestoreType { | |
375 // The entry has been restored is from the last session. | |
376 RESTORE_LAST_SESSION, | |
377 | |
378 // The entry has been restored from the current session. This is used when | |
379 // the user issues 'reopen closed tab'. | |
380 RESTORE_CURRENT_SESSION, | |
381 | |
382 // The entry was not restored. | |
383 RESTORE_NONE | |
384 }; | |
385 | |
386 // The RestoreType for this entry. This is set if the entry was retored. This | |
387 // is set to RESTORE_NONE once the entry is loaded. | |
388 void set_restore_type(RestoreType type) { | |
389 restore_type_ = type; | |
390 } | |
391 RestoreType restore_type() const { | |
392 return restore_type_; | |
393 } | |
394 | |
395 private: | |
396 // WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING | |
397 // Session/Tab restore save portions of this class so that it can be recreated | |
398 // later. If you add a new field that needs to be persisted you'll have to | |
399 // update SessionService/TabRestoreService appropriately. | |
400 // WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING | |
401 | |
402 // See the accessors above for descriptions. | |
403 int unique_id_; | |
404 scoped_refptr<SiteInstance> site_instance_; | |
405 PageType page_type_; | |
406 GURL url_; | |
407 GURL referrer_; | |
408 GURL virtual_url_; | |
409 bool update_virtual_url_with_url_; | |
410 string16 title_; | |
411 FaviconStatus favicon_; | |
412 std::string content_state_; | |
413 int32 page_id_; | |
414 SSLStatus ssl_; | |
415 PageTransition::Type transition_type_; | |
416 GURL user_typed_url_; | |
417 bool has_post_data_; | |
418 RestoreType restore_type_; | |
419 | |
420 // This is a cached version of the result of GetTitleForDisplay. It prevents | |
421 // us from having to do URL formatting on the URL evey time the title is | |
422 // displayed. When the URL, virtual URL, or title is set, this should be | |
423 // cleared to force a refresh. | |
424 string16 cached_display_title_; | |
425 | |
426 // Copy and assignment is explicitly allowed for this class. | |
427 }; | |
428 | 11 |
429 #endif // CHROME_BROWSER_TAB_CONTENTS_NAVIGATION_ENTRY_H_ | 12 #endif // CHROME_BROWSER_TAB_CONTENTS_NAVIGATION_ENTRY_H_ |
OLD | NEW |