Pass FrameTreeNode (not RenderFrameHost) to NavigateToEntry.
[chromium-blink-merge.git] / content / browser / frame_host / navigation_request.h
blob948dbd1de14c8f64bd58ada794b97c2fc00e871e
1 // Copyright 2014 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_REQUEST_H_
6 #define CONTENT_BROWSER_FRAME_HOST_NAVIGATION_REQUEST_H_
8 #include "base/basictypes.h"
9 #include "base/memory/ref_counted.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "content/browser/frame_host/navigation_entry_impl.h"
12 #include "content/browser/loader/navigation_url_loader_delegate.h"
13 #include "content/common/content_export.h"
14 #include "content/common/frame_message_enums.h"
15 #include "content/common/navigation_params.h"
17 namespace content {
19 class FrameTreeNode;
20 class NavigationURLLoader;
21 class ResourceRequestBody;
22 class SiteInstanceImpl;
23 struct NavigationRequestInfo;
25 // PlzNavigate
26 // A UI thread object that owns a navigation request until it commits. It
27 // ensures the UI thread can start a navigation request in the
28 // ResourceDispatcherHost (that lives on the IO thread).
29 // TODO(clamy): Describe the interactions between the UI and IO thread during
30 // the navigation following its refactoring.
31 class CONTENT_EXPORT NavigationRequest : public NavigationURLLoaderDelegate {
32 public:
33 // Keeps track of the various stages of a NavigationRequest.
34 enum NavigationState {
35 // Initial state.
36 NOT_STARTED = 0,
38 // Waiting for a BeginNavigation IPC from the renderer in a
39 // browser-initiated navigation. If there is no live renderer when the
40 // request is created, this stage is skipped.
41 WAITING_FOR_RENDERER_RESPONSE,
43 // The request was sent to the IO thread.
44 STARTED,
46 // The response started on the IO thread and is ready to be committed. This
47 // is one of the two final states for the request.
48 RESPONSE_STARTED,
50 // The request failed on the IO thread and an error page should be
51 // displayed. This is one of the two final states for the request.
52 FAILED,
55 // Creates a request for a browser-intiated navigation.
56 static scoped_ptr<NavigationRequest> CreateBrowserInitiated(
57 FrameTreeNode* frame_tree_node,
58 const NavigationEntryImpl& entry,
59 FrameMsg_Navigate_Type::Value navigation_type,
60 base::TimeTicks navigation_start);
62 // Creates a request for a renderer-intiated navigation.
63 // Note: |body| is sent to the IO thread when calling BeginNavigation, and
64 // should no longer be manipulated afterwards on the UI thread.
65 static scoped_ptr<NavigationRequest> CreateRendererInitiated(
66 FrameTreeNode* frame_tree_node,
67 const CommonNavigationParams& common_params,
68 const BeginNavigationParams& begin_params,
69 scoped_refptr<ResourceRequestBody> body);
71 ~NavigationRequest() override;
73 // Called on the UI thread by the Navigator to start the navigation on the IO
74 // thread.
75 // TODO(clamy): see if ResourceRequestBody could be un-refcounted to avoid
76 // threading subtleties.
77 void BeginNavigation();
79 const CommonNavigationParams& common_params() const { return common_params_; }
81 const BeginNavigationParams& begin_params() const { return begin_params_; }
83 const CommitNavigationParams& commit_params() const { return commit_params_; }
85 NavigationURLLoader* loader_for_testing() const { return loader_.get(); }
87 NavigationState state() const { return state_; }
89 SiteInstanceImpl* source_site_instance() const {
90 return source_site_instance_.get();
93 SiteInstanceImpl* dest_site_instance() const {
94 return dest_site_instance_.get();
97 NavigationEntryImpl::RestoreType restore_type() const {
98 return restore_type_;
101 bool is_view_source() const { return is_view_source_; };
103 int bindings() const { return bindings_; };
105 bool browser_initiated() const { return browser_initiated_ ; }
107 void SetWaitingForRendererResponse() {
108 DCHECK(state_ == NOT_STARTED);
109 state_ = WAITING_FOR_RENDERER_RESPONSE;
112 private:
113 NavigationRequest(FrameTreeNode* frame_tree_node,
114 const CommonNavigationParams& common_params,
115 const BeginNavigationParams& begin_params,
116 const CommitNavigationParams& commit_params,
117 scoped_refptr<ResourceRequestBody> body,
118 bool browser_initiated,
119 const NavigationEntryImpl* navitation_entry);
121 // NavigationURLLoaderDelegate implementation.
122 void OnRequestRedirected(
123 const net::RedirectInfo& redirect_info,
124 const scoped_refptr<ResourceResponse>& response) override;
125 void OnResponseStarted(const scoped_refptr<ResourceResponse>& response,
126 scoped_ptr<StreamHandle> body) override;
127 void OnRequestFailed(int net_error) override;
128 void OnRequestStarted(base::TimeTicks timestamp) override;
130 FrameTreeNode* frame_tree_node_;
132 // Initialized on creation of the NavigationRequest. Sent to the renderer when
133 // the navigation is ready to commit.
134 // Note: When the navigation is ready to commit, the url in |common_params|
135 // will be set to the final navigation url, obtained after following all
136 // redirects.
137 CommonNavigationParams common_params_;
138 const BeginNavigationParams begin_params_;
139 const CommitNavigationParams commit_params_;
140 const bool browser_initiated_;
142 NavigationState state_;
145 // The parameters to send to the IO thread. |loader_| takes ownership of
146 // |info_| after calling BeginNavigation.
147 scoped_ptr<NavigationRequestInfo> info_;
149 scoped_ptr<NavigationURLLoader> loader_;
151 // These next items are used in browser-initiated navigations to store
152 // information from the NavigationEntryImpl that is required after request
153 // creation time.
154 scoped_refptr<SiteInstanceImpl> source_site_instance_;
155 scoped_refptr<SiteInstanceImpl> dest_site_instance_;
156 NavigationEntryImpl::RestoreType restore_type_;
157 bool is_view_source_;
158 int bindings_;
160 DISALLOW_COPY_AND_ASSIGN(NavigationRequest);
163 } // namespace content
165 #endif // CONTENT_BROWSER_FRAME_HOST_NAVIGATION_REQUEST_H_