Add remoting and PPAPI tests to GN build
[chromium-blink-merge.git] / content / browser / frame_host / navigation_request.h
blob56e993d7af3bbbee19f9378eecdaea72bb20ec82
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 // Helper function to determine if the navigation request to |url| should be
56 // sent to the network stack.
57 static bool ShouldMakeNetworkRequest(const GURL& url);
59 // Creates a request for a browser-intiated navigation.
60 static scoped_ptr<NavigationRequest> CreateBrowserInitiated(
61 FrameTreeNode* frame_tree_node,
62 const NavigationEntryImpl& entry,
63 FrameMsg_Navigate_Type::Value navigation_type,
64 base::TimeTicks navigation_start);
66 // Creates a request for a renderer-intiated navigation.
67 // Note: |body| is sent to the IO thread when calling BeginNavigation, and
68 // should no longer be manipulated afterwards on the UI thread.
69 static scoped_ptr<NavigationRequest> CreateRendererInitiated(
70 FrameTreeNode* frame_tree_node,
71 const CommonNavigationParams& common_params,
72 const BeginNavigationParams& begin_params,
73 scoped_refptr<ResourceRequestBody> body);
75 ~NavigationRequest() override;
77 // Called on the UI thread by the Navigator to start the navigation. Returns
78 // whether a request was made on the IO thread.
79 // TODO(clamy): see if ResourceRequestBody could be un-refcounted to avoid
80 // threading subtleties.
81 bool BeginNavigation();
83 const CommonNavigationParams& common_params() const { return common_params_; }
85 const BeginNavigationParams& begin_params() const { return begin_params_; }
87 const CommitNavigationParams& commit_params() const { return commit_params_; }
89 NavigationURLLoader* loader_for_testing() const { return loader_.get(); }
91 NavigationState state() const { return state_; }
93 SiteInstanceImpl* source_site_instance() const {
94 return source_site_instance_.get();
97 SiteInstanceImpl* dest_site_instance() const {
98 return dest_site_instance_.get();
101 NavigationEntryImpl::RestoreType restore_type() const {
102 return restore_type_;
105 bool is_view_source() const { return is_view_source_; };
107 int bindings() const { return bindings_; };
109 bool browser_initiated() const { return browser_initiated_ ; }
111 void SetWaitingForRendererResponse() {
112 DCHECK(state_ == NOT_STARTED);
113 state_ = WAITING_FOR_RENDERER_RESPONSE;
116 private:
117 NavigationRequest(FrameTreeNode* frame_tree_node,
118 const CommonNavigationParams& common_params,
119 const BeginNavigationParams& begin_params,
120 const CommitNavigationParams& commit_params,
121 scoped_refptr<ResourceRequestBody> body,
122 bool browser_initiated,
123 const NavigationEntryImpl* navitation_entry);
125 // NavigationURLLoaderDelegate implementation.
126 void OnRequestRedirected(
127 const net::RedirectInfo& redirect_info,
128 const scoped_refptr<ResourceResponse>& response) override;
129 void OnResponseStarted(const scoped_refptr<ResourceResponse>& response,
130 scoped_ptr<StreamHandle> body) override;
131 void OnRequestFailed(int net_error) override;
132 void OnRequestStarted(base::TimeTicks timestamp) override;
134 FrameTreeNode* frame_tree_node_;
136 // Initialized on creation of the NavigationRequest. Sent to the renderer when
137 // the navigation is ready to commit.
138 // Note: When the navigation is ready to commit, the url in |common_params|
139 // will be set to the final navigation url, obtained after following all
140 // redirects.
141 CommonNavigationParams common_params_;
142 const BeginNavigationParams begin_params_;
143 const CommitNavigationParams commit_params_;
144 const bool browser_initiated_;
146 NavigationState state_;
149 // The parameters to send to the IO thread. |loader_| takes ownership of
150 // |info_| after calling BeginNavigation.
151 scoped_ptr<NavigationRequestInfo> info_;
153 scoped_ptr<NavigationURLLoader> loader_;
155 // These next items are used in browser-initiated navigations to store
156 // information from the NavigationEntryImpl that is required after request
157 // creation time.
158 scoped_refptr<SiteInstanceImpl> source_site_instance_;
159 scoped_refptr<SiteInstanceImpl> dest_site_instance_;
160 NavigationEntryImpl::RestoreType restore_type_;
161 bool is_view_source_;
162 int bindings_;
164 DISALLOW_COPY_AND_ASSIGN(NavigationRequest);
167 } // namespace content
169 #endif // CONTENT_BROWSER_FRAME_HOST_NAVIGATION_REQUEST_H_