| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // 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 | 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_NAVIGATION_ENTRY_H_ | 5 #ifndef CHROME_BROWSER_NAVIGATION_ENTRY_H_ |
| 6 #define CHROME_BROWSER_NAVIGATION_ENTRY_H_ | 6 #define CHROME_BROWSER_NAVIGATION_ENTRY_H_ |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/scoped_ptr.h" | 9 #include "base/scoped_ptr.h" |
| 10 #include "base/string_util.h" | 10 #include "base/string_util.h" |
| 11 #include "chrome/browser/tab_contents/security_style.h" | 11 #include "chrome/browser/tab_contents/security_style.h" |
| 12 #include "chrome/browser/tab_contents/site_instance.h" | 12 #include "chrome/browser/tab_contents/site_instance.h" |
| 13 #include "chrome/browser/tab_contents/tab_contents_type.h" | 13 #include "chrome/browser/tab_contents/tab_contents_type.h" |
| 14 #include "chrome/common/page_transition_types.h" | 14 #include "chrome/common/page_transition_types.h" |
| 15 #include "googleurl/src/gurl.h" | 15 #include "googleurl/src/gurl.h" |
| 16 #include "grit/theme_resources.h" | 16 #include "grit/theme_resources.h" |
| 17 #include "skia/include/SkBitmap.h" | 17 #include "skia/include/SkBitmap.h" |
| 18 | 18 |
| 19 class NavigationController; |
| 20 |
| 19 //////////////////////////////////////////////////////////////////////////////// | 21 //////////////////////////////////////////////////////////////////////////////// |
| 20 // | 22 // |
| 21 // NavigationEntry class | 23 // NavigationEntry class |
| 22 // | 24 // |
| 23 // A NavigationEntry is a data structure that captures all the information | 25 // A NavigationEntry is a data structure that captures all the information |
| 24 // required to recreate a browsing state. This includes some opaque binary | 26 // required to recreate a browsing state. This includes some opaque binary |
| 25 // state as provided by the TabContents as well as some clear text title and | 27 // state as provided by the TabContents as well as some clear text title and |
| 26 // URL which is used for our user interface. | 28 // URL which is used for our user interface. |
| 27 // | 29 // |
| 28 //////////////////////////////////////////////////////////////////////////////// | 30 //////////////////////////////////////////////////////////////////////////////// |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 }; | 164 }; |
| 163 | 165 |
| 164 // --------------------------------------------------------------------------- | 166 // --------------------------------------------------------------------------- |
| 165 | 167 |
| 166 explicit NavigationEntry(TabContentsType type); | 168 explicit NavigationEntry(TabContentsType type); |
| 167 NavigationEntry(TabContentsType type, | 169 NavigationEntry(TabContentsType type, |
| 168 SiteInstance* instance, | 170 SiteInstance* instance, |
| 169 int page_id, | 171 int page_id, |
| 170 const GURL& url, | 172 const GURL& url, |
| 171 const GURL& referrer, | 173 const GURL& referrer, |
| 172 const std::wstring& title, | 174 const string16& title, |
| 173 PageTransition::Type transition_type); | 175 PageTransition::Type transition_type); |
| 174 ~NavigationEntry() { | 176 ~NavigationEntry() { |
| 175 } | 177 } |
| 176 | 178 |
| 177 // Page-related stuff -------------------------------------------------------- | 179 // Page-related stuff -------------------------------------------------------- |
| 178 | 180 |
| 179 // A unique ID is preserved across commits and redirects, which means that | 181 // A unique ID is preserved across commits and redirects, which means that |
| 180 // sometimes a NavigationEntry's unique ID needs to be set (e.g. when | 182 // sometimes a NavigationEntry's unique ID needs to be set (e.g. when |
| 181 // creating a committed entry to correspond to a to-be-deleted pending entry, | 183 // creating a committed entry to correspond to a to-be-deleted pending entry, |
| 182 // the pending entry's ID must be copied). | 184 // the pending entry's ID must be copied). |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 214 } | 216 } |
| 215 PageType page_type() const { | 217 PageType page_type() const { |
| 216 return page_type_; | 218 return page_type_; |
| 217 } | 219 } |
| 218 | 220 |
| 219 // The actual URL of the page. For some about pages, this may be a scary | 221 // The actual URL of the page. For some about pages, this may be a scary |
| 220 // data: URL or something like that. Use display_url() below for showing to | 222 // data: URL or something like that. Use display_url() below for showing to |
| 221 // the user. | 223 // the user. |
| 222 void set_url(const GURL& url) { | 224 void set_url(const GURL& url) { |
| 223 url_ = url; | 225 url_ = url; |
| 224 if (display_url_.is_empty()) { | 226 cached_display_title_.clear(); |
| 225 // If there is no explicit display URL, then we'll display this URL. | |
| 226 display_url_as_string_ = UTF8ToWide(url_.spec()); | |
| 227 } | |
| 228 } | 227 } |
| 229 const GURL& url() const { | 228 const GURL& url() const { |
| 230 return url_; | 229 return url_; |
| 231 } | 230 } |
| 232 | 231 |
| 233 // The referring URL. Can be empty. | 232 // The referring URL. Can be empty. |
| 234 void set_referrer(const GURL& referrer) { | 233 void set_referrer(const GURL& referrer) { |
| 235 referrer_ = referrer; | 234 referrer_ = referrer; |
| 236 } | 235 } |
| 237 const GURL& referrer() const { | 236 const GURL& referrer() const { |
| 238 return referrer_; | 237 return referrer_; |
| 239 } | 238 } |
| 240 | 239 |
| 241 // The display URL, when nonempty, will override the actual URL of the page | 240 // The display URL, when nonempty, will override the actual URL of the page |
| 242 // when we display it to the user. This allows us to have nice and friendly | 241 // when we display it to the user. This allows us to have nice and friendly |
| 243 // URLs that the user sees for things like about: URLs, but actually feed | 242 // URLs that the user sees for things like about: URLs, but actually feed |
| 244 // the renderer a data URL that results in the content loading. | 243 // the renderer a data URL that results in the content loading. |
| 245 // | 244 // |
| 246 // display_url() will return the URL to display to the user in all cases, so | 245 // display_url() will return the URL to display to the user in all cases, so |
| 247 // if there is no overridden display URL, it will return the actual one. | 246 // if there is no overridden display URL, it will return the actual one. |
| 248 void set_display_url(const GURL& url) { | 247 void set_display_url(const GURL& url) { |
| 249 display_url_ = (url == url_) ? GURL() : url; | 248 display_url_ = (url == url_) ? GURL() : url; |
| 250 display_url_as_string_ = UTF8ToWide(url.spec()); | 249 cached_display_title_.clear(); |
| 251 } | 250 } |
| 252 bool has_display_url() const { | 251 bool has_display_url() const { |
| 253 return !display_url_.is_empty(); | 252 return !display_url_.is_empty(); |
| 254 } | 253 } |
| 255 const GURL& display_url() const { | 254 const GURL& display_url() const { |
| 256 return display_url_.is_empty() ? url_ : display_url_; | 255 return display_url_.is_empty() ? url_ : display_url_; |
| 257 } | 256 } |
| 258 | 257 |
| 259 // The title as set by the page. This will be empty if there is no title set. | 258 // The title as set by the page. This will be empty if there is no title set. |
| 260 // The caller is responsible for detecting when there is no title and | 259 // The caller is responsible for detecting when there is no title and |
| 261 // displaying the appropriate "Untitled" label if this is being displayed to | 260 // displaying the appropriate "Untitled" label if this is being displayed to |
| 262 // the user. | 261 // the user. |
| 263 void set_title(const std::wstring& title) { | 262 void set_title(const string16& title) { |
| 264 title_ = title; | 263 title_ = title; |
| 264 cached_display_title_.clear(); |
| 265 } | 265 } |
| 266 const std::wstring& title() const { | 266 const string16& title() const { |
| 267 return title_; | 267 return title_; |
| 268 } | 268 } |
| 269 | 269 |
| 270 // The favicon data and tracking information. See FaviconStatus above. | 270 // The favicon data and tracking information. See FaviconStatus above. |
| 271 const FaviconStatus& favicon() const { | 271 const FaviconStatus& favicon() const { |
| 272 return favicon_; | 272 return favicon_; |
| 273 } | 273 } |
| 274 FaviconStatus& favicon() { | 274 FaviconStatus& favicon() { |
| 275 return favicon_; | 275 return favicon_; |
| 276 } | 276 } |
| (...skipping 29 matching lines...) Expand all Loading... |
| 306 return ssl_; | 306 return ssl_; |
| 307 } | 307 } |
| 308 SSLStatus& ssl() { | 308 SSLStatus& ssl() { |
| 309 return ssl_; | 309 return ssl_; |
| 310 } | 310 } |
| 311 | 311 |
| 312 // Page-related helpers ------------------------------------------------------ | 312 // Page-related helpers ------------------------------------------------------ |
| 313 | 313 |
| 314 // Returns the title to be displayed on the tab. This could be the title of | 314 // Returns the title to be displayed on the tab. This could be the title of |
| 315 // the page if it is available or the URL. | 315 // the page if it is available or the URL. |
| 316 const std::wstring& GetTitleForDisplay(); | 316 // |
| 317 // The NavigationController corresponding to this entry must be given so we |
| 318 // can get the preferences so we can optionally format a URL for display. It |
| 319 // may be NULL if you don't need proper URL formatting (e.g. unit tests). |
| 320 const string16& GetTitleForDisplay(const NavigationController* controller); |
| 317 | 321 |
| 318 // Returns true if the current tab is in view source mode. This will be false | 322 // Returns true if the current tab is in view source mode. This will be false |
| 319 // if there is no navigation. | 323 // if there is no navigation. |
| 320 bool IsViewSourceMode() const; | 324 bool IsViewSourceMode() const; |
| 321 | 325 |
| 322 // Tracking stuff ------------------------------------------------------------ | 326 // Tracking stuff ------------------------------------------------------------ |
| 323 | 327 |
| 324 // The transition type indicates what the user did to move to this page from | 328 // The transition type indicates what the user did to move to this page from |
| 325 // the previous page. | 329 // the previous page. |
| 326 void set_transition_type(PageTransition::Type transition_type) { | 330 void set_transition_type(PageTransition::Type transition_type) { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 376 // update SessionService/TabRestoreService appropriately. | 380 // update SessionService/TabRestoreService appropriately. |
| 377 // WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING | 381 // WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING |
| 378 | 382 |
| 379 // See the accessors above for descriptions. | 383 // See the accessors above for descriptions. |
| 380 int unique_id_; | 384 int unique_id_; |
| 381 TabContentsType tab_type_; | 385 TabContentsType tab_type_; |
| 382 scoped_refptr<SiteInstance> site_instance_; | 386 scoped_refptr<SiteInstance> site_instance_; |
| 383 PageType page_type_; | 387 PageType page_type_; |
| 384 GURL url_; | 388 GURL url_; |
| 385 GURL referrer_; | 389 GURL referrer_; |
| 386 | |
| 387 GURL display_url_; | 390 GURL display_url_; |
| 388 | 391 string16 title_; |
| 389 // We cache a copy of the display URL as a string so we don't have to | |
| 390 // convert the display URL to a wide string every time we paint. | |
| 391 std::wstring display_url_as_string_; | |
| 392 | |
| 393 std::wstring title_; | |
| 394 FaviconStatus favicon_; | 392 FaviconStatus favicon_; |
| 395 std::string content_state_; | 393 std::string content_state_; |
| 396 int32 page_id_; | 394 int32 page_id_; |
| 397 SSLStatus ssl_; | 395 SSLStatus ssl_; |
| 398 PageTransition::Type transition_type_; | 396 PageTransition::Type transition_type_; |
| 399 GURL user_typed_url_; | 397 GURL user_typed_url_; |
| 400 bool has_post_data_; | 398 bool has_post_data_; |
| 401 bool restored_; | 399 bool restored_; |
| 402 | 400 |
| 401 // This is a cached version of the result of GetTitleForDisplay. It prevents |
| 402 // us from having to do URL formatting on the URL evey time the title is |
| 403 // displayed. When the URL, display URL, or title is set, this should be |
| 404 // cleared to force a refresh. |
| 405 string16 cached_display_title_; |
| 406 |
| 403 // Copy and assignment is explicitly allowed for this class. | 407 // Copy and assignment is explicitly allowed for this class. |
| 404 }; | 408 }; |
| 405 | 409 |
| 406 #endif // CHROME_BROWSER_NAVIGATION_ENTRY_H_ | 410 #endif // CHROME_BROWSER_NAVIGATION_ENTRY_H_ |
| OLD | NEW |