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 "base/time/time.h"
11 #include "content/browser/frame_host/frame_navigation_entry.h"
12 #include "content/browser/site_instance_impl.h"
13 #include "content/public/browser/favicon_status.h"
14 #include "content/public/browser/global_request_id.h"
15 #include "content/public/browser/navigation_entry.h"
16 #include "content/public/common/page_state.h"
17 #include "content/public/common/ssl_status.h"
21 class CONTENT_EXPORT NavigationEntryImpl
22 : public NON_EXPORTED_BASE(NavigationEntry
) {
24 static NavigationEntryImpl
* FromNavigationEntry(NavigationEntry
* entry
);
26 // The value of bindings() before it is set during commit.
27 static int kInvalidBindings
;
29 NavigationEntryImpl();
30 NavigationEntryImpl(SiteInstanceImpl
* instance
,
33 const Referrer
& referrer
,
34 const base::string16
& title
,
35 ui::PageTransition transition_type
,
36 bool is_renderer_initiated
);
37 ~NavigationEntryImpl() override
;
39 // NavigationEntry implementation:
40 int GetUniqueID() const override
;
41 PageType
GetPageType() const override
;
42 void SetURL(const GURL
& url
) override
;
43 const GURL
& GetURL() const override
;
44 void SetBaseURLForDataURL(const GURL
& url
) override
;
45 const GURL
& GetBaseURLForDataURL() const override
;
46 void SetReferrer(const Referrer
& referrer
) override
;
47 const Referrer
& GetReferrer() const override
;
48 void SetVirtualURL(const GURL
& url
) override
;
49 const GURL
& GetVirtualURL() const override
;
50 void SetTitle(const base::string16
& title
) override
;
51 const base::string16
& GetTitle() const override
;
52 void SetPageState(const PageState
& state
) override
;
53 const PageState
& GetPageState() const override
;
54 void SetPageID(int page_id
) override
;
55 int32
GetPageID() const override
;
56 const base::string16
& GetTitleForDisplay(
57 const std::string
& languages
) const override
;
58 bool IsViewSourceMode() const override
;
59 void SetTransitionType(ui::PageTransition transition_type
) override
;
60 ui::PageTransition
GetTransitionType() const override
;
61 const GURL
& GetUserTypedURL() const override
;
62 void SetHasPostData(bool has_post_data
) override
;
63 bool GetHasPostData() const override
;
64 void SetPostID(int64 post_id
) override
;
65 int64
GetPostID() const override
;
66 void SetBrowserInitiatedPostData(const base::RefCountedMemory
* data
) override
;
67 const base::RefCountedMemory
* GetBrowserInitiatedPostData() const override
;
68 const FaviconStatus
& GetFavicon() const override
;
69 FaviconStatus
& GetFavicon() override
;
70 const SSLStatus
& GetSSL() const override
;
71 SSLStatus
& GetSSL() override
;
72 void SetOriginalRequestURL(const GURL
& original_url
) override
;
73 const GURL
& GetOriginalRequestURL() const override
;
74 void SetIsOverridingUserAgent(bool override
) override
;
75 bool GetIsOverridingUserAgent() const override
;
76 void SetTimestamp(base::Time timestamp
) override
;
77 base::Time
GetTimestamp() const override
;
78 void SetCanLoadLocalResources(bool allow
) override
;
79 bool GetCanLoadLocalResources() const override
;
80 void SetFrameToNavigate(const std::string
& frame_name
) override
;
81 const std::string
& GetFrameToNavigate() const override
;
82 void SetExtraData(const std::string
& key
,
83 const base::string16
& data
) override
;
84 bool GetExtraData(const std::string
& key
,
85 base::string16
* data
) const override
;
86 void ClearExtraData(const std::string
& key
) override
;
87 void SetHttpStatusCode(int http_status_code
) override
;
88 int GetHttpStatusCode() const override
;
89 void SetRedirectChain(const std::vector
<GURL
>& redirects
) override
;
90 const std::vector
<GURL
>& GetRedirectChain() const override
;
91 bool IsRestored() const override
;
93 // Once a navigation entry is committed, we should no longer track several
94 // pieces of non-persisted state, as documented on the members below.
95 void ResetForCommit();
97 void set_unique_id(int unique_id
) {
98 unique_id_
= unique_id
;
101 // The SiteInstance represents which pages must share processes. This is a
102 // reference counted pointer to a shared SiteInstance.
104 // Note that the SiteInstance should usually not be changed after it is set,
105 // but this may happen if the NavigationEntry was cloned and needs to use a
106 // different SiteInstance.
107 void set_site_instance(SiteInstanceImpl
* site_instance
);
108 SiteInstanceImpl
* site_instance() const {
109 return frame_entry_
.site_instance();
112 // The |source_site_instance| is used to identify the SiteInstance of the
113 // frame that initiated the navigation.
114 void set_source_site_instance(SiteInstanceImpl
* source_site_instance
);
115 SiteInstanceImpl
* source_site_instance() const {
116 return source_site_instance_
.get();
119 // Remember the set of bindings granted to this NavigationEntry at the time
120 // of commit, to ensure that we do not grant it additional bindings if we
121 // navigate back to it in the future. This can only be changed once.
122 void SetBindings(int bindings
);
123 int bindings() const {
127 void set_page_type(PageType page_type
) {
128 page_type_
= page_type
;
131 bool has_virtual_url() const {
132 return !virtual_url_
.is_empty();
135 bool update_virtual_url_with_url() const {
136 return update_virtual_url_with_url_
;
138 void set_update_virtual_url_with_url(bool update
) {
139 update_virtual_url_with_url_
= update
;
142 // Extra headers (separated by \n) to send during the request.
143 void set_extra_headers(const std::string
& extra_headers
) {
144 extra_headers_
= extra_headers
;
146 const std::string
& extra_headers() const {
147 return extra_headers_
;
150 // Whether this (pending) navigation is renderer-initiated. Resets to false
151 // for all types of navigations after commit.
152 void set_is_renderer_initiated(bool is_renderer_initiated
) {
153 is_renderer_initiated_
= is_renderer_initiated
;
155 bool is_renderer_initiated() const {
156 return is_renderer_initiated_
;
159 void set_user_typed_url(const GURL
& user_typed_url
) {
160 user_typed_url_
= user_typed_url
;
163 // Enumerations of the possible restore types.
165 // Restore from the previous session.
166 RESTORE_LAST_SESSION_EXITED_CLEANLY
,
167 RESTORE_LAST_SESSION_CRASHED
,
169 // The entry has been restored from the current session. This is used when
170 // the user issues 'reopen closed tab'.
171 RESTORE_CURRENT_SESSION
,
173 // The entry was not restored.
177 // The RestoreType for this entry. This is set if the entry was retored. This
178 // is set to RESTORE_NONE once the entry is loaded.
179 void set_restore_type(RestoreType type
) {
180 restore_type_
= type
;
182 RestoreType
restore_type() const {
183 return restore_type_
;
186 void set_transferred_global_request_id(
187 const GlobalRequestID
& transferred_global_request_id
) {
188 transferred_global_request_id_
= transferred_global_request_id
;
191 GlobalRequestID
transferred_global_request_id() const {
192 return transferred_global_request_id_
;
195 // Whether this (pending) navigation needs to replace current entry.
196 // Resets to false after commit.
197 bool should_replace_entry() const {
198 return should_replace_entry_
;
201 void set_should_replace_entry(bool should_replace_entry
) {
202 should_replace_entry_
= should_replace_entry
;
205 void SetScreenshotPNGData(scoped_refptr
<base::RefCountedBytes
> png_data
);
206 const scoped_refptr
<base::RefCountedBytes
> screenshot() const {
210 // Whether this (pending) navigation should clear the session history. Resets
211 // to false after commit.
212 bool should_clear_history_list() const {
213 return should_clear_history_list_
;
215 void set_should_clear_history_list(bool should_clear_history_list
) {
216 should_clear_history_list_
= should_clear_history_list
;
219 // Indicates which FrameTreeNode to navigate. Currently only used if the
220 // --site-per-process flag is passed.
221 int64
frame_tree_node_id() const {
222 return frame_tree_node_id_
;
224 void set_frame_tree_node_id(int64 frame_tree_node_id
) {
225 frame_tree_node_id_
= frame_tree_node_id
;
228 // Returns the history URL for a data URL to use in Blink.
229 GURL
GetHistoryURLForDataURL() const;
231 #if defined(OS_ANDROID)
232 base::TimeTicks
intent_received_timestamp() const {
233 return intent_received_timestamp_
;
236 void set_intent_received_timestamp(
237 const base::TimeTicks intent_received_timestamp
) {
238 intent_received_timestamp_
= intent_received_timestamp
;
243 // WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
244 // Session/Tab restore save portions of this class so that it can be recreated
245 // later. If you add a new field that needs to be persisted you'll have to
246 // update SessionService/TabRestoreService and Android WebView
247 // state_serializer.cc appropriately.
248 // WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
250 // The FrameNavigationEntry for the main frame.
251 // TODO(creis): Make this a tree with nodes for each frame in the page.
252 FrameNavigationEntry frame_entry_
;
254 // See the accessors above for descriptions.
256 // TODO(creis): Persist bindings_. http://crbug.com/173672.
260 bool update_virtual_url_with_url_
;
261 base::string16 title_
;
262 FaviconStatus favicon_
;
263 PageState page_state_
;
266 ui::PageTransition transition_type_
;
267 GURL user_typed_url_
;
270 RestoreType restore_type_
;
271 GURL original_request_url_
;
272 bool is_overriding_user_agent_
;
273 base::Time timestamp_
;
274 int http_status_code_
;
276 // This member is not persisted with session restore because it is transient.
277 // If the post request succeeds, this field is cleared since the same
278 // information is stored in |content_state_| above. It is also only shallow
279 // copied with compiler provided copy constructor.
280 // Cleared in |ResetForCommit|.
281 scoped_refptr
<const base::RefCountedMemory
> browser_initiated_post_data_
;
283 // This is also a transient member (i.e. is not persisted with session
284 // restore). The screenshot of a page is taken when navigating away from the
285 // page. This screenshot is displayed during an overscroll-navigation
286 // gesture. |screenshot_| will be NULL when the screenshot is not available
287 // (e.g. after a session restore, or if taking the screenshot of a page
288 // failed). The UI is responsible for dealing with missing screenshots
289 // appropriately (e.g. display a placeholder image instead).
290 scoped_refptr
<base::RefCountedBytes
> screenshot_
;
292 // This member is not persisted with session restore.
293 std::string extra_headers_
;
295 // This member is cleared in |ResetForCommit| and not persisted.
296 scoped_refptr
<SiteInstanceImpl
> source_site_instance_
;
298 // Used for specifying base URL for pages loaded via data URLs. Only used and
299 // persisted by Android WebView.
300 GURL base_url_for_data_url_
;
302 // Whether the entry, while loading, was created for a renderer-initiated
303 // navigation. This dictates whether the URL should be displayed before the
304 // navigation commits. It is cleared in |ResetForCommit| and not persisted.
305 bool is_renderer_initiated_
;
307 // This is a cached version of the result of GetTitleForDisplay. It prevents
308 // us from having to do URL formatting on the URL every time the title is
309 // displayed. When the URL, virtual URL, or title is set, this should be
310 // cleared to force a refresh.
311 mutable base::string16 cached_display_title_
;
313 // In case a navigation is transferred to a new RVH but the request has
314 // been generated in the renderer already, this identifies the old request so
315 // that it can be resumed. The old request is stored until the
316 // ResourceDispatcher receives the navigation from the renderer which
317 // carries this |transferred_global_request_id_| annotation. Once the request
318 // is transferred to the new process, this is cleared and the request
319 // continues as normal.
320 // Cleared in |ResetForCommit|.
321 GlobalRequestID transferred_global_request_id_
;
323 // This is set to true when this entry is being reloaded and due to changes in
324 // the state of the URL, it has to be reloaded in a different site instance.
325 // In such case, we must treat it as an existing navigation in the new site
326 // instance, instead of a new navigation. This value should not be persisted
327 // and is cleared in |ResetForCommit|.
329 // We also use this flag for cross-process redirect navigations, so that the
330 // browser will replace the current navigation entry (which is the page
331 // doing the redirect).
332 bool should_replace_entry_
;
334 // This is used when transferring a pending entry from one process to another.
335 // We also send this data through session sync for offline analysis.
336 // It is preserved after commit but should not be persisted.
337 std::vector
<GURL
> redirect_chain_
;
339 // This is set to true when this entry's navigation should clear the session
340 // history both on the renderer and browser side. The browser side history
341 // won't be cleared until the renderer has committed this navigation. This
342 // entry is not persisted by the session restore system, as it is always
343 // cleared in |ResetForCommit|.
344 bool should_clear_history_list_
;
346 // Set when this entry should be able to access local file:// resources. This
347 // value is not needed after the entry commits and is not persisted.
348 bool can_load_local_resources_
;
350 // If not empty, the name of the frame to navigate. This field is not
351 // persisted, because it is currently only used in tests.
352 std::string frame_to_navigate_
;
354 // If not -1, this indicates which FrameTreeNode to navigate. This field is
355 // not persisted because it is experimental and only used when the
356 // --site-per-process flag is passed. It is cleared in |ResetForCommit|
357 // because we only use it while the navigation is pending.
358 // TODO(creis): Move this to FrameNavigationEntry.
359 int64 frame_tree_node_id_
;
361 #if defined(OS_ANDROID)
362 // The time at which Chrome received the Android Intent that triggered this
363 // URL load operation. Reset at commit and not persisted.
364 base::TimeTicks intent_received_timestamp_
;
367 // Used to store extra data to support browser features. This member is not
368 // persisted, unless specific data is taken out/put back in at save/restore
369 // time (see TabNavigation for an example of this).
370 std::map
<std::string
, base::string16
> extra_data_
;
372 // Copy and assignment is explicitly allowed for this class.
375 } // namespace content
377 #endif // CONTENT_BROWSER_FRAME_HOST_NAVIGATION_ENTRY_IMPL_H_