[email protected] | 86cd947 | 2012-02-03 19:51:05 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef CONTENT_PUBLIC_BROWSER_NAVIGATION_ENTRY_H_ |
| 6 | #define CONTENT_PUBLIC_BROWSER_NAVIGATION_ENTRY_H_ |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 7 | |
| 8 | #include <string> |
| 9 | |
[email protected] | 132e281a | 2012-07-31 18:32:44 | [diff] [blame] | 10 | #include "base/memory/ref_counted_memory.h" |
[email protected] | 26dd01c | 2013-06-12 13:52:13 | [diff] [blame^] | 11 | #include "base/strings/string16.h" |
[email protected] | 688aa65c6 | 2012-09-28 04:32:22 | [diff] [blame] | 12 | #include "base/time.h" |
[email protected] | 5050b952 | 2011-12-28 07:11:03 | [diff] [blame] | 13 | #include "content/common/content_export.h" |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 14 | #include "content/public/common/page_transition_types.h" |
[email protected] | ad23a09 | 2011-12-28 07:02:04 | [diff] [blame] | 15 | #include "content/public/common/page_type.h" |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 16 | #include "content/public/common/referrer.h" |
| 17 | |
| 18 | class GURL; |
| 19 | |
| 20 | namespace content { |
| 21 | |
[email protected] | 691aa2f | 2013-05-28 22:52:04 | [diff] [blame] | 22 | class PageState; |
[email protected] | d583e3f2 | 2011-12-27 21:38:17 | [diff] [blame] | 23 | struct FaviconStatus; |
| 24 | struct SSLStatus; |
| 25 | |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 26 | // A NavigationEntry is a data structure that captures all the information |
| 27 | // required to recreate a browsing state. This includes some opaque binary |
[email protected] | 770005b | 2012-04-16 15:58:13 | [diff] [blame] | 28 | // state as provided by the WebContentsImpl as well as some clear text title and |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 29 | // URL which is used for our user interface. |
| 30 | class NavigationEntry { |
| 31 | public: |
| 32 | virtual ~NavigationEntry() {} |
| 33 | |
[email protected] | 5050b952 | 2011-12-28 07:11:03 | [diff] [blame] | 34 | CONTENT_EXPORT static NavigationEntry* Create(); |
| 35 | CONTENT_EXPORT static NavigationEntry* Create(const NavigationEntry& copy); |
[email protected] | ad23a09 | 2011-12-28 07:02:04 | [diff] [blame] | 36 | |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 37 | // Page-related stuff -------------------------------------------------------- |
| 38 | |
| 39 | // A unique ID is preserved across commits and redirects, which means that |
| 40 | // sometimes a NavigationEntry's unique ID needs to be set (e.g. when |
| 41 | // creating a committed entry to correspond to a to-be-deleted pending entry, |
| 42 | // the pending entry's ID must be copied). |
| 43 | virtual int GetUniqueID() const = 0; |
| 44 | |
[email protected] | ad23a09 | 2011-12-28 07:02:04 | [diff] [blame] | 45 | // The page type tells us if this entry is for an interstitial or error page. |
| 46 | virtual content::PageType GetPageType() const = 0; |
| 47 | |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 48 | // The actual URL of the page. For some about pages, this may be a scary |
| 49 | // data: URL or something like that. Use GetVirtualURL() below for showing to |
| 50 | // the user. |
[email protected] | ad23a09 | 2011-12-28 07:02:04 | [diff] [blame] | 51 | virtual void SetURL(const GURL& url) = 0; |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 52 | virtual const GURL& GetURL() const = 0; |
| 53 | |
[email protected] | d1ef81d | 2012-07-24 11:39:36 | [diff] [blame] | 54 | // Used for specifying a base URL for pages loaded via data URLs. |
| 55 | virtual void SetBaseURLForDataURL(const GURL& url) = 0; |
| 56 | virtual const GURL& GetBaseURLForDataURL() const = 0; |
| 57 | |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 58 | // The referring URL. Can be empty. |
[email protected] | 022af74 | 2011-12-28 18:37:25 | [diff] [blame] | 59 | virtual void SetReferrer(const content::Referrer& referrer) = 0; |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 60 | virtual const content::Referrer& GetReferrer() const = 0; |
| 61 | |
| 62 | // The virtual URL, when nonempty, will override the actual URL of the page |
| 63 | // when we display it to the user. This allows us to have nice and friendly |
| 64 | // URLs that the user sees for things like about: URLs, but actually feed |
| 65 | // the renderer a data URL that results in the content loading. |
| 66 | // |
| 67 | // GetVirtualURL() will return the URL to display to the user in all cases, so |
| 68 | // if there is no overridden display URL, it will return the actual one. |
| 69 | virtual void SetVirtualURL(const GURL& url) = 0; |
| 70 | virtual const GURL& GetVirtualURL() const = 0; |
| 71 | |
| 72 | // The title as set by the page. This will be empty if there is no title set. |
| 73 | // The caller is responsible for detecting when there is no title and |
| 74 | // displaying the appropriate "Untitled" label if this is being displayed to |
| 75 | // the user. |
| 76 | virtual void SetTitle(const string16& title) = 0; |
| 77 | virtual const string16& GetTitle() const = 0; |
| 78 | |
[email protected] | 691aa2f | 2013-05-28 22:52:04 | [diff] [blame] | 79 | // XXX |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 80 | // Content state is an opaque blob created by WebKit that represents the |
| 81 | // state of the page. This includes form entries and scroll position for each |
| 82 | // frame. We store it so that we can supply it back to WebKit to restore form |
| 83 | // state properly when the user goes back and forward. |
| 84 | // |
| 85 | // WARNING: This state is saved to the file and used to restore previous |
| 86 | // states. If the format is modified in the future, we should still be able to |
| 87 | // deal with older versions. |
[email protected] | 691aa2f | 2013-05-28 22:52:04 | [diff] [blame] | 88 | virtual void SetPageState(const PageState& state) = 0; |
| 89 | virtual const PageState& GetPageState() const = 0; |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 90 | |
[email protected] | e018d3b | 2012-04-17 13:24:15 | [diff] [blame] | 91 | // Describes the current page that the tab represents. This is the ID that the |
| 92 | // renderer generated for the page and is how we can tell new versus |
| 93 | // renavigations. |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 94 | virtual void SetPageID(int page_id) = 0; |
| 95 | virtual int32 GetPageID() const = 0; |
| 96 | |
| 97 | // Page-related helpers ------------------------------------------------------ |
| 98 | |
| 99 | // Returns the title to be displayed on the tab. This could be the title of |
| 100 | // the page if it is available or the URL. |languages| is the list of |
| 101 | // accpeted languages (e.g., prefs::kAcceptLanguages) or empty if proper |
| 102 | // URL formatting isn't needed (e.g., unit tests). |
| 103 | virtual const string16& GetTitleForDisplay( |
| 104 | const std::string& languages) const = 0; |
| 105 | |
| 106 | // Returns true if the current tab is in view source mode. This will be false |
| 107 | // if there is no navigation. |
| 108 | virtual bool IsViewSourceMode() const = 0; |
| 109 | |
| 110 | // Tracking stuff ------------------------------------------------------------ |
| 111 | |
| 112 | // The transition type indicates what the user did to move to this page from |
| 113 | // the previous page. |
[email protected] | 022af74 | 2011-12-28 18:37:25 | [diff] [blame] | 114 | virtual void SetTransitionType(content::PageTransition transition_type) = 0; |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 115 | virtual content::PageTransition GetTransitionType() const = 0; |
| 116 | |
[email protected] | ad23a09 | 2011-12-28 07:02:04 | [diff] [blame] | 117 | // The user typed URL was the URL that the user initiated the navigation |
| 118 | // with, regardless of any redirects. This is used to generate keywords, for |
| 119 | // example, based on "what the user thinks the site is called" rather than |
| 120 | // what it's actually called. For example, if the user types "foo.com", that |
| 121 | // may redirect somewhere arbitrary like "bar.com/foo", and we want to use |
| 122 | // the name that the user things of the site as having. |
| 123 | // |
| 124 | // This URL will be is_empty() if the URL was navigated to some other way. |
| 125 | // Callers should fall back on using the regular or display URL in this case. |
| 126 | virtual const GURL& GetUserTypedURL() const = 0; |
| 127 | |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 128 | // Post data is form data that was posted to get to this page. The data will |
| 129 | // have to be reposted to reload the page properly. This flag indicates |
| 130 | // whether the page had post data. |
| 131 | // |
[email protected] | 132e281a | 2012-07-31 18:32:44 | [diff] [blame] | 132 | // The actual post data is stored either in |
| 133 | // 1) browser_initiated_post_data when a new post data request is started. |
| 134 | // 2) content_state when a post request has started and is extracted by |
| 135 | // WebKit to actually make the request. |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 136 | virtual void SetHasPostData(bool has_post_data) = 0; |
| 137 | virtual bool GetHasPostData() const = 0; |
[email protected] | d583e3f2 | 2011-12-27 21:38:17 | [diff] [blame] | 138 | |
[email protected] | 86cd947 | 2012-02-03 19:51:05 | [diff] [blame] | 139 | // The Post identifier associated with the page. |
| 140 | virtual void SetPostID(int64 post_id) = 0; |
| 141 | virtual int64 GetPostID() const = 0; |
| 142 | |
[email protected] | 132e281a | 2012-07-31 18:32:44 | [diff] [blame] | 143 | // Holds the raw post data of a browser initiated post request. |
| 144 | // For efficiency, this should be cleared when content_state is populated |
| 145 | // since the data is duplicated. |
| 146 | // Note, this field: |
| 147 | // 1) is not persisted in session restore. |
| 148 | // 2) is shallow copied with the static copy Create method above. |
| 149 | // 3) may be NULL so check before use. |
| 150 | virtual void SetBrowserInitiatedPostData( |
| 151 | const base::RefCountedMemory* data) = 0; |
| 152 | virtual const base::RefCountedMemory* GetBrowserInitiatedPostData() const = 0; |
| 153 | |
[email protected] | d583e3f2 | 2011-12-27 21:38:17 | [diff] [blame] | 154 | // The favicon data and tracking information. See content::FaviconStatus. |
| 155 | virtual const FaviconStatus& GetFavicon() const = 0; |
| 156 | virtual FaviconStatus& GetFavicon() = 0; |
| 157 | |
| 158 | // All the SSL flags and state. See content::SSLStatus. |
| 159 | virtual const SSLStatus& GetSSL() const = 0; |
| 160 | virtual SSLStatus& GetSSL() = 0; |
[email protected] | 074269f | 2012-04-17 21:12:42 | [diff] [blame] | 161 | |
| 162 | // Store the URL that caused this NavigationEntry to be created. |
| 163 | virtual void SetOriginalRequestURL(const GURL& original_url) = 0; |
| 164 | virtual const GURL& GetOriginalRequestURL() const = 0; |
[email protected] | 86ef6a39 | 2012-05-11 22:03:11 | [diff] [blame] | 165 | |
| 166 | // Store whether or not we're overriding the user agent. |
| 167 | virtual void SetIsOverridingUserAgent(bool override) = 0; |
| 168 | virtual bool GetIsOverridingUserAgent() const = 0; |
[email protected] | 688aa65c6 | 2012-09-28 04:32:22 | [diff] [blame] | 169 | |
| 170 | // The time at which the last known local navigation has |
| 171 | // completed. (A navigation can be completed more than once if the |
| 172 | // page is reloaded.) |
| 173 | // |
| 174 | // If GetTimestamp() returns a null time, that means that either: |
| 175 | // |
| 176 | // - this navigation hasn't completed yet; |
| 177 | // - this navigation was restored and for some reason the |
| 178 | // timestamp wasn't available; |
| 179 | // - or this navigation was copied from a foreign session. |
| 180 | virtual void SetTimestamp(base::Time timestamp) = 0; |
| 181 | virtual base::Time GetTimestamp() const = 0; |
[email protected] | 951a6483 | 2012-10-11 16:26:37 | [diff] [blame] | 182 | |
| 183 | // Used to specify if this entry should be able to access local file:// |
| 184 | // resources. |
| 185 | virtual void SetCanLoadLocalResources(bool allow) = 0; |
| 186 | virtual bool GetCanLoadLocalResources() const = 0; |
[email protected] | 3027cf0 | 2013-01-24 08:16:58 | [diff] [blame] | 187 | |
| 188 | // Used to specify which frame to navigate. If empty, the main frame is |
| 189 | // navigated. This is currently not persisted in session restore, because it |
| 190 | // is currently only used in tests. |
| 191 | virtual void SetFrameToNavigate(const std::string& frame_name) = 0; |
| 192 | virtual const std::string& GetFrameToNavigate() const = 0; |
[email protected] | 261cf89 | 2013-02-01 00:42:36 | [diff] [blame] | 193 | |
| 194 | // Set extra data on this NavigationEntry according to the specified |key|. |
| 195 | // This data is not persisted by default. |
| 196 | virtual void SetExtraData(const std::string& key, const string16& data) = 0; |
| 197 | // If present, fills the |data| present at the specified |key|. |
| 198 | virtual bool GetExtraData(const std::string& key, string16* data) const = 0; |
| 199 | // Removes the data at the specified |key|. |
| 200 | virtual void ClearExtraData(const std::string& key) = 0; |
[email protected] | 36fc039 | 2011-12-25 03:59:51 | [diff] [blame] | 201 | }; |
| 202 | |
| 203 | } // namespace content |
| 204 | |
| 205 | #endif // CONTENT_PUBLIC_BROWSER_NAVIGATION_ENTRY_H_ |