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