Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(171)

Side by Side Diff: content/browser/frame_host/navigation_handle_impl.h

Issue 2321543002: Merge CrossSiteResourceHandler and NavigationResourceThrottle (Closed)
Patch Set: Addressed comments Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef CONTENT_BROWSER_FRAME_HOST_NAVIGATION_HANDLE_IMPL_H_ 5 #ifndef CONTENT_BROWSER_FRAME_HOST_NAVIGATION_HANDLE_IMPL_H_
6 #define CONTENT_BROWSER_FRAME_HOST_NAVIGATION_HANDLE_IMPL_H_ 6 #define CONTENT_BROWSER_FRAME_HOST_NAVIGATION_HANDLE_IMPL_H_
7 7
8 #include "content/public/browser/navigation_handle.h" 8 #include "content/public/browser/navigation_handle.h"
9 9
10 #include <stddef.h> 10 #include <stddef.h>
11 11
12 #include "base/callback.h" 12 #include "base/callback.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/memory/ref_counted.h" 14 #include "base/memory/ref_counted.h"
15 #include "base/memory/scoped_vector.h" 15 #include "base/memory/scoped_vector.h"
16 #include "content/browser/frame_host/frame_tree_node.h" 16 #include "content/browser/frame_host/frame_tree_node.h"
17 #include "content/browser/frame_host/render_frame_host_impl.h" 17 #include "content/browser/frame_host/render_frame_host_impl.h"
18 #include "content/common/content_export.h" 18 #include "content/common/content_export.h"
19 #include "content/public/browser/global_request_id.h"
19 #include "content/public/browser/navigation_data.h" 20 #include "content/public/browser/navigation_data.h"
20 #include "content/public/browser/navigation_throttle.h" 21 #include "content/public/browser/navigation_throttle.h"
21 #include "content/public/common/request_context_type.h" 22 #include "content/public/common/request_context_type.h"
22 #include "content/public/common/ssl_status.h" 23 #include "content/public/common/ssl_status.h"
23 #include "url/gurl.h" 24 #include "url/gurl.h"
24 25
25 struct FrameHostMsg_DidCommitProvisionalLoad_Params; 26 struct FrameHostMsg_DidCommitProvisionalLoad_Params;
26 27
27 namespace content { 28 namespace content {
28 29
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 145
145 // Returns whether the navigation is currently being transferred from one 146 // Returns whether the navigation is currently being transferred from one
146 // RenderFrameHost to another. In particular, a DidStartProvisionalLoad IPC 147 // RenderFrameHost to another. In particular, a DidStartProvisionalLoad IPC
147 // for the navigation URL, received in the new RenderFrameHost, should not 148 // for the navigation URL, received in the new RenderFrameHost, should not
148 // indicate the start of a new navigation in that case. 149 // indicate the start of a new navigation in that case.
149 bool is_transferring() const { return is_transferring_; } 150 bool is_transferring() const { return is_transferring_; }
150 void set_is_transferring(bool is_transferring) { 151 void set_is_transferring(bool is_transferring) {
151 is_transferring_ = is_transferring; 152 is_transferring_ = is_transferring;
152 } 153 }
153 154
154 // Updates the RenderFrameHost that is about to commit the navigation. This
155 // is used during transfer navigations.
156 void set_render_frame_host(RenderFrameHostImpl* render_frame_host) {
157 render_frame_host_ = render_frame_host;
158 }
159
160 // Returns the POST body associated with this navigation. This will be 155 // Returns the POST body associated with this navigation. This will be
161 // null for GET and/or other non-POST requests (or if a response to a POST 156 // null for GET and/or other non-POST requests (or if a response to a POST
162 // request was a redirect that changed the method to GET - for example 302). 157 // request was a redirect that changed the method to GET - for example 302).
163 const scoped_refptr<ResourceRequestBodyImpl>& resource_request_body() const { 158 const scoped_refptr<ResourceRequestBodyImpl>& resource_request_body() const {
164 return resource_request_body_; 159 return resource_request_body_;
165 } 160 }
166 161
167 typedef base::Callback<void(NavigationThrottle::ThrottleCheckResult)> 162 typedef base::Callback<void(NavigationThrottle::ThrottleCheckResult)>
168 ThrottleChecksFinishedCallback; 163 ThrottleChecksFinishedCallback;
169 164
(...skipping 21 matching lines...) Expand all
191 bool new_is_external_protocol, 186 bool new_is_external_protocol,
192 scoped_refptr<net::HttpResponseHeaders> response_headers, 187 scoped_refptr<net::HttpResponseHeaders> response_headers,
193 const ThrottleChecksFinishedCallback& callback); 188 const ThrottleChecksFinishedCallback& callback);
194 189
195 // Called when the URLRequest has delivered response headers and metadata. 190 // Called when the URLRequest has delivered response headers and metadata.
196 // |callback| will be called when all throttle checks have completed, 191 // |callback| will be called when all throttle checks have completed,
197 // allowing the caller to cancel the navigation or let it proceed. 192 // allowing the caller to cancel the navigation or let it proceed.
198 // NavigationHandle will not call |callback| with a result of DEFER. 193 // NavigationHandle will not call |callback| with a result of DEFER.
199 // If the result is PROCEED, then 'ReadyToCommitNavigation' will be called 194 // If the result is PROCEED, then 'ReadyToCommitNavigation' will be called
200 // with |render_frame_host| and |response_headers| just before calling 195 // with |render_frame_host| and |response_headers| just before calling
201 // |callback|. 196 // |callback|. Should a transfer navigation happen, |transfer_callback| will
197 // be run on the IO thread.
198 // PlzNavigate: transfer navigations are not possible.
202 void WillProcessResponse( 199 void WillProcessResponse(
203 RenderFrameHostImpl* render_frame_host, 200 RenderFrameHostImpl* render_frame_host,
204 scoped_refptr<net::HttpResponseHeaders> response_headers, 201 scoped_refptr<net::HttpResponseHeaders> response_headers,
205 const SSLStatus& ssl_status, 202 const SSLStatus& ssl_status,
203 const GlobalRequestID& request_id,
204 bool should_replace_current_entry,
205 bool is_download,
206 bool is_stream,
207 const base::Closure& transfer_callback,
206 const ThrottleChecksFinishedCallback& callback); 208 const ThrottleChecksFinishedCallback& callback);
207 209
208 // Returns the FrameTreeNode this navigation is happening in. 210 // Returns the FrameTreeNode this navigation is happening in.
209 FrameTreeNode* frame_tree_node() { return frame_tree_node_; } 211 FrameTreeNode* frame_tree_node() { return frame_tree_node_; }
210 212
211 // Called when the navigation is ready to be committed in 213 // Called when the navigation is ready to be committed in
212 // |render_frame_host|. This will update the |state_| and inform the 214 // |render_frame_host|. This will update the |state_| and inform the
213 // delegate. 215 // delegate.
214 void ReadyToCommitNavigation(RenderFrameHostImpl* render_frame_host); 216 void ReadyToCommitNavigation(RenderFrameHostImpl* render_frame_host);
215 217
216 // Called when the navigation was committed in |render_frame_host|. This will 218 // Called when the navigation was committed in |render_frame_host|. This will
217 // update the |state_|. 219 // update the |state_|.
218 void DidCommitNavigation( 220 void DidCommitNavigation(
219 const FrameHostMsg_DidCommitProvisionalLoad_Params& params, 221 const FrameHostMsg_DidCommitProvisionalLoad_Params& params,
220 bool same_page, 222 bool same_page,
221 RenderFrameHostImpl* render_frame_host); 223 RenderFrameHostImpl* render_frame_host);
222 224
223 // Called during commit. Takes ownership of the embedder's NavigationData 225 // Called during commit. Takes ownership of the embedder's NavigationData
224 // instance. This NavigationData may have been cloned prior to being added 226 // instance. This NavigationData may have been cloned prior to being added
225 // here. 227 // here.
226 void set_navigation_data(std::unique_ptr<NavigationData> navigation_data) { 228 void set_navigation_data(std::unique_ptr<NavigationData> navigation_data) {
227 navigation_data_ = std::move(navigation_data); 229 navigation_data_ = std::move(navigation_data);
228 } 230 }
229 231
230 SSLStatus ssl_status() { return ssl_status_; } 232 SSLStatus ssl_status() { return ssl_status_; }
231 233
234 const GlobalRequestID& request_id() const { return request_id_; }
235
236 // Called when the navigation is transferred to a RenderFrameHost.
237 void TransferToRenderFrameHost(RenderFrameHostImpl* render_frame_host);
238
232 private: 239 private:
233 friend class NavigationHandleImplTest; 240 friend class NavigationHandleImplTest;
234 241
235 // Used to track the state the navigation is currently in. 242 // Used to track the state the navigation is currently in.
236 enum State { 243 enum State {
237 INITIAL = 0, 244 INITIAL = 0,
238 WILL_SEND_REQUEST, 245 WILL_SEND_REQUEST,
239 DEFERRING_START, 246 DEFERRING_START,
240 WILL_REDIRECT_REQUEST, 247 WILL_REDIRECT_REQUEST,
241 DEFERRING_REDIRECT, 248 DEFERRING_REDIRECT,
(...skipping 10 matching lines...) Expand all
252 bool is_renderer_initiated, 259 bool is_renderer_initiated,
253 bool is_synchronous, 260 bool is_synchronous,
254 bool is_srcdoc, 261 bool is_srcdoc,
255 const base::TimeTicks& navigation_start, 262 const base::TimeTicks& navigation_start,
256 int pending_nav_entry_id); 263 int pending_nav_entry_id);
257 264
258 NavigationThrottle::ThrottleCheckResult CheckWillStartRequest(); 265 NavigationThrottle::ThrottleCheckResult CheckWillStartRequest();
259 NavigationThrottle::ThrottleCheckResult CheckWillRedirectRequest(); 266 NavigationThrottle::ThrottleCheckResult CheckWillRedirectRequest();
260 NavigationThrottle::ThrottleCheckResult CheckWillProcessResponse(); 267 NavigationThrottle::ThrottleCheckResult CheckWillProcessResponse();
261 268
269 // Called when WillProcessResponse checks are done, to find the final
270 // RenderFrameHost for the navigation. Returns true if the navigation should
271 // proceed.
272 bool FindFinalRenderFrameHost();
273
274 // Check whether the navigation should be transferred. Returns false if the
275 // transfer attempt results in the destruction of this NavigationHandle.
276 bool MaybeTransferAndProceed();
277
262 // Helper function to run and reset the |complete_callback_|. This marks the 278 // Helper function to run and reset the |complete_callback_|. This marks the
263 // end of a round of NavigationThrottleChecks. 279 // end of a round of NavigationThrottleChecks.
264 void RunCompleteCallback(NavigationThrottle::ThrottleCheckResult result); 280 void RunCompleteCallback(NavigationThrottle::ThrottleCheckResult result);
265 281
266 // Used in tests. 282 // Used in tests.
267 State state() const { return state_; } 283 State state() const { return state_; }
268 284
269 // Populates |throttles_| with the throttles for this navigation. 285 // Populates |throttles_| with the throttles for this navigation.
270 void RegisterNavigationThrottles(); 286 void RegisterNavigationThrottles();
271 287
272 // See NavigationHandle for a description of those member variables. 288 // See NavigationHandle for a description of those member variables.
273 GURL url_; 289 GURL url_;
274 Referrer sanitized_referrer_; 290 Referrer sanitized_referrer_;
275 bool has_user_gesture_; 291 bool has_user_gesture_;
276 ui::PageTransition transition_; 292 ui::PageTransition transition_;
277 bool is_external_protocol_; 293 bool is_external_protocol_;
278 net::Error net_error_code_; 294 net::Error net_error_code_;
279 RenderFrameHostImpl* render_frame_host_; 295 RenderFrameHostImpl* render_frame_host_;
280 const bool is_renderer_initiated_; 296 const bool is_renderer_initiated_;
281 bool is_same_page_; 297 bool is_same_page_;
282 const bool is_synchronous_; 298 const bool is_synchronous_;
283 const bool is_srcdoc_; 299 const bool is_srcdoc_;
284 bool was_redirected_; 300 bool was_redirected_;
285 scoped_refptr<net::HttpResponseHeaders> response_headers_; 301 scoped_refptr<net::HttpResponseHeaders> response_headers_;
286 302
303 // The original url of the navigation. This may differ from |url_| if the
304 // navigation encounters redirects.
305 const GURL original_url_;
306
287 // The HTTP method used for the navigation. 307 // The HTTP method used for the navigation.
288 std::string method_; 308 std::string method_;
289 309
290 // The POST body associated with this navigation. This will be null for GET 310 // The POST body associated with this navigation. This will be null for GET
291 // and/or other non-POST requests (or if a response to a POST request was a 311 // and/or other non-POST requests (or if a response to a POST request was a
292 // redirect that changed the method to GET - for example 302). 312 // redirect that changed the method to GET - for example 302).
293 scoped_refptr<ResourceRequestBodyImpl> resource_request_body_; 313 scoped_refptr<ResourceRequestBodyImpl> resource_request_body_;
294 314
295 // The state the navigation is in. 315 // The state the navigation is in.
296 State state_; 316 State state_;
(...skipping 21 matching lines...) Expand all
318 RequestContextType request_context_type_; 338 RequestContextType request_context_type_;
319 339
320 // This callback will be run when all throttle checks have been performed. 340 // This callback will be run when all throttle checks have been performed.
321 ThrottleChecksFinishedCallback complete_callback_; 341 ThrottleChecksFinishedCallback complete_callback_;
322 342
323 // Embedder data tied to this navigation. 343 // Embedder data tied to this navigation.
324 std::unique_ptr<NavigationData> navigation_data_; 344 std::unique_ptr<NavigationData> navigation_data_;
325 345
326 SSLStatus ssl_status_; 346 SSLStatus ssl_status_;
327 347
348 // The id of the URLRequest tied to this navigation.
349 GlobalRequestID request_id_;
350
351 // Whether the current NavigationEntry should be replaced upon commit.
352 bool should_replace_current_entry_;
353
354 // The chain of redirects.
355 std::vector<GURL> redirect_chain_;
356
357 // A callback to run on the IO thread if the navigation transfers.
358 base::Closure transfer_callback_;
359
360 // Whether the navigation ended up being a download or a stream.
361 bool is_download_;
362 bool is_stream_;
363
364 base::WeakPtrFactory<NavigationHandleImpl> weak_factory_;
365
328 DISALLOW_COPY_AND_ASSIGN(NavigationHandleImpl); 366 DISALLOW_COPY_AND_ASSIGN(NavigationHandleImpl);
329 }; 367 };
330 368
331 } // namespace content 369 } // namespace content
332 370
333 #endif // CONTENT_BROWSER_FRAME_HOST_NAVIGATION_HANDLE_IMPL_H_ 371 #endif // CONTENT_BROWSER_FRAME_HOST_NAVIGATION_HANDLE_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698