Use multiline attribute to check for IA2_STATE_MULTILINE.
[chromium-blink-merge.git] / content / browser / frame_host / navigation_entry_impl.h
blob9bebe15caa60124aa973b032054b76ad856efe97
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/memory/scoped_vector.h"
11 #include "base/time/time.h"
12 #include "content/browser/frame_host/frame_navigation_entry.h"
13 #include "content/browser/site_instance_impl.h"
14 #include "content/common/frame_message_enums.h"
15 #include "content/public/browser/favicon_status.h"
16 #include "content/public/browser/global_request_id.h"
17 #include "content/public/browser/navigation_entry.h"
18 #include "content/public/common/page_state.h"
19 #include "content/public/common/ssl_status.h"
21 namespace content {
22 struct CommonNavigationParams;
23 struct RequestNavigationParams;
24 struct StartNavigationParams;
26 class CONTENT_EXPORT NavigationEntryImpl
27 : public NON_EXPORTED_BASE(NavigationEntry) {
28 public:
29 // Represents a tree of FrameNavigationEntries that make up this joint session
30 // history item. The tree currently only tracks the main frame.
31 // TODO(creis): Populate the tree with subframe entries in --site-per-process.
32 struct TreeNode {
33 TreeNode(FrameNavigationEntry* frame_entry);
34 ~TreeNode();
36 // Returns a deep copy of the tree with copies of each node's
37 // FrameNavigationEntries. We do not yet share FrameNavigationEntries
38 // across trees.
39 // TODO(creis): For --site-per-process, share FrameNavigationEntries between
40 // NavigationEntries of the same tab.
41 TreeNode* Clone() const;
43 // Ref counted pointer that keeps the FrameNavigationEntry alive as long as
44 // it is needed by this node's NavigationEntry.
45 scoped_refptr<FrameNavigationEntry> frame_entry;
47 // List of child TreeNodes, which will be deleted when this node is.
48 ScopedVector<TreeNode> children;
51 static NavigationEntryImpl* FromNavigationEntry(NavigationEntry* entry);
53 // The value of bindings() before it is set during commit.
54 static int kInvalidBindings;
56 NavigationEntryImpl();
57 NavigationEntryImpl(SiteInstanceImpl* instance,
58 int page_id,
59 const GURL& url,
60 const Referrer& referrer,
61 const base::string16& title,
62 ui::PageTransition transition_type,
63 bool is_renderer_initiated);
64 ~NavigationEntryImpl() override;
66 // NavigationEntry implementation:
67 int GetUniqueID() const override;
68 PageType GetPageType() const override;
69 void SetURL(const GURL& url) override;
70 const GURL& GetURL() const override;
71 void SetBaseURLForDataURL(const GURL& url) override;
72 const GURL& GetBaseURLForDataURL() const override;
73 void SetReferrer(const Referrer& referrer) override;
74 const Referrer& GetReferrer() const override;
75 void SetVirtualURL(const GURL& url) override;
76 const GURL& GetVirtualURL() const override;
77 void SetTitle(const base::string16& title) override;
78 const base::string16& GetTitle() const override;
79 void SetPageState(const PageState& state) override;
80 const PageState& GetPageState() const override;
81 void SetPageID(int page_id) override;
82 int32 GetPageID() const override;
83 const base::string16& GetTitleForDisplay(
84 const std::string& languages) const override;
85 bool IsViewSourceMode() const override;
86 void SetTransitionType(ui::PageTransition transition_type) override;
87 ui::PageTransition GetTransitionType() const override;
88 const GURL& GetUserTypedURL() const override;
89 void SetHasPostData(bool has_post_data) override;
90 bool GetHasPostData() const override;
91 void SetPostID(int64 post_id) override;
92 int64 GetPostID() const override;
93 void SetBrowserInitiatedPostData(const base::RefCountedMemory* data) override;
94 const base::RefCountedMemory* GetBrowserInitiatedPostData() const override;
95 const FaviconStatus& GetFavicon() const override;
96 FaviconStatus& GetFavicon() override;
97 const SSLStatus& GetSSL() const override;
98 SSLStatus& GetSSL() override;
99 void SetOriginalRequestURL(const GURL& original_url) override;
100 const GURL& GetOriginalRequestURL() const override;
101 void SetIsOverridingUserAgent(bool override) override;
102 bool GetIsOverridingUserAgent() const override;
103 void SetTimestamp(base::Time timestamp) override;
104 base::Time GetTimestamp() const override;
105 void SetCanLoadLocalResources(bool allow) override;
106 bool GetCanLoadLocalResources() const override;
107 void SetFrameToNavigate(const std::string& frame_name) override;
108 const std::string& GetFrameToNavigate() const override;
109 void SetExtraData(const std::string& key,
110 const base::string16& data) override;
111 bool GetExtraData(const std::string& key,
112 base::string16* data) const override;
113 void ClearExtraData(const std::string& key) override;
114 void SetHttpStatusCode(int http_status_code) override;
115 int GetHttpStatusCode() const override;
116 void SetRedirectChain(const std::vector<GURL>& redirects) override;
117 const std::vector<GURL>& GetRedirectChain() const override;
118 bool IsRestored() const override;
120 // Creates a copy of this NavigationEntryImpl that can be modified
121 // independently from the original. Does not copy any value that would be
122 // cleared in ResetForCommit.
123 // TODO(creis): Once we start sharing FrameNavigationEntries between
124 // NavigationEntryImpls, we will need to support two versions of Clone: one
125 // that shares the existing FrameNavigationEntries (for use within the same
126 // tab) and one that draws them from a different pool (for use in a new tab).
127 NavigationEntryImpl* Clone() const;
129 // Helper functions to construct NavigationParameters for a navigation to this
130 // NavigationEntry.
131 CommonNavigationParams ConstructCommonNavigationParams(
132 FrameMsg_Navigate_Type::Value navigation_type) const;
133 StartNavigationParams ConstructStartNavigationParams() const;
134 RequestNavigationParams ConstructRequestNavigationParams(
135 base::TimeTicks navigation_start,
136 int pending_offset_to_send,
137 int current_offset_to_send,
138 int current_length_to_send) const;
140 // Once a navigation entry is committed, we should no longer track several
141 // pieces of non-persisted state, as documented on the members below.
142 void ResetForCommit();
144 // Exposes the tree of FrameNavigationEntries that make up this joint session
145 // history item.
146 // In default Chrome, this tree only has a root node with an unshared
147 // FrameNavigationEntry. Subframes are only added to the tree if the
148 // --site-per-process flag is passed.
149 TreeNode* root_node() const {
150 return frame_tree_.get();
153 // Finds the TreeNode associated with |frame_tree_node_id| to add or update
154 // its FrameNavigationEntry. A new FrameNavigationEntry is added if none
155 // exists, or else the existing one (which might be shared with other
156 // NavigationEntries) is updated with the given parameters.
157 void AddOrUpdateFrameEntry(int64 frame_tree_node_id,
158 SiteInstanceImpl* site_instance,
159 const GURL& url,
160 const Referrer& referrer);
162 void set_unique_id(int unique_id) {
163 unique_id_ = unique_id;
166 // The SiteInstance represents which pages must share processes. This is a
167 // reference counted pointer to a shared SiteInstance.
169 // Note that the SiteInstance should usually not be changed after it is set,
170 // but this may happen if the NavigationEntry was cloned and needs to use a
171 // different SiteInstance.
172 void set_site_instance(SiteInstanceImpl* site_instance);
173 SiteInstanceImpl* site_instance() const {
174 return frame_tree_->frame_entry->site_instance();
177 // The |source_site_instance| is used to identify the SiteInstance of the
178 // frame that initiated the navigation.
179 void set_source_site_instance(SiteInstanceImpl* source_site_instance);
180 SiteInstanceImpl* source_site_instance() const {
181 return source_site_instance_.get();
184 // Remember the set of bindings granted to this NavigationEntry at the time
185 // of commit, to ensure that we do not grant it additional bindings if we
186 // navigate back to it in the future. This can only be changed once.
187 void SetBindings(int bindings);
188 int bindings() const {
189 return bindings_;
192 void set_page_type(PageType page_type) {
193 page_type_ = page_type;
196 bool has_virtual_url() const {
197 return !virtual_url_.is_empty();
200 bool update_virtual_url_with_url() const {
201 return update_virtual_url_with_url_;
203 void set_update_virtual_url_with_url(bool update) {
204 update_virtual_url_with_url_ = update;
207 // Extra headers (separated by \n) to send during the request.
208 void set_extra_headers(const std::string& extra_headers) {
209 extra_headers_ = extra_headers;
211 const std::string& extra_headers() const {
212 return extra_headers_;
215 // Whether this (pending) navigation is renderer-initiated. Resets to false
216 // for all types of navigations after commit.
217 void set_is_renderer_initiated(bool is_renderer_initiated) {
218 is_renderer_initiated_ = is_renderer_initiated;
220 bool is_renderer_initiated() const {
221 return is_renderer_initiated_;
224 void set_user_typed_url(const GURL& user_typed_url) {
225 user_typed_url_ = user_typed_url;
228 // Enumerations of the possible restore types.
229 enum RestoreType {
230 // Restore from the previous session.
231 RESTORE_LAST_SESSION_EXITED_CLEANLY,
232 RESTORE_LAST_SESSION_CRASHED,
234 // The entry has been restored from the current session. This is used when
235 // the user issues 'reopen closed tab'.
236 RESTORE_CURRENT_SESSION,
238 // The entry was not restored.
239 RESTORE_NONE
242 // The RestoreType for this entry. This is set if the entry was retored. This
243 // is set to RESTORE_NONE once the entry is loaded.
244 void set_restore_type(RestoreType type) {
245 restore_type_ = type;
247 RestoreType restore_type() const {
248 return restore_type_;
251 void set_transferred_global_request_id(
252 const GlobalRequestID& transferred_global_request_id) {
253 transferred_global_request_id_ = transferred_global_request_id;
256 GlobalRequestID transferred_global_request_id() const {
257 return transferred_global_request_id_;
260 // Whether this (pending) navigation needs to replace current entry.
261 // Resets to false after commit.
262 bool should_replace_entry() const {
263 return should_replace_entry_;
266 void set_should_replace_entry(bool should_replace_entry) {
267 should_replace_entry_ = should_replace_entry;
270 void SetScreenshotPNGData(scoped_refptr<base::RefCountedBytes> png_data);
271 const scoped_refptr<base::RefCountedBytes> screenshot() const {
272 return screenshot_;
275 // Whether this (pending) navigation should clear the session history. Resets
276 // to false after commit.
277 bool should_clear_history_list() const {
278 return should_clear_history_list_;
280 void set_should_clear_history_list(bool should_clear_history_list) {
281 should_clear_history_list_ = should_clear_history_list;
284 // Indicates which FrameTreeNode to navigate. Currently only used if the
285 // --site-per-process flag is passed.
286 int64 frame_tree_node_id() const {
287 return frame_tree_node_id_;
289 void set_frame_tree_node_id(int64 frame_tree_node_id) {
290 frame_tree_node_id_ = frame_tree_node_id;
293 // Returns the history URL for a data URL to use in Blink.
294 GURL GetHistoryURLForDataURL() const;
296 #if defined(OS_ANDROID)
297 base::TimeTicks intent_received_timestamp() const {
298 return intent_received_timestamp_;
301 void set_intent_received_timestamp(
302 const base::TimeTicks intent_received_timestamp) {
303 intent_received_timestamp_ = intent_received_timestamp;
305 #endif
307 private:
308 // WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
309 // Session/Tab restore save portions of this class so that it can be recreated
310 // later. If you add a new field that needs to be persisted you'll have to
311 // update SessionService/TabRestoreService and Android WebView
312 // state_serializer.cc appropriately.
313 // For all new fields, update |Clone| and possibly |ResetForCommit|.
314 // WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
316 // Tree of FrameNavigationEntries, one for each frame on the page.
317 // TODO(creis): Once FrameNavigationEntries can be shared across multiple
318 // NavigationEntries, we will need to update Session/Tab restore. For now,
319 // each NavigationEntry's tree has its own unshared FrameNavigationEntries.
320 scoped_ptr<TreeNode> frame_tree_;
322 // See the accessors above for descriptions.
323 int unique_id_;
324 // TODO(creis): Persist bindings_. http://crbug.com/173672.
325 int bindings_;
326 PageType page_type_;
327 GURL virtual_url_;
328 bool update_virtual_url_with_url_;
329 base::string16 title_;
330 FaviconStatus favicon_;
331 PageState page_state_;
332 int32 page_id_;
333 SSLStatus ssl_;
334 ui::PageTransition transition_type_;
335 GURL user_typed_url_;
336 bool has_post_data_;
337 int64 post_id_;
338 RestoreType restore_type_;
339 GURL original_request_url_;
340 bool is_overriding_user_agent_;
341 base::Time timestamp_;
342 int http_status_code_;
344 // This member is not persisted with session restore because it is transient.
345 // If the post request succeeds, this field is cleared since the same
346 // information is stored in |content_state_| above. It is also only shallow
347 // copied with compiler provided copy constructor.
348 // Cleared in |ResetForCommit|.
349 scoped_refptr<const base::RefCountedMemory> browser_initiated_post_data_;
351 // This is also a transient member (i.e. is not persisted with session
352 // restore). The screenshot of a page is taken when navigating away from the
353 // page. This screenshot is displayed during an overscroll-navigation
354 // gesture. |screenshot_| will be NULL when the screenshot is not available
355 // (e.g. after a session restore, or if taking the screenshot of a page
356 // failed). The UI is responsible for dealing with missing screenshots
357 // appropriately (e.g. display a placeholder image instead).
358 scoped_refptr<base::RefCountedBytes> screenshot_;
360 // This member is not persisted with session restore.
361 std::string extra_headers_;
363 // This member is cleared in |ResetForCommit| and not persisted.
364 scoped_refptr<SiteInstanceImpl> source_site_instance_;
366 // Used for specifying base URL for pages loaded via data URLs. Only used and
367 // persisted by Android WebView.
368 GURL base_url_for_data_url_;
370 // Whether the entry, while loading, was created for a renderer-initiated
371 // navigation. This dictates whether the URL should be displayed before the
372 // navigation commits. It is cleared in |ResetForCommit| and not persisted.
373 bool is_renderer_initiated_;
375 // This is a cached version of the result of GetTitleForDisplay. It prevents
376 // us from having to do URL formatting on the URL every time the title is
377 // displayed. When the URL, virtual URL, or title is set, this should be
378 // cleared to force a refresh.
379 mutable base::string16 cached_display_title_;
381 // In case a navigation is transferred to a new RVH but the request has
382 // been generated in the renderer already, this identifies the old request so
383 // that it can be resumed. The old request is stored until the
384 // ResourceDispatcher receives the navigation from the renderer which
385 // carries this |transferred_global_request_id_| annotation. Once the request
386 // is transferred to the new process, this is cleared and the request
387 // continues as normal.
388 // Cleared in |ResetForCommit|.
389 GlobalRequestID transferred_global_request_id_;
391 // This is set to true when this entry is being reloaded and due to changes in
392 // the state of the URL, it has to be reloaded in a different site instance.
393 // In such case, we must treat it as an existing navigation in the new site
394 // instance, instead of a new navigation. This value should not be persisted
395 // and is cleared in |ResetForCommit|.
397 // We also use this flag for cross-process redirect navigations, so that the
398 // browser will replace the current navigation entry (which is the page
399 // doing the redirect).
400 bool should_replace_entry_;
402 // This is used when transferring a pending entry from one process to another.
403 // We also send this data through session sync for offline analysis.
404 // It is preserved after commit but should not be persisted.
405 std::vector<GURL> redirect_chain_;
407 // This is set to true when this entry's navigation should clear the session
408 // history both on the renderer and browser side. The browser side history
409 // won't be cleared until the renderer has committed this navigation. This
410 // entry is not persisted by the session restore system, as it is always
411 // cleared in |ResetForCommit|.
412 bool should_clear_history_list_;
414 // Set when this entry should be able to access local file:// resources. This
415 // value is not needed after the entry commits and is not persisted.
416 bool can_load_local_resources_;
418 // If not empty, the name of the frame to navigate. This field is not
419 // persisted, because it is currently only used in tests.
420 std::string frame_to_navigate_;
422 // If not -1, this indicates which FrameTreeNode to navigate. This field is
423 // not persisted because it is experimental and only used when the
424 // --site-per-process flag is passed. It is cleared in |ResetForCommit|
425 // because we only use it while the navigation is pending.
426 // TODO(creis): Move this to FrameNavigationEntry.
427 int64 frame_tree_node_id_;
429 #if defined(OS_ANDROID)
430 // The time at which Chrome received the Android Intent that triggered this
431 // URL load operation. Reset at commit and not persisted.
432 base::TimeTicks intent_received_timestamp_;
433 #endif
435 // Used to store extra data to support browser features. This member is not
436 // persisted, unless specific data is taken out/put back in at save/restore
437 // time (see TabNavigation for an example of this).
438 std::map<std::string, base::string16> extra_data_;
440 DISALLOW_COPY_AND_ASSIGN(NavigationEntryImpl);
443 } // namespace content
445 #endif // CONTENT_BROWSER_FRAME_HOST_NAVIGATION_ENTRY_IMPL_H_