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 "content/browser/frame_host/frame_tree.h" | 7 #include "content/browser/frame_host/frame_tree.h" |
8 #include "content/browser/frame_host/frame_tree_node.h" | 8 #include "content/browser/frame_host/frame_tree_node.h" |
9 #include "content/browser/frame_host/navigation_controller_impl.h" | 9 #include "content/browser/frame_host/navigation_controller_impl.h" |
10 #include "content/browser/frame_host/navigation_handle_impl.h" | 10 #include "content/browser/frame_host/navigation_handle_impl.h" |
11 #include "content/browser/frame_host/navigation_request_info.h" | 11 #include "content/browser/frame_host/navigation_request_info.h" |
12 #include "content/browser/frame_host/navigator.h" | 12 #include "content/browser/frame_host/navigator.h" |
13 #include "content/browser/loader/navigation_url_loader.h" | 13 #include "content/browser/loader/navigation_url_loader.h" |
14 #include "content/browser/site_instance_impl.h" | 14 #include "content/browser/site_instance_impl.h" |
15 #include "content/common/resource_request_body.h" | 15 #include "content/common/resource_request_body.h" |
16 #include "content/public/browser/navigation_controller.h" | 16 #include "content/public/browser/navigation_controller.h" |
17 #include "content/public/browser/navigation_throttle.h" | |
17 #include "content/public/browser/stream_handle.h" | 18 #include "content/public/browser/stream_handle.h" |
18 #include "content/public/common/content_client.h" | 19 #include "content/public/common/content_client.h" |
19 #include "net/base/load_flags.h" | 20 #include "net/base/load_flags.h" |
20 #include "net/http/http_request_headers.h" | 21 #include "net/http/http_request_headers.h" |
21 #include "net/url_request/redirect_info.h" | 22 #include "net/url_request/redirect_info.h" |
22 | 23 |
23 namespace content { | 24 namespace content { |
24 | 25 |
25 namespace { | 26 namespace { |
26 | 27 |
(...skipping 15 matching lines...) Expand all Loading... | |
42 case FrameMsg_Navigate_Type::RESTORE_WITH_POST: | 43 case FrameMsg_Navigate_Type::RESTORE_WITH_POST: |
43 load_flags |= net::LOAD_ONLY_FROM_CACHE; | 44 load_flags |= net::LOAD_ONLY_FROM_CACHE; |
44 break; | 45 break; |
45 case FrameMsg_Navigate_Type::NORMAL: | 46 case FrameMsg_Navigate_Type::NORMAL: |
46 default: | 47 default: |
47 break; | 48 break; |
48 } | 49 } |
49 return load_flags; | 50 return load_flags; |
50 } | 51 } |
51 | 52 |
53 // Filters the URL for the navigation based. | |
54 GURL FilterURL(const GURL& url, FrameTreeNode* frame_tree_node) { | |
55 RenderFrameHostImpl* render_frame_host = | |
56 frame_tree_node->render_manager()->speculative_frame_host() | |
57 ? frame_tree_node->render_manager()->speculative_frame_host() | |
58 : frame_tree_node->render_manager()->current_frame_host(); | |
carlosk
2015/08/28 16:40:24
This next-RFH logic should live inside RFHM. We've
nasko
2015/08/31 23:25:15
This code seems a bit fragile. What happens if the
clamy
2015/09/03 15:30:51
This would happen in the case of redirects. In tha
nasko
2015/09/04 23:36:49
I'm not sure we need to call FilterURL on redirect
| |
59 GURL filtered_url = url; | |
60 render_frame_host->GetProcess()->FilterURL(false, &filtered_url); | |
61 return filtered_url; | |
62 } | |
63 | |
52 } // namespace | 64 } // namespace |
53 | 65 |
54 // static | 66 // static |
55 scoped_ptr<NavigationRequest> NavigationRequest::CreateBrowserInitiated( | 67 scoped_ptr<NavigationRequest> NavigationRequest::CreateBrowserInitiated( |
56 FrameTreeNode* frame_tree_node, | 68 FrameTreeNode* frame_tree_node, |
57 const GURL& dest_url, | 69 const GURL& dest_url, |
58 const Referrer& dest_referrer, | 70 const Referrer& dest_referrer, |
59 const FrameNavigationEntry& frame_entry, | 71 const FrameNavigationEntry& frame_entry, |
60 const NavigationEntryImpl& entry, | 72 const NavigationEntryImpl& entry, |
61 FrameMsg_Navigate_Type::Value navigation_type, | 73 FrameMsg_Navigate_Type::Value navigation_type, |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
172 | 184 |
173 NavigationRequest::~NavigationRequest() { | 185 NavigationRequest::~NavigationRequest() { |
174 } | 186 } |
175 | 187 |
176 bool NavigationRequest::BeginNavigation() { | 188 bool NavigationRequest::BeginNavigation() { |
177 DCHECK(!loader_); | 189 DCHECK(!loader_); |
178 DCHECK(state_ == NOT_STARTED || state_ == WAITING_FOR_RENDERER_RESPONSE); | 190 DCHECK(state_ == NOT_STARTED || state_ == WAITING_FOR_RENDERER_RESPONSE); |
179 state_ = STARTED; | 191 state_ = STARTED; |
180 | 192 |
181 if (ShouldMakeNetworkRequestForURL(common_params_.url)) { | 193 if (ShouldMakeNetworkRequestForURL(common_params_.url)) { |
194 // TODO(clamy): pass the real value for |is_external_protocol|. | |
davidben
2015/09/01 21:55:18
Hrm. It seems to manage that, we'd need to either
clamy
2015/09/03 15:30:51
So it seems it is only used on Android to log to t
| |
195 NavigationThrottle::ThrottleCheckResult result = | |
196 navigation_handle_->WillStartRequest( | |
197 begin_params_.method == "POST", | |
198 Referrer::SanitizeForRequest(common_params_.url, | |
199 common_params_.referrer), | |
200 begin_params_.has_user_gesture, common_params_.transition, false); | |
201 | |
202 // Abort the request if needed. This will destroy the NavigationRequest. | |
203 if (result == NavigationThrottle::CANCEL_AND_IGNORE) { | |
204 frame_tree_node_->ResetNavigationRequest(false); | |
205 return false; | |
206 } | |
207 | |
182 loader_ = NavigationURLLoader::Create( | 208 loader_ = NavigationURLLoader::Create( |
183 frame_tree_node_->navigator()->GetController()->GetBrowserContext(), | 209 frame_tree_node_->navigator()->GetController()->GetBrowserContext(), |
184 frame_tree_node_->frame_tree_node_id(), info_.Pass(), this); | 210 frame_tree_node_->frame_tree_node_id(), info_.Pass(), this); |
185 return true; | 211 return true; |
186 } | 212 } |
187 | 213 |
188 // There is no need to make a network request for this navigation, so commit | 214 // There is no need to make a network request for this navigation, so commit |
189 // it immediately. | 215 // it immediately. |
190 state_ = RESPONSE_STARTED; | 216 state_ = RESPONSE_STARTED; |
191 frame_tree_node_->navigator()->CommitNavigation( | 217 frame_tree_node_->navigator()->CommitNavigation( |
192 frame_tree_node_, nullptr, scoped_ptr<StreamHandle>()); | 218 frame_tree_node_, nullptr, scoped_ptr<StreamHandle>()); |
193 return false; | 219 return false; |
194 | 220 |
195 // TODO(davidben): Fire (and add as necessary) observer methods such as | 221 // TODO(davidben): Fire (and add as necessary) observer methods such as |
196 // DidStartProvisionalLoadForFrame for the navigation. | 222 // DidStartProvisionalLoadForFrame for the navigation. |
197 } | 223 } |
198 | 224 |
199 void NavigationRequest::CreateNavigationHandle(NavigatorDelegate* delegate) { | 225 void NavigationRequest::CreateNavigationHandle(NavigatorDelegate* delegate) { |
200 navigation_handle_ = NavigationHandleImpl::Create( | 226 navigation_handle_ = NavigationHandleImpl::Create( |
201 common_params_.url, frame_tree_node_->IsMainFrame(), delegate); | 227 common_params_.url, FilterURL(common_params_.url, frame_tree_node_), |
228 frame_tree_node_->IsMainFrame(), delegate); | |
202 } | 229 } |
203 | 230 |
204 void NavigationRequest::TransferNavigationHandleOwnership( | 231 void NavigationRequest::TransferNavigationHandleOwnership( |
205 RenderFrameHostImpl* render_frame_host) { | 232 RenderFrameHostImpl* render_frame_host) { |
206 render_frame_host->SetNavigationHandle(navigation_handle_.Pass()); | 233 render_frame_host->SetNavigationHandle(navigation_handle_.Pass()); |
207 } | 234 } |
208 | 235 |
209 void NavigationRequest::OnRequestRedirected( | 236 void NavigationRequest::OnRequestRedirected( |
210 const net::RedirectInfo& redirect_info, | 237 const net::RedirectInfo& redirect_info, |
211 const scoped_refptr<ResourceResponse>& response) { | 238 const scoped_refptr<ResourceResponse>& response, |
212 // TODO(davidben): Track other changes from redirects. These are important | 239 bool is_external_protocol) { |
213 // for, e.g., reloads. | |
214 common_params_.url = redirect_info.new_url; | 240 common_params_.url = redirect_info.new_url; |
241 begin_params_.method = redirect_info.new_method; | |
242 common_params_.referrer.url = GURL(redirect_info.new_referrer); | |
215 | 243 |
216 // TODO(davidben): This where prerender and navigation_interceptor should be | 244 // TODO(clamy): Have CSP + security upgrade checks here. |
217 // integrated. For now, just always follow all redirects. | 245 NavigationThrottle::ThrottleCheckResult result = |
246 navigation_handle_->WillRedirectRequest( | |
247 common_params_.url, FilterURL(common_params_.url, frame_tree_node_), | |
nasko
2015/08/31 23:25:15
FilterURL should be a called separately and possib
clamy
2015/09/03 15:30:51
Done. I have added a TODO for the kill (note that
| |
248 begin_params_.method == "POST", common_params_.referrer.url, | |
249 is_external_protocol); | |
250 | |
251 // Abort the request if needed. This will destroy the NavigationRequest. | |
252 if (result == NavigationThrottle::CANCEL_AND_IGNORE) { | |
253 frame_tree_node_->ResetNavigationRequest(false); | |
254 return; | |
255 } | |
256 | |
218 loader_->FollowRedirect(); | 257 loader_->FollowRedirect(); |
219 | 258 |
220 navigation_handle_->DidRedirectNavigation(redirect_info.new_url); | 259 navigation_handle_->DidRedirectNavigation(redirect_info.new_url); |
221 } | 260 } |
222 | 261 |
223 void NavigationRequest::OnResponseStarted( | 262 void NavigationRequest::OnResponseStarted( |
224 const scoped_refptr<ResourceResponse>& response, | 263 const scoped_refptr<ResourceResponse>& response, |
225 scoped_ptr<StreamHandle> body) { | 264 scoped_ptr<StreamHandle> body) { |
226 DCHECK(state_ == STARTED); | 265 DCHECK(state_ == STARTED); |
227 state_ = RESPONSE_STARTED; | 266 state_ = RESPONSE_STARTED; |
228 frame_tree_node_->navigator()->CommitNavigation(frame_tree_node_, | 267 frame_tree_node_->navigator()->CommitNavigation(frame_tree_node_, |
229 response.get(), body.Pass()); | 268 response.get(), body.Pass()); |
230 } | 269 } |
231 | 270 |
232 void NavigationRequest::OnRequestFailed(bool has_stale_copy_in_cache, | 271 void NavigationRequest::OnRequestFailed(bool has_stale_copy_in_cache, |
233 int net_error) { | 272 int net_error) { |
234 DCHECK(state_ == STARTED); | 273 DCHECK(state_ == STARTED); |
235 state_ = FAILED; | 274 state_ = FAILED; |
236 navigation_handle_->set_net_error_code(static_cast<net::Error>(net_error)); | 275 navigation_handle_->set_net_error_code(static_cast<net::Error>(net_error)); |
237 frame_tree_node_->navigator()->FailedNavigation( | 276 frame_tree_node_->navigator()->FailedNavigation( |
238 frame_tree_node_, has_stale_copy_in_cache, net_error); | 277 frame_tree_node_, has_stale_copy_in_cache, net_error); |
239 } | 278 } |
240 | 279 |
241 void NavigationRequest::OnRequestStarted(base::TimeTicks timestamp) { | 280 void NavigationRequest::OnRequestStarted(base::TimeTicks timestamp) { |
242 frame_tree_node_->navigator()->LogResourceRequestTime(timestamp, | 281 frame_tree_node_->navigator()->LogResourceRequestTime(timestamp, |
243 common_params_.url); | 282 common_params_.url); |
244 } | 283 } |
245 | 284 |
246 } // namespace content | 285 } // namespace content |
OLD | NEW |