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_factory.h" | |
10 #include "content/browser/frame_host/navigation_handle_impl.h" | 11 #include "content/browser/frame_host/navigation_handle_impl.h" |
11 #include "content/browser/frame_host/navigation_request_info.h" | 12 #include "content/browser/frame_host/navigation_request_info.h" |
12 #include "content/browser/frame_host/navigator.h" | 13 #include "content/browser/frame_host/navigator.h" |
13 #include "content/browser/loader/navigation_url_loader.h" | 14 #include "content/browser/loader/navigation_url_loader.h" |
14 #include "content/browser/site_instance_impl.h" | 15 #include "content/browser/site_instance_impl.h" |
15 #include "content/common/resource_request_body.h" | 16 #include "content/common/resource_request_body.h" |
16 #include "content/public/browser/navigation_controller.h" | 17 #include "content/public/browser/navigation_controller.h" |
18 #include "content/public/browser/navigation_throttle.h" | |
17 #include "content/public/browser/stream_handle.h" | 19 #include "content/public/browser/stream_handle.h" |
18 #include "content/public/common/content_client.h" | 20 #include "content/public/common/content_client.h" |
19 #include "net/base/load_flags.h" | 21 #include "net/base/load_flags.h" |
20 #include "net/http/http_request_headers.h" | 22 #include "net/http/http_request_headers.h" |
21 #include "net/url_request/redirect_info.h" | 23 #include "net/url_request/redirect_info.h" |
22 | 24 |
23 namespace content { | 25 namespace content { |
24 | 26 |
25 namespace { | 27 namespace { |
26 | 28 |
(...skipping 15 matching lines...) Expand all Loading... | |
42 case FrameMsg_Navigate_Type::RESTORE_WITH_POST: | 44 case FrameMsg_Navigate_Type::RESTORE_WITH_POST: |
43 load_flags |= net::LOAD_ONLY_FROM_CACHE; | 45 load_flags |= net::LOAD_ONLY_FROM_CACHE; |
44 break; | 46 break; |
45 case FrameMsg_Navigate_Type::NORMAL: | 47 case FrameMsg_Navigate_Type::NORMAL: |
46 default: | 48 default: |
47 break; | 49 break; |
48 } | 50 } |
49 return load_flags; | 51 return load_flags; |
50 } | 52 } |
51 | 53 |
54 // Filters the URL for the navigation based. | |
Charlie Reis
2015/09/16 00:09:24
I'm not sure what "for the navigation based" means
clamy
2015/09/16 01:03:22
Method was removed.
| |
55 GURL FilterURL(const GURL& url, FrameTreeNode* frame_tree_node) { | |
Charlie Reis
2015/09/16 00:09:25
This feels like the wrong place to be enforcing th
clamy
2015/09/16 01:03:22
I see. In that case, since this method is PlzNavig
| |
56 RenderFrameHostImpl* render_frame_host = | |
57 frame_tree_node->render_manager()->speculative_frame_host() | |
Charlie Reis
2015/09/16 00:09:25
Is this only used in PlzNavigate?
clamy
2015/09/16 01:03:22
Yes - but I removed this method, see above.
| |
58 ? frame_tree_node->render_manager()->speculative_frame_host() | |
59 : frame_tree_node->render_manager()->current_frame_host(); | |
60 GURL filtered_url = url; | |
61 render_frame_host->GetProcess()->FilterURL(false, &filtered_url); | |
62 return filtered_url; | |
63 } | |
64 | |
52 } // namespace | 65 } // namespace |
53 | 66 |
54 // static | 67 // static |
55 scoped_ptr<NavigationRequest> NavigationRequest::CreateBrowserInitiated( | 68 scoped_ptr<NavigationRequest> NavigationRequest::CreateBrowserInitiated( |
56 FrameTreeNode* frame_tree_node, | 69 FrameTreeNode* frame_tree_node, |
57 const GURL& dest_url, | 70 const GURL& dest_url, |
58 const Referrer& dest_referrer, | 71 const Referrer& dest_referrer, |
59 const FrameNavigationEntry& frame_entry, | 72 const FrameNavigationEntry& frame_entry, |
60 const NavigationEntryImpl& entry, | 73 const NavigationEntryImpl& entry, |
61 FrameMsg_Navigate_Type::Value navigation_type, | 74 FrameMsg_Navigate_Type::Value navigation_type, |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
172 | 185 |
173 NavigationRequest::~NavigationRequest() { | 186 NavigationRequest::~NavigationRequest() { |
174 } | 187 } |
175 | 188 |
176 bool NavigationRequest::BeginNavigation() { | 189 bool NavigationRequest::BeginNavigation() { |
177 DCHECK(!loader_); | 190 DCHECK(!loader_); |
178 DCHECK(state_ == NOT_STARTED || state_ == WAITING_FOR_RENDERER_RESPONSE); | 191 DCHECK(state_ == NOT_STARTED || state_ == WAITING_FOR_RENDERER_RESPONSE); |
179 state_ = STARTED; | 192 state_ = STARTED; |
180 | 193 |
181 if (ShouldMakeNetworkRequestForURL(common_params_.url)) { | 194 if (ShouldMakeNetworkRequestForURL(common_params_.url)) { |
195 // TODO(clamy): pass the real value for |is_external_protocol| if needed. | |
196 NavigationThrottle::ThrottleCheckResult result = | |
197 navigation_handle_->WillStartRequest( | |
198 begin_params_.method == "POST", | |
199 Referrer::SanitizeForRequest(common_params_.url, | |
200 common_params_.referrer), | |
201 begin_params_.has_user_gesture, common_params_.transition, false); | |
202 | |
203 // Abort the request if needed. This will destroy the NavigationRequest. | |
204 if (result == NavigationThrottle::CANCEL_AND_IGNORE) { | |
205 frame_tree_node_->ResetNavigationRequest(false); | |
206 return false; | |
207 } | |
208 | |
182 loader_ = NavigationURLLoader::Create( | 209 loader_ = NavigationURLLoader::Create( |
183 frame_tree_node_->navigator()->GetController()->GetBrowserContext(), | 210 frame_tree_node_->navigator()->GetController()->GetBrowserContext(), |
184 frame_tree_node_->frame_tree_node_id(), info_.Pass(), this); | 211 frame_tree_node_->frame_tree_node_id(), info_.Pass(), this); |
185 return true; | 212 return true; |
186 } | 213 } |
187 | 214 |
188 // There is no need to make a network request for this navigation, so commit | 215 // There is no need to make a network request for this navigation, so commit |
189 // it immediately. | 216 // it immediately. |
190 state_ = RESPONSE_STARTED; | 217 state_ = RESPONSE_STARTED; |
191 frame_tree_node_->navigator()->CommitNavigation( | 218 frame_tree_node_->navigator()->CommitNavigation( |
192 frame_tree_node_, nullptr, scoped_ptr<StreamHandle>()); | 219 frame_tree_node_, nullptr, scoped_ptr<StreamHandle>()); |
193 return false; | 220 return false; |
194 | 221 |
195 // TODO(davidben): Fire (and add as necessary) observer methods such as | 222 // TODO(davidben): Fire (and add as necessary) observer methods such as |
196 // DidStartProvisionalLoadForFrame for the navigation. | 223 // DidStartProvisionalLoadForFrame for the navigation. |
197 } | 224 } |
198 | 225 |
199 void NavigationRequest::CreateNavigationHandle(NavigatorDelegate* delegate) { | 226 void NavigationRequest::CreateNavigationHandle(NavigatorDelegate* delegate) { |
200 navigation_handle_ = NavigationHandleImpl::Create( | 227 navigation_handle_ = NavigationHandleFactory::Create( |
201 common_params_.url, frame_tree_node_->IsMainFrame(), delegate); | 228 common_params_.url, FilterURL(common_params_.url, frame_tree_node_), |
229 frame_tree_node_->IsMainFrame(), delegate); | |
202 } | 230 } |
203 | 231 |
204 void NavigationRequest::TransferNavigationHandleOwnership( | 232 void NavigationRequest::TransferNavigationHandleOwnership( |
205 RenderFrameHostImpl* render_frame_host) { | 233 RenderFrameHostImpl* render_frame_host) { |
206 render_frame_host->SetNavigationHandle(navigation_handle_.Pass()); | 234 render_frame_host->SetNavigationHandle(navigation_handle_.Pass()); |
207 } | 235 } |
208 | 236 |
209 void NavigationRequest::OnRequestRedirected( | 237 void NavigationRequest::OnRequestRedirected( |
210 const net::RedirectInfo& redirect_info, | 238 const net::RedirectInfo& redirect_info, |
211 const scoped_refptr<ResourceResponse>& response) { | 239 const scoped_refptr<ResourceResponse>& response) { |
212 // TODO(davidben): Track other changes from redirects. These are important | |
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 // TODO(clamy): Kill the renderer if FilterURL fails? |
246 // TODO(clamy): pass the real value for |is_external_protocol| if needed. | |
247 const GURL validated_new_url = | |
248 FilterURL(common_params_.url, frame_tree_node_); | |
249 NavigationThrottle::ThrottleCheckResult result = | |
250 navigation_handle_->WillRedirectRequest( | |
251 common_params_.url, validated_new_url, begin_params_.method == "POST", | |
252 common_params_.referrer.url, false); | |
253 | |
254 // Abort the request if needed. This will destroy the NavigationRequest. | |
255 if (result == NavigationThrottle::CANCEL_AND_IGNORE) { | |
256 frame_tree_node_->ResetNavigationRequest(false); | |
257 return; | |
258 } | |
259 | |
218 loader_->FollowRedirect(); | 260 loader_->FollowRedirect(); |
219 | 261 |
220 navigation_handle_->DidRedirectNavigation(redirect_info.new_url); | 262 navigation_handle_->DidRedirectNavigation(redirect_info.new_url); |
221 } | 263 } |
222 | 264 |
223 void NavigationRequest::OnResponseStarted( | 265 void NavigationRequest::OnResponseStarted( |
224 const scoped_refptr<ResourceResponse>& response, | 266 const scoped_refptr<ResourceResponse>& response, |
225 scoped_ptr<StreamHandle> body) { | 267 scoped_ptr<StreamHandle> body) { |
226 DCHECK(state_ == STARTED); | 268 DCHECK(state_ == STARTED); |
227 state_ = RESPONSE_STARTED; | 269 state_ = RESPONSE_STARTED; |
228 frame_tree_node_->navigator()->CommitNavigation(frame_tree_node_, | 270 frame_tree_node_->navigator()->CommitNavigation(frame_tree_node_, |
229 response.get(), body.Pass()); | 271 response.get(), body.Pass()); |
230 } | 272 } |
231 | 273 |
232 void NavigationRequest::OnRequestFailed(bool has_stale_copy_in_cache, | 274 void NavigationRequest::OnRequestFailed(bool has_stale_copy_in_cache, |
233 int net_error) { | 275 int net_error) { |
234 DCHECK(state_ == STARTED); | 276 DCHECK(state_ == STARTED); |
235 state_ = FAILED; | 277 state_ = FAILED; |
236 navigation_handle_->set_net_error_code(static_cast<net::Error>(net_error)); | 278 navigation_handle_->set_net_error_code(static_cast<net::Error>(net_error)); |
237 frame_tree_node_->navigator()->FailedNavigation( | 279 frame_tree_node_->navigator()->FailedNavigation( |
238 frame_tree_node_, has_stale_copy_in_cache, net_error); | 280 frame_tree_node_, has_stale_copy_in_cache, net_error); |
239 } | 281 } |
240 | 282 |
241 void NavigationRequest::OnRequestStarted(base::TimeTicks timestamp) { | 283 void NavigationRequest::OnRequestStarted(base::TimeTicks timestamp) { |
242 frame_tree_node_->navigator()->LogResourceRequestTime(timestamp, | 284 frame_tree_node_->navigator()->LogResourceRequestTime(timestamp, |
243 common_params_.url); | 285 common_params_.url); |
244 } | 286 } |
245 | 287 |
246 } // namespace content | 288 } // namespace content |
OLD | NEW |