OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 #include "content/browser/frame_host/navigation_request.h" | 5 #include "content/browser/frame_host/navigation_request.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "content/browser/loader/resource_dispatcher_host_impl.h" | 8 #include "content/browser/frame_host/frame_tree_node.h" |
9 #include "content/common/resource_request_body.h" | 9 #include "content/browser/frame_host/render_frame_host_manager.h" |
10 #include "content/public/browser/browser_thread.h" | 10 #include "content/public/browser/stream_handle.h" |
| 11 #include "net/url_request/redirect_info.h" |
11 | 12 |
12 namespace content { | 13 namespace content { |
13 | 14 |
14 namespace { | |
15 | |
16 // The next available browser-global navigation request ID. | |
17 static int64 next_navigation_request_id_ = 0; | |
18 | |
19 void OnBeginNavigation(const NavigationRequestInfo& info, | |
20 scoped_refptr<ResourceRequestBody> request_body, | |
21 int64 navigation_request_id, | |
22 int64 frame_tree_node_id) { | |
23 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
24 ResourceDispatcherHostImpl::Get()->StartNavigationRequest( | |
25 info, request_body, navigation_request_id, frame_tree_node_id); | |
26 } | |
27 | |
28 void CancelNavigationRequest(int64 navigation_request_id, | |
29 int64 frame_tree_node_id) { | |
30 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | |
31 ResourceDispatcherHostImpl::Get()->CancelNavigationRequest( | |
32 navigation_request_id, frame_tree_node_id); | |
33 } | |
34 | |
35 } // namespace | |
36 | |
37 NavigationRequest::NavigationRequest(const NavigationRequestInfo& info, | 15 NavigationRequest::NavigationRequest(const NavigationRequestInfo& info, |
38 int64 frame_tree_node_id) | 16 BrowserContext* browser_context, |
39 : navigation_request_id_(++next_navigation_request_id_), | 17 FrameTreeNode* frame_tree_node) |
40 info_(info), | 18 : info_(info), |
41 frame_tree_node_id_(frame_tree_node_id) { | 19 browser_context_(browser_context), |
| 20 frame_tree_node_(frame_tree_node) { |
42 } | 21 } |
43 | 22 |
44 NavigationRequest::~NavigationRequest() { | 23 NavigationRequest::~NavigationRequest() { |
45 } | 24 } |
46 | 25 |
47 void NavigationRequest::BeginNavigation( | 26 void NavigationRequest::BeginNavigation( |
48 scoped_refptr<ResourceRequestBody> request_body) { | 27 scoped_refptr<ResourceRequestBody> request_body) { |
49 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 28 DCHECK(!loader_); |
50 BrowserThread::PostTask( | 29 |
51 BrowserThread::IO, | 30 final_url_ = info_.navigation_params.url; |
52 FROM_HERE, | 31 loader_.reset(NavigationURLLoader::Create( |
53 base::Bind(&OnBeginNavigation, | 32 browser_context_, frame_tree_node_->frame_tree_node_id(), |
54 info_, | 33 info_, request_body.get(), this)); |
55 request_body, | |
56 navigation_request_id_, | |
57 frame_tree_node_id_)); | |
58 } | 34 } |
59 | 35 |
60 void NavigationRequest::CancelNavigation() { | 36 void NavigationRequest::OnRequestRedirected( |
61 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::UI)); | 37 const net::RedirectInfo& redirect_info, |
62 BrowserThread::PostTask( | 38 ResourceResponse* response) { |
63 BrowserThread::IO, | 39 final_url_ = redirect_info.new_url; |
64 FROM_HERE, | 40 |
65 base::Bind(&CancelNavigationRequest, | 41 // TODO(davidben): This where prerender and navigation_interceptor should be |
66 navigation_request_id_, frame_tree_node_id_)); | 42 // integrated. For now, just always follow all redirects. |
| 43 loader_->FollowRedirect(); |
| 44 } |
| 45 |
| 46 void NavigationRequest::OnResponseStarted(ResourceResponse* response, |
| 47 scoped_ptr<StreamHandle> body) { |
| 48 frame_tree_node_->render_manager()->CommitNavigation( |
| 49 final_url_, response, body.Pass()); |
| 50 } |
| 51 |
| 52 void NavigationRequest::OnRequestFailed(int net_error) { |
| 53 // TODO(davidben): Network failures should display a network error page. |
| 54 NOTIMPLEMENTED(); |
67 } | 55 } |
68 | 56 |
69 } // namespace content | 57 } // namespace content |
OLD | NEW |