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/service_worker/service_worker_navigation_handle.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" |
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" |
| 23 #include "third_party/WebKit/public/web/WebSandboxFlags.h" |
22 | 24 |
23 namespace content { | 25 namespace content { |
24 | 26 |
25 namespace { | 27 namespace { |
26 | 28 |
27 // Returns the net load flags to use based on the navigation type. | 29 // Returns the net load flags to use based on the navigation type. |
28 // TODO(clamy): unify the code with what is happening on the renderer side. | 30 // TODO(clamy): unify the code with what is happening on the renderer side. |
29 int LoadFlagFromNavigationType(FrameMsg_Navigate_Type::Value navigation_type) { | 31 int LoadFlagFromNavigationType(FrameMsg_Navigate_Type::Value navigation_type) { |
30 int load_flags = net::LOAD_NORMAL; | 32 int load_flags = net::LOAD_NORMAL; |
31 switch (navigation_type) { | 33 switch (navigation_type) { |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
245 common_params_.referrer.url, false, | 247 common_params_.referrer.url, false, |
246 base::Bind(&NavigationRequest::OnRedirectChecksComplete, | 248 base::Bind(&NavigationRequest::OnRedirectChecksComplete, |
247 base::Unretained(this))); | 249 base::Unretained(this))); |
248 } | 250 } |
249 | 251 |
250 void NavigationRequest::OnResponseStarted( | 252 void NavigationRequest::OnResponseStarted( |
251 const scoped_refptr<ResourceResponse>& response, | 253 const scoped_refptr<ResourceResponse>& response, |
252 scoped_ptr<StreamHandle> body) { | 254 scoped_ptr<StreamHandle> body) { |
253 DCHECK(state_ == STARTED); | 255 DCHECK(state_ == STARTED); |
254 state_ = RESPONSE_STARTED; | 256 state_ = RESPONSE_STARTED; |
| 257 |
| 258 // Update the service worker params of the request params. |
| 259 request_params_.should_create_service_worker = |
| 260 (frame_tree_node_->current_replication_state().sandbox_flags & |
| 261 blink::WebSandboxFlags::Origin) != blink::WebSandboxFlags::Origin; |
| 262 if (navigation_handle_->service_worker_handle()) { |
| 263 request_params_.service_worker_provider_id = |
| 264 navigation_handle_->service_worker_handle() |
| 265 ->service_worker_provider_host_id(); |
| 266 } |
| 267 |
255 frame_tree_node_->navigator()->CommitNavigation(frame_tree_node_, | 268 frame_tree_node_->navigator()->CommitNavigation(frame_tree_node_, |
256 response.get(), body.Pass()); | 269 response.get(), body.Pass()); |
257 } | 270 } |
258 | 271 |
259 void NavigationRequest::OnRequestFailed(bool has_stale_copy_in_cache, | 272 void NavigationRequest::OnRequestFailed(bool has_stale_copy_in_cache, |
260 int net_error) { | 273 int net_error) { |
261 DCHECK(state_ == STARTED); | 274 DCHECK(state_ == STARTED); |
262 state_ = FAILED; | 275 state_ = FAILED; |
263 navigation_handle_->set_net_error_code(static_cast<net::Error>(net_error)); | 276 navigation_handle_->set_net_error_code(static_cast<net::Error>(net_error)); |
264 frame_tree_node_->navigator()->FailedNavigation( | 277 frame_tree_node_->navigator()->FailedNavigation( |
(...skipping 10 matching lines...) Expand all Loading... |
275 CHECK(result != NavigationThrottle::DEFER); | 288 CHECK(result != NavigationThrottle::DEFER); |
276 | 289 |
277 // Abort the request if needed. This will destroy the NavigationRequest. | 290 // Abort the request if needed. This will destroy the NavigationRequest. |
278 if (result == NavigationThrottle::CANCEL_AND_IGNORE) { | 291 if (result == NavigationThrottle::CANCEL_AND_IGNORE) { |
279 frame_tree_node_->ResetNavigationRequest(false); | 292 frame_tree_node_->ResetNavigationRequest(false); |
280 return; | 293 return; |
281 } | 294 } |
282 | 295 |
283 loader_ = NavigationURLLoader::Create( | 296 loader_ = NavigationURLLoader::Create( |
284 frame_tree_node_->navigator()->GetController()->GetBrowserContext(), | 297 frame_tree_node_->navigator()->GetController()->GetBrowserContext(), |
285 info_.Pass(), this); | 298 info_.Pass(), navigation_handle_->service_worker_handle(), this); |
286 } | 299 } |
287 | 300 |
288 void NavigationRequest::OnRedirectChecksComplete( | 301 void NavigationRequest::OnRedirectChecksComplete( |
289 NavigationThrottle::ThrottleCheckResult result) { | 302 NavigationThrottle::ThrottleCheckResult result) { |
290 CHECK(result != NavigationThrottle::DEFER); | 303 CHECK(result != NavigationThrottle::DEFER); |
291 | 304 |
292 // Abort the request if needed. This will destroy the NavigationRequest. | 305 // Abort the request if needed. This will destroy the NavigationRequest. |
293 if (result == NavigationThrottle::CANCEL_AND_IGNORE) { | 306 if (result == NavigationThrottle::CANCEL_AND_IGNORE) { |
294 frame_tree_node_->ResetNavigationRequest(false); | 307 frame_tree_node_->ResetNavigationRequest(false); |
295 return; | 308 return; |
296 } | 309 } |
297 | 310 |
298 loader_->FollowRedirect(); | 311 loader_->FollowRedirect(); |
299 navigation_handle_->DidRedirectNavigation(common_params_.url); | 312 navigation_handle_->DidRedirectNavigation(common_params_.url); |
300 } | 313 } |
301 | 314 |
302 } // namespace content | 315 } // namespace content |
OLD | NEW |