1 // Copyright 2013 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.
5 #ifndef CONTENT_BROWSER_FRAME_HOST_NAVIGATION_ENTRY_IMPL_H_
6 #define CONTENT_BROWSER_FRAME_HOST_NAVIGATION_ENTRY_IMPL_H_
8 #include "base/basictypes.h"
9 #include "base/memory/ref_counted.h"
10 #include "content/browser/site_instance_impl.h"
11 #include "content/public/browser/favicon_status.h"
12 #include "content/public/browser/global_request_id.h"
13 #include "content/public/browser/navigation_entry.h"
14 #include "content/public/common/page_state.h"
15 #include "content/public/common/ssl_status.h"
19 class CONTENT_EXPORT NavigationEntryImpl
20 : public NON_EXPORTED_BASE(NavigationEntry
) {
22 static NavigationEntryImpl
* FromNavigationEntry(NavigationEntry
* entry
);
24 // The value of bindings() before it is set during commit.
25 static int kInvalidBindings
;
27 NavigationEntryImpl();
28 NavigationEntryImpl(SiteInstanceImpl
* instance
,
31 const Referrer
& referrer
,
32 const base::string16
& title
,
33 ui::PageTransition transition_type
,
34 bool is_renderer_initiated
);
35 ~NavigationEntryImpl() override
;
37 // NavigationEntry implementation:
38 int GetUniqueID() const override
;
39 PageType
GetPageType() const override
;
40 void SetURL(const GURL
& url
) override
;
41 const GURL
& GetURL() const override
;
42 void SetBaseURLForDataURL(const GURL
& url
) override
;
43 const GURL
& GetBaseURLForDataURL() const override
;
44 void SetReferrer(const Referrer
& referrer
) override
;
45 const Referrer
& GetReferrer() const override
;
46 void SetVirtualURL(const GURL
& url
) override
;
47 const GURL
& GetVirtualURL() const override
;
48 void SetTitle(const base::string16
& title
) override
;
49 const base::string16
& GetTitle() const override
;
50 void SetPageState(const PageState
& state
) override
;
51 const PageState
& GetPageState() const override
;
52 void SetPageID(int page_id
) override
;
53 int32
GetPageID() const override
;
54 const base::string16
& GetTitleForDisplay(
55 const std::string
& languages
) const override
;
56 bool IsViewSourceMode() const override
;
57 void SetTransitionType(ui::PageTransition transition_type
) override
;
58 ui::PageTransition
GetTransitionType() const override
;
59 const GURL
& GetUserTypedURL() const override
;
60 void SetHasPostData(bool has_post_data
) override
;
61 bool GetHasPostData() const override
;
62 void SetPostID(int64 post_id
) override
;
63 int64
GetPostID() const override
;
64 void SetBrowserInitiatedPostData(const base::RefCountedMemory
* data
) override
;
65 const base::RefCountedMemory
* GetBrowserInitiatedPostData() const override
;
66 const FaviconStatus
& GetFavicon() const override
;
67 FaviconStatus
& GetFavicon() override
;
68 const SSLStatus
& GetSSL() const override
;
69 SSLStatus
& GetSSL() override
;
70 void SetOriginalRequestURL(const GURL
& original_url
) override
;
71 const GURL
& GetOriginalRequestURL() const override
;
72 void SetIsOverridingUserAgent(bool override
) override
;
73 bool GetIsOverridingUserAgent() const override
;
74 void SetTimestamp(base::Time timestamp
) override
;
75 base::Time
GetTimestamp() const override
;
76 void SetCanLoadLocalResources(bool allow
) override
;
77 bool GetCanLoadLocalResources() const override
;
78 void SetFrameToNavigate(const std::string
& frame_name
) override
;
79 const std::string
& GetFrameToNavigate() const override
;
80 void SetExtraData(const std::string
& key
,
81 const base::string16
& data
) override
;
82 bool GetExtraData(const std::string
& key
,
83 base::string16
* data
) const override
;
84 void ClearExtraData(const std::string
& key
) override
;
85 void SetHttpStatusCode(int http_status_code
) override
;
86 int GetHttpStatusCode() const override
;
87 void SetRedirectChain(const std::vector
<GURL
>& redirects
) override
;
88 const std::vector
<GURL
>& GetRedirectChain() const override
;
89 bool IsRestored() const override
;
91 // Once a navigation entry is committed, we should no longer track several
92 // pieces of non-persisted state, as documented on the members below.
93 void ResetForCommit();
95 void set_unique_id(int unique_id
) {
96 unique_id_
= unique_id
;
99 // The SiteInstance tells us how to share sub-processes. This is a reference
100 // counted pointer to a shared site instance.
102 // Note that the SiteInstance should usually not be changed after it is set,
103 // but this may happen if the NavigationEntry was cloned and needs to use a
104 // different SiteInstance.
105 void set_site_instance(SiteInstanceImpl
* site_instance
);
106 SiteInstanceImpl
* site_instance() const {
107 return site_instance_
.get();
110 // Remember the set of bindings granted to this NavigationEntry at the time
111 // of commit, to ensure that we do not grant it additional bindings if we
112 // navigate back to it in the future. This can only be changed once.
113 void SetBindings(int bindings
);
114 int bindings() const {
118 void set_page_type(PageType page_type
) {
119 page_type_
= page_type
;
122 bool has_virtual_url() const {
123 return !virtual_url_
.is_empty();
126 bool update_virtual_url_with_url() const {
127 return update_virtual_url_with_url_
;
129 void set_update_virtual_url_with_url(bool update
) {
130 update_virtual_url_with_url_
= update
;
133 // Extra headers (separated by \n) to send during the request.
134 void set_extra_headers(const std::string
& extra_headers
) {
135 extra_headers_
= extra_headers
;
137 const std::string
& extra_headers() const {
138 return extra_headers_
;
141 // Whether this (pending) navigation is renderer-initiated. Resets to false
142 // for all types of navigations after commit.
143 void set_is_renderer_initiated(bool is_renderer_initiated
) {
144 is_renderer_initiated_
= is_renderer_initiated
;
146 bool is_renderer_initiated() const {
147 return is_renderer_initiated_
;
150 void set_user_typed_url(const GURL
& user_typed_url
) {
151 user_typed_url_
= user_typed_url
;
154 // Enumerations of the possible restore types.
156 // Restore from the previous session.
157 RESTORE_LAST_SESSION_EXITED_CLEANLY
,
158 RESTORE_LAST_SESSION_CRASHED
,
160 // The entry has been restored from the current session. This is used when
161 // the user issues 'reopen closed tab'.
162 RESTORE_CURRENT_SESSION
,
164 // The entry was not restored.
168 // The RestoreType for this entry. This is set if the entry was retored. This
169 // is set to RESTORE_NONE once the entry is loaded.
170 void set_restore_type(RestoreType type
) {
171 restore_type_
= type
;
173 RestoreType
restore_type() const {
174 return restore_type_
;
177 void set_transferred_global_request_id(
178 const GlobalRequestID
& transferred_global_request_id
) {
179 transferred_global_request_id_
= transferred_global_request_id
;
182 GlobalRequestID
transferred_global_request_id() const {
183 return transferred_global_request_id_
;
186 // Whether this (pending) navigation needs to replace current entry.
187 // Resets to false after commit.
188 bool should_replace_entry() const {
189 return should_replace_entry_
;
192 void set_should_replace_entry(bool should_replace_entry
) {
193 should_replace_entry_
= should_replace_entry
;
196 void SetScreenshotPNGData(scoped_refptr
<base::RefCountedBytes
> png_data
);
197 const scoped_refptr
<base::RefCountedBytes
> screenshot() const {
201 // Whether this (pending) navigation should clear the session history. Resets
202 // to false after commit.
203 bool should_clear_history_list() const {
204 return should_clear_history_list_
;
206 void set_should_clear_history_list(bool should_clear_history_list
) {
207 should_clear_history_list_
= should_clear_history_list
;
210 // Indicates which FrameTreeNode to navigate. Currently only used if the
211 // --site-per-process flag is passed.
212 int64
frame_tree_node_id() const {
213 return frame_tree_node_id_
;
215 void set_frame_tree_node_id(int64 frame_tree_node_id
) {
216 frame_tree_node_id_
= frame_tree_node_id
;
220 // WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
221 // Session/Tab restore save portions of this class so that it can be recreated
222 // later. If you add a new field that needs to be persisted you'll have to
223 // update SessionService/TabRestoreService and Android WebView
224 // state_serializer.cc appropriately.
225 // WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
227 // See the accessors above for descriptions.
229 scoped_refptr
<SiteInstanceImpl
> site_instance_
;
230 // TODO(creis): Persist bindings_. http://crbug.com/173672.
236 bool update_virtual_url_with_url_
;
237 base::string16 title_
;
238 FaviconStatus favicon_
;
239 PageState page_state_
;
242 ui::PageTransition transition_type_
;
243 GURL user_typed_url_
;
246 RestoreType restore_type_
;
247 GURL original_request_url_
;
248 bool is_overriding_user_agent_
;
249 base::Time timestamp_
;
250 int http_status_code_
;
252 // This member is not persisted with session restore because it is transient.
253 // If the post request succeeds, this field is cleared since the same
254 // information is stored in |content_state_| above. It is also only shallow
255 // copied with compiler provided copy constructor.
256 // Cleared in |ResetForCommit|.
257 scoped_refptr
<const base::RefCountedMemory
> browser_initiated_post_data_
;
259 // This is also a transient member (i.e. is not persisted with session
260 // restore). The screenshot of a page is taken when navigating away from the
261 // page. This screenshot is displayed during an overscroll-navigation
262 // gesture. |screenshot_| will be NULL when the screenshot is not available
263 // (e.g. after a session restore, or if taking the screenshot of a page
264 // failed). The UI is responsible for dealing with missing screenshots
265 // appropriately (e.g. display a placeholder image instead).
266 scoped_refptr
<base::RefCountedBytes
> screenshot_
;
268 // This member is not persisted with session restore.
269 std::string extra_headers_
;
271 // Used for specifying base URL for pages loaded via data URLs. Only used and
272 // persisted by Android WebView.
273 GURL base_url_for_data_url_
;
275 // Whether the entry, while loading, was created for a renderer-initiated
276 // navigation. This dictates whether the URL should be displayed before the
277 // navigation commits. It is cleared in |ResetForCommit| and not persisted.
278 bool is_renderer_initiated_
;
280 // This is a cached version of the result of GetTitleForDisplay. It prevents
281 // us from having to do URL formatting on the URL every time the title is
282 // displayed. When the URL, virtual URL, or title is set, this should be
283 // cleared to force a refresh.
284 mutable base::string16 cached_display_title_
;
286 // In case a navigation is transferred to a new RVH but the request has
287 // been generated in the renderer already, this identifies the old request so
288 // that it can be resumed. The old request is stored until the
289 // ResourceDispatcher receives the navigation from the renderer which
290 // carries this |transferred_global_request_id_| annotation. Once the request
291 // is transferred to the new process, this is cleared and the request
292 // continues as normal.
293 // Cleared in |ResetForCommit|.
294 GlobalRequestID transferred_global_request_id_
;
296 // This is set to true when this entry is being reloaded and due to changes in
297 // the state of the URL, it has to be reloaded in a different site instance.
298 // In such case, we must treat it as an existing navigation in the new site
299 // instance, instead of a new navigation. This value should not be persisted
300 // and is cleared in |ResetForCommit|.
302 // We also use this flag for cross-process redirect navigations, so that the
303 // browser will replace the current navigation entry (which is the page
304 // doing the redirect).
305 bool should_replace_entry_
;
307 // This is used when transferring a pending entry from one process to another.
308 // We also send this data through session sync for offline analysis.
309 // It is preserved after commit but should not be persisted.
310 std::vector
<GURL
> redirect_chain_
;
312 // This is set to true when this entry's navigation should clear the session
313 // history both on the renderer and browser side. The browser side history
314 // won't be cleared until the renderer has committed this navigation. This
315 // entry is not persisted by the session restore system, as it is always
316 // cleared in |ResetForCommit|.
317 bool should_clear_history_list_
;
319 // Set when this entry should be able to access local file:// resources. This
320 // value is not needed after the entry commits and is not persisted.
321 bool can_load_local_resources_
;
323 // If not empty, the name of the frame to navigate. This field is not
324 // persisted, because it is currently only used in tests.
325 std::string frame_to_navigate_
;
327 // If not -1, this indicates which FrameTreeNode to navigate. This field is
328 // not persisted because it is experimental and only used when the
329 // --site-per-process flag is passed. It is cleared in |ResetForCommit|
330 // because we only use it while the navigation is pending.
331 // TODO(creis): Move this to FrameNavigationEntry.
332 int64 frame_tree_node_id_
;
334 // Used to store extra data to support browser features. This member is not
335 // persisted, unless specific data is taken out/put back in at save/restore
336 // time (see TabNavigation for an example of this).
337 std::map
<std::string
, base::string16
> extra_data_
;
339 // Copy and assignment is explicitly allowed for this class.
342 } // namespace content
344 #endif // CONTENT_BROWSER_FRAME_HOST_NAVIGATION_ENTRY_IMPL_H_