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