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

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 #include <string> 11 #include <string>
12 12
13 #include "base/callback.h" 13 #include "base/callback.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/memory/ref_counted.h" 15 #include "base/memory/ref_counted.h"
16 #include "base/memory/scoped_vector.h" 16 #include "base/memory/scoped_vector.h"
17 #include "content/browser/frame_host/frame_tree_node.h" 17 #include "content/browser/frame_host/frame_tree_node.h"
18 #include "content/browser/frame_host/render_frame_host_impl.h" 18 #include "content/browser/frame_host/render_frame_host_impl.h"
19 #include "content/common/content_export.h" 19 #include "content/common/content_export.h"
20 #include "content/public/browser/global_request_id.h"
20 #include "content/public/browser/navigation_data.h" 21 #include "content/public/browser/navigation_data.h"
21 #include "content/public/browser/navigation_throttle.h" 22 #include "content/public/browser/navigation_throttle.h"
22 #include "content/public/browser/ssl_status.h" 23 #include "content/public/browser/ssl_status.h"
23 #include "content/public/common/request_context_type.h" 24 #include "content/public/common/request_context_type.h"
24 #include "url/gurl.h" 25 #include "url/gurl.h"
25 26
26 struct FrameHostMsg_DidCommitProvisionalLoad_Params; 27 struct FrameHostMsg_DidCommitProvisionalLoad_Params;
27 28
28 namespace content { 29 namespace content {
29 30
30 class NavigatorDelegate; 31 class NavigatorDelegate;
31 class ResourceRequestBodyImpl; 32 class ResourceRequestBodyImpl;
33 class SiteInstance;
32 34
33 // This class keeps track of a single navigation. It is created upon receipt of 35 // This class keeps track of a single navigation. It is created upon receipt of
34 // a DidStartProvisionalLoad IPC in a RenderFrameHost. The RenderFrameHost owns 36 // a DidStartProvisionalLoad IPC in a RenderFrameHost. The RenderFrameHost owns
35 // the newly created NavigationHandleImpl as long as the navigation is ongoing. 37 // the newly created NavigationHandleImpl as long as the navigation is ongoing.
36 // The NavigationHandleImpl in the RenderFrameHost will be reset when the 38 // The NavigationHandleImpl in the RenderFrameHost will be reset when the
37 // navigation stops, that is if one of the following events happen: 39 // navigation stops, that is if one of the following events happen:
38 // - The RenderFrameHost receives a DidStartProvisionalLoad IPC for a new 40 // - The RenderFrameHost receives a DidStartProvisionalLoad IPC for a new
39 // navigation (see below for special cases where the DidStartProvisionalLoad 41 // navigation (see below for special cases where the DidStartProvisionalLoad
40 // message does not indicate the start of a new navigation). 42 // message does not indicate the start of a new navigation).
41 // - The RenderFrameHost stops loading. 43 // - The RenderFrameHost stops loading.
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 bool new_is_external_protocol, 196 bool new_is_external_protocol,
195 scoped_refptr<net::HttpResponseHeaders> response_headers, 197 scoped_refptr<net::HttpResponseHeaders> response_headers,
196 const ThrottleChecksFinishedCallback& callback); 198 const ThrottleChecksFinishedCallback& callback);
197 199
198 // Called when the URLRequest has delivered response headers and metadata. 200 // Called when the URLRequest has delivered response headers and metadata.
199 // |callback| will be called when all throttle checks have completed, 201 // |callback| will be called when all throttle checks have completed,
200 // allowing the caller to cancel the navigation or let it proceed. 202 // allowing the caller to cancel the navigation or let it proceed.
201 // NavigationHandle will not call |callback| with a result of DEFER. 203 // NavigationHandle will not call |callback| with a result of DEFER.
202 // If the result is PROCEED, then 'ReadyToCommitNavigation' will be called 204 // If the result is PROCEED, then 'ReadyToCommitNavigation' will be called
203 // with |render_frame_host| and |response_headers| just before calling 205 // with |render_frame_host| and |response_headers| just before calling
204 // |callback|. 206 // |callback|. Should a transfer navigation happen, |transfer_callback| will
207 // be run on the IO thread.
208 // PlzNavigate: transfer navigations are not possible.
205 void WillProcessResponse( 209 void WillProcessResponse(
206 RenderFrameHostImpl* render_frame_host, 210 RenderFrameHostImpl* render_frame_host,
207 scoped_refptr<net::HttpResponseHeaders> response_headers, 211 scoped_refptr<net::HttpResponseHeaders> response_headers,
208 const SSLStatus& ssl_status, 212 const SSLStatus& ssl_status,
213 const GlobalRequestID& request_id,
214 bool should_replace_current_entry,
215 bool is_download,
216 bool is_stream,
217 const base::Closure& transfer_callback,
209 const ThrottleChecksFinishedCallback& callback); 218 const ThrottleChecksFinishedCallback& callback);
210 219
211 // Returns the FrameTreeNode this navigation is happening in. 220 // Returns the FrameTreeNode this navigation is happening in.
212 FrameTreeNode* frame_tree_node() { return frame_tree_node_; } 221 FrameTreeNode* frame_tree_node() { return frame_tree_node_; }
213 222
214 // Called when the navigation is ready to be committed in 223 // Called when the navigation is ready to be committed in
215 // |render_frame_host|. This will update the |state_| and inform the 224 // |render_frame_host|. This will update the |state_| and inform the
216 // delegate. 225 // delegate.
217 void ReadyToCommitNavigation(RenderFrameHostImpl* render_frame_host); 226 void ReadyToCommitNavigation(RenderFrameHostImpl* render_frame_host);
218 227
219 // Called when the navigation was committed in |render_frame_host|. This will 228 // Called when the navigation was committed in |render_frame_host|. This will
220 // update the |state_|. 229 // update the |state_|.
221 void DidCommitNavigation( 230 void DidCommitNavigation(
222 const FrameHostMsg_DidCommitProvisionalLoad_Params& params, 231 const FrameHostMsg_DidCommitProvisionalLoad_Params& params,
223 bool same_page, 232 bool same_page,
224 RenderFrameHostImpl* render_frame_host); 233 RenderFrameHostImpl* render_frame_host);
225 234
226 // Called during commit. Takes ownership of the embedder's NavigationData 235 // Called during commit. Takes ownership of the embedder's NavigationData
227 // instance. This NavigationData may have been cloned prior to being added 236 // instance. This NavigationData may have been cloned prior to being added
228 // here. 237 // here.
229 void set_navigation_data(std::unique_ptr<NavigationData> navigation_data) { 238 void set_navigation_data(std::unique_ptr<NavigationData> navigation_data) {
230 navigation_data_ = std::move(navigation_data); 239 navigation_data_ = std::move(navigation_data);
231 } 240 }
232 241
233 SSLStatus ssl_status() { return ssl_status_; } 242 SSLStatus ssl_status() { return ssl_status_; }
234 243
244 // This is valid after the network response has started.
245 // TODO(clamy): See if this can be initialized earlier if needed by
246 // non-transfer code. There may some issue in PlzNavigate, where
247 // WillStartRequest will be called before starting a requets on the IO thread.
Charlie Reis 2016/09/21 03:31:47 nit: request
clamy 2016/09/21 15:04:06 Done.
248 const GlobalRequestID& request_id() const {
249 DCHECK_GE(state_, WILL_PROCESS_RESPONSE);
250 return request_id_;
251 }
252
253 // Called when the navigation is transferred to a different renderer.
254 void Transfer();
255
235 private: 256 private:
236 friend class NavigationHandleImplTest; 257 friend class NavigationHandleImplTest;
237 258
238 // Used to track the state the navigation is currently in. 259 // Used to track the state the navigation is currently in.
239 enum State { 260 enum State {
240 INITIAL = 0, 261 INITIAL = 0,
241 WILL_SEND_REQUEST, 262 WILL_SEND_REQUEST,
242 DEFERRING_START, 263 DEFERRING_START,
243 WILL_REDIRECT_REQUEST, 264 WILL_REDIRECT_REQUEST,
244 DEFERRING_REDIRECT, 265 DEFERRING_REDIRECT,
(...skipping 10 matching lines...) Expand all
255 bool is_renderer_initiated, 276 bool is_renderer_initiated,
256 bool is_synchronous, 277 bool is_synchronous,
257 bool is_srcdoc, 278 bool is_srcdoc,
258 const base::TimeTicks& navigation_start, 279 const base::TimeTicks& navigation_start,
259 int pending_nav_entry_id); 280 int pending_nav_entry_id);
260 281
261 NavigationThrottle::ThrottleCheckResult CheckWillStartRequest(); 282 NavigationThrottle::ThrottleCheckResult CheckWillStartRequest();
262 NavigationThrottle::ThrottleCheckResult CheckWillRedirectRequest(); 283 NavigationThrottle::ThrottleCheckResult CheckWillRedirectRequest();
263 NavigationThrottle::ThrottleCheckResult CheckWillProcessResponse(); 284 NavigationThrottle::ThrottleCheckResult CheckWillProcessResponse();
264 285
286 // Called when WillProcessResponse checks are done, to find the final
287 // RenderFrameHost for the navigation. Checks whether the navigation should be
288 // transferred. Returns false if the transfer attempt results in the
289 // destruction of this NavigationHandle and the navigation should no longer
290 // proceed.
Charlie Reis 2016/09/21 03:31:47 I think it's worth mentioning a case that the tran
clamy 2016/09/21 15:04:06 Yes. Mentioned that case.
291 bool MaybeTransferAndProceed();
292
293 // Helper method for MaybeTransferAndProceed. Returns false if the transfer
294 // attempt results in the destruction of this NavigationHandle.
295 bool MaybeTransferAndProceedInternal();
296
265 // Helper function to run and reset the |complete_callback_|. This marks the 297 // Helper function to run and reset the |complete_callback_|. This marks the
266 // end of a round of NavigationThrottleChecks. 298 // end of a round of NavigationThrottleChecks.
267 void RunCompleteCallback(NavigationThrottle::ThrottleCheckResult result); 299 void RunCompleteCallback(NavigationThrottle::ThrottleCheckResult result);
268 300
269 // Used in tests. 301 // Used in tests.
270 State state() const { return state_; } 302 State state() const { return state_; }
271 303
272 // Populates |throttles_| with the throttles for this navigation. 304 // Populates |throttles_| with the throttles for this navigation.
273 void RegisterNavigationThrottles(); 305 void RegisterNavigationThrottles();
274 306
275 // See NavigationHandle for a description of those member variables. 307 // See NavigationHandle for a description of those member variables.
276 GURL url_; 308 GURL url_;
277 Referrer sanitized_referrer_; 309 Referrer sanitized_referrer_;
278 bool has_user_gesture_; 310 bool has_user_gesture_;
279 ui::PageTransition transition_; 311 ui::PageTransition transition_;
280 bool is_external_protocol_; 312 bool is_external_protocol_;
281 net::Error net_error_code_; 313 net::Error net_error_code_;
282 RenderFrameHostImpl* render_frame_host_; 314 RenderFrameHostImpl* render_frame_host_;
283 const bool is_renderer_initiated_; 315 const bool is_renderer_initiated_;
284 bool is_same_page_; 316 bool is_same_page_;
285 const bool is_synchronous_; 317 const bool is_synchronous_;
286 const bool is_srcdoc_; 318 const bool is_srcdoc_;
287 bool was_redirected_; 319 bool was_redirected_;
288 scoped_refptr<net::HttpResponseHeaders> response_headers_; 320 scoped_refptr<net::HttpResponseHeaders> response_headers_;
289 321
322 // The original url of the navigation. This may differ from |url_| if the
323 // navigation encounters redirects.
324 const GURL original_url_;
325
290 // The HTTP method used for the navigation. 326 // The HTTP method used for the navigation.
291 std::string method_; 327 std::string method_;
292 328
293 // The POST body associated with this navigation. This will be null for GET 329 // The POST body associated with this navigation. This will be null for GET
294 // and/or other non-POST requests (or if a response to a POST request was a 330 // and/or other non-POST requests (or if a response to a POST request was a
295 // redirect that changed the method to GET - for example 302). 331 // redirect that changed the method to GET - for example 302).
296 scoped_refptr<ResourceRequestBodyImpl> resource_request_body_; 332 scoped_refptr<ResourceRequestBodyImpl> resource_request_body_;
297 333
298 // The state the navigation is in. 334 // The state the navigation is in.
299 State state_; 335 State state_;
(...skipping 21 matching lines...) Expand all
321 RequestContextType request_context_type_; 357 RequestContextType request_context_type_;
322 358
323 // This callback will be run when all throttle checks have been performed. 359 // This callback will be run when all throttle checks have been performed.
324 ThrottleChecksFinishedCallback complete_callback_; 360 ThrottleChecksFinishedCallback complete_callback_;
325 361
326 // Embedder data tied to this navigation. 362 // Embedder data tied to this navigation.
327 std::unique_ptr<NavigationData> navigation_data_; 363 std::unique_ptr<NavigationData> navigation_data_;
328 364
329 SSLStatus ssl_status_; 365 SSLStatus ssl_status_;
330 366
367 // The id of the URLRequest tied to this navigation.
368 GlobalRequestID request_id_;
369
370 // Whether the current NavigationEntry should be replaced upon commit.
371 bool should_replace_current_entry_;
372
373 // The chain of redirects.
374 std::vector<GURL> redirect_chain_;
375
376 // A callback to run on the IO thread if the navigation transfers.
377 base::Closure transfer_callback_;
378
379 // Whether the navigation ended up being a download or a stream.
380 bool is_download_;
381 bool is_stream_;
382
383 base::WeakPtrFactory<NavigationHandleImpl> weak_factory_;
384
331 DISALLOW_COPY_AND_ASSIGN(NavigationHandleImpl); 385 DISALLOW_COPY_AND_ASSIGN(NavigationHandleImpl);
332 }; 386 };
333 387
334 } // namespace content 388 } // namespace content
335 389
336 #endif // CONTENT_BROWSER_FRAME_HOST_NAVIGATION_HANDLE_IMPL_H_ 390 #endif // CONTENT_BROWSER_FRAME_HOST_NAVIGATION_HANDLE_IMPL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698