OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // See http://dev.chromium.org/developers/design-documents/multi-process-resourc
e-loading | 5 // See http://dev.chromium.org/developers/design-documents/multi-process-resourc
e-loading |
6 | 6 |
7 #include "content/browser/renderer_host/resource_dispatcher_host_impl.h" | 7 #include "content/browser/renderer_host/resource_dispatcher_host_impl.h" |
8 | 8 |
9 #include <set> | 9 #include <set> |
10 #include <vector> | 10 #include <vector> |
(...skipping 1393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1404 | 1404 |
1405 DCHECK(request->status().is_success()); | 1405 DCHECK(request->status().is_success()); |
1406 | 1406 |
1407 if (info->process_type() != PROCESS_TYPE_PLUGIN && | 1407 if (info->process_type() != PROCESS_TYPE_PLUGIN && |
1408 !ChildProcessSecurityPolicyImpl::GetInstance()-> | 1408 !ChildProcessSecurityPolicyImpl::GetInstance()-> |
1409 CanRequestURL(info->GetChildID(), new_url)) { | 1409 CanRequestURL(info->GetChildID(), new_url)) { |
1410 VLOG(1) << "Denied unauthorized request for " | 1410 VLOG(1) << "Denied unauthorized request for " |
1411 << new_url.possibly_invalid_spec(); | 1411 << new_url.possibly_invalid_spec(); |
1412 | 1412 |
1413 // Tell the renderer that this request was disallowed. | 1413 // Tell the renderer that this request was disallowed. |
1414 CancelRequestInternal(request, false); | 1414 CancelRequestInternal(request, false, false); |
1415 return; | 1415 return; |
1416 } | 1416 } |
1417 | 1417 |
1418 NotifyReceivedRedirect(request, info->GetChildID(), new_url); | 1418 NotifyReceivedRedirect(request, info->GetChildID(), new_url); |
1419 | 1419 |
1420 if (HandleExternalProtocol(info->GetRequestID(), info->GetChildID(), | 1420 if (HandleExternalProtocol(info->GetRequestID(), info->GetChildID(), |
1421 info->GetRouteID(), new_url, | 1421 info->GetRouteID(), new_url, |
1422 info->GetResourceType(), | 1422 info->GetResourceType(), |
1423 *request->context()->job_factory(), | 1423 *request->context()->job_factory(), |
1424 info->resource_handler())) { | 1424 info->resource_handler())) { |
1425 // The request is complete so we can remove it. | 1425 // The request is complete so we can remove it. |
1426 RemovePendingRequest(info->GetChildID(), info->GetRequestID()); | 1426 RemovePendingRequest(info->GetChildID(), info->GetRequestID()); |
1427 return; | 1427 return; |
1428 } | 1428 } |
1429 | 1429 |
1430 scoped_refptr<ResourceResponse> response(new ResourceResponse); | 1430 scoped_refptr<ResourceResponse> response(new ResourceResponse); |
1431 PopulateResourceResponse(request, response); | 1431 PopulateResourceResponse(request, response); |
1432 if (!info->resource_handler()->OnRequestRedirected(info->GetRequestID(), | 1432 if (!info->resource_handler()->OnRequestRedirected(info->GetRequestID(), |
1433 new_url, | 1433 new_url, |
1434 response, defer_redirect)) | 1434 response, defer_redirect)) |
1435 CancelRequestInternal(request, false); | 1435 CancelRequestInternal(request, false, false); |
1436 } | 1436 } |
1437 | 1437 |
1438 void ResourceDispatcherHostImpl::OnAuthRequired( | 1438 void ResourceDispatcherHostImpl::OnAuthRequired( |
1439 net::URLRequest* request, | 1439 net::URLRequest* request, |
1440 net::AuthChallengeInfo* auth_info) { | 1440 net::AuthChallengeInfo* auth_info) { |
1441 if (request->load_flags() & net::LOAD_DO_NOT_PROMPT_FOR_LOGIN) { | 1441 if (request->load_flags() & net::LOAD_DO_NOT_PROMPT_FOR_LOGIN) { |
1442 request->CancelAuth(); | 1442 request->CancelAuth(); |
1443 return; | 1443 return; |
1444 } | 1444 } |
1445 | 1445 |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1532 return; | 1532 return; |
1533 } | 1533 } |
1534 | 1534 |
1535 // We want to send a final upload progress message prior to sending | 1535 // We want to send a final upload progress message prior to sending |
1536 // the response complete message even if we're waiting for an ack to | 1536 // the response complete message even if we're waiting for an ack to |
1537 // to a previous upload progress message. | 1537 // to a previous upload progress message. |
1538 info->set_waiting_for_upload_progress_ack(false); | 1538 info->set_waiting_for_upload_progress_ack(false); |
1539 MaybeUpdateUploadProgress(info, request); | 1539 MaybeUpdateUploadProgress(info, request); |
1540 | 1540 |
1541 if (!CompleteResponseStarted(request)) { | 1541 if (!CompleteResponseStarted(request)) { |
1542 CancelRequestInternal(request, false); | 1542 CancelRequestInternal(request, false, false); |
1543 } else { | 1543 } else { |
1544 // Check if the handler paused the request in their OnResponseStarted. | 1544 // Check if the handler paused the request in their OnResponseStarted. |
1545 if (PauseRequestIfNeeded(info)) { | 1545 if (PauseRequestIfNeeded(info)) { |
1546 VLOG(1) << "OnResponseStarted pausing2: " << request->url().spec(); | 1546 VLOG(1) << "OnResponseStarted pausing2: " << request->url().spec(); |
1547 return; | 1547 return; |
1548 } | 1548 } |
1549 | 1549 |
1550 StartReading(request); | 1550 StartReading(request); |
1551 } | 1551 } |
1552 } else { | 1552 } else { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1587 | 1587 |
1588 if (defer) | 1588 if (defer) |
1589 PauseRequest(info->GetChildID(), info->GetRequestID(), true); | 1589 PauseRequest(info->GetChildID(), info->GetRequestID(), true); |
1590 | 1590 |
1591 return true; | 1591 return true; |
1592 } | 1592 } |
1593 | 1593 |
1594 void ResourceDispatcherHostImpl::CancelRequest(int child_id, | 1594 void ResourceDispatcherHostImpl::CancelRequest(int child_id, |
1595 int request_id, | 1595 int request_id, |
1596 bool from_renderer) { | 1596 bool from_renderer) { |
| 1597 CancelRequestWorker(child_id, request_id, from_renderer, false); |
| 1598 } |
| 1599 |
| 1600 void ResourceDispatcherHostImpl::CancelRequestWithHandledExternallyStatus( |
| 1601 int child_id, int request_id) { |
| 1602 CancelRequestWorker(child_id, request_id, false, true); |
| 1603 } |
| 1604 |
| 1605 void ResourceDispatcherHostImpl::CancelRequestWorker(int child_id, |
| 1606 int request_id, |
| 1607 bool from_renderer, |
| 1608 bool handled_externally) { |
| 1609 // The renderer will only ever ask us to perform a regular cancel. |
| 1610 DCHECK(!(handled_externally && from_renderer)); |
1597 GlobalRequestID id(child_id, request_id); | 1611 GlobalRequestID id(child_id, request_id); |
1598 if (from_renderer) { | 1612 if (from_renderer) { |
1599 // When the old renderer dies, it sends a message to us to cancel its | 1613 // When the old renderer dies, it sends a message to us to cancel its |
1600 // requests. | 1614 // requests. |
1601 if (transferred_navigations_.find(id) != transferred_navigations_.end()) | 1615 if (transferred_navigations_.find(id) != transferred_navigations_.end()) |
1602 return; | 1616 return; |
1603 } | 1617 } |
1604 | 1618 |
1605 PendingRequestList::iterator i = pending_requests_.find(id); | 1619 PendingRequestList::iterator i = pending_requests_.find(id); |
1606 if (i == pending_requests_.end()) { | 1620 if (i == pending_requests_.end()) { |
1607 // We probably want to remove this warning eventually, but I wanted to be | 1621 // We probably want to remove this warning eventually, but I wanted to be |
1608 // able to notice when this happens during initial development since it | 1622 // able to notice when this happens during initial development since it |
1609 // should be rare and may indicate a bug. | 1623 // should be rare and may indicate a bug. |
1610 DVLOG(1) << "Canceling a request that wasn't found"; | 1624 DVLOG(1) << "Canceling a request that wasn't found"; |
1611 return; | 1625 return; |
1612 } | 1626 } |
1613 net::URLRequest* request = i->second; | 1627 net::URLRequest* request = i->second; |
1614 | 1628 |
1615 bool started_before_cancel = request->is_pending(); | 1629 bool started_before_cancel = request->is_pending(); |
1616 if (CancelRequestInternal(request, from_renderer) && | 1630 if (CancelRequestInternal(request, from_renderer, handled_externally) && |
1617 !started_before_cancel) { | 1631 !started_before_cancel) { |
1618 // If the request isn't in flight, then we won't get an asynchronous | 1632 // If the request isn't in flight, then we won't get an asynchronous |
1619 // notification from the request, so we have to signal ourselves to finish | 1633 // notification from the request, so we have to signal ourselves to finish |
1620 // this request. | 1634 // this request. |
1621 MessageLoop::current()->PostTask( | 1635 MessageLoop::current()->PostTask( |
1622 FROM_HERE, | 1636 FROM_HERE, |
1623 base::Bind(&ResourceDispatcherHostImpl::CallResponseCompleted, | 1637 base::Bind(&ResourceDispatcherHostImpl::CallResponseCompleted, |
1624 base::Unretained(this), | 1638 base::Unretained(this), |
1625 child_id, | 1639 child_id, |
1626 request_id)); | 1640 request_id)); |
1627 } | 1641 } |
1628 } | 1642 } |
1629 | 1643 |
1630 bool ResourceDispatcherHostImpl::CancelRequestInternal(net::URLRequest* request, | 1644 bool ResourceDispatcherHostImpl::CancelRequestInternal( |
1631 bool from_renderer) { | 1645 net::URLRequest* request, |
| 1646 bool from_renderer, |
| 1647 bool handled_externally) { |
1632 VLOG(1) << "CancelRequest: " << request->url().spec(); | 1648 VLOG(1) << "CancelRequest: " << request->url().spec(); |
1633 | 1649 |
1634 // WebKit will send us a cancel for downloads since it no longer handles them. | 1650 // WebKit will send us a cancel for downloads since it no longer handles them. |
1635 // In this case, ignore the cancel since we handle downloads in the browser. | 1651 // In this case, ignore the cancel since we handle downloads in the browser. |
1636 ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest(request); | 1652 ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest(request); |
1637 if (!from_renderer || !info->is_download()) { | 1653 if (!from_renderer || !info->is_download()) { |
1638 if (info->login_delegate()) { | 1654 if (info->login_delegate()) { |
1639 info->login_delegate()->OnRequestCancelled(); | 1655 info->login_delegate()->OnRequestCancelled(); |
1640 info->set_login_delegate(NULL); | 1656 info->set_login_delegate(NULL); |
1641 } | 1657 } |
1642 if (info->ssl_client_auth_handler()) { | 1658 if (info->ssl_client_auth_handler()) { |
1643 info->ssl_client_auth_handler()->OnRequestCancelled(); | 1659 info->ssl_client_auth_handler()->OnRequestCancelled(); |
1644 info->set_ssl_client_auth_handler(NULL); | 1660 info->set_ssl_client_auth_handler(NULL); |
1645 } | 1661 } |
1646 request->Cancel(); | 1662 if (handled_externally) |
| 1663 request->CancelWithHandledExternallyStatus(); |
| 1664 else |
| 1665 request->Cancel(); |
1647 // Our callers assume |request| is valid after we return. | 1666 // Our callers assume |request| is valid after we return. |
1648 DCHECK(IsValidRequest(request)); | 1667 DCHECK(IsValidRequest(request)); |
1649 return true; | 1668 return true; |
1650 } | 1669 } |
1651 | 1670 |
1652 // Do not remove from the pending requests, as the request will still | 1671 // Do not remove from the pending requests, as the request will still |
1653 // call AllDataReceived, and may even have more data before it does | 1672 // call AllDataReceived, and may even have more data before it does |
1654 // that. | 1673 // that. |
1655 return false; | 1674 return false; |
1656 } | 1675 } |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1743 // of whether |defer_start| was set). | 1762 // of whether |defer_start| was set). |
1744 // (2) If |defer_start| was set to true, then the request is not added | 1763 // (2) If |defer_start| was set to true, then the request is not added |
1745 // into the resource queue, and will only be started in response to | 1764 // into the resource queue, and will only be started in response to |
1746 // calling StartDeferredRequest(). | 1765 // calling StartDeferredRequest(). |
1747 // (3) If |defer_start| is not set, then the request is inserted into | 1766 // (3) If |defer_start| is not set, then the request is inserted into |
1748 // the resource_queue_ (which may pause it further, or start it). | 1767 // the resource_queue_ (which may pause it further, or start it). |
1749 bool defer_start = false; | 1768 bool defer_start = false; |
1750 if (!info->resource_handler()->OnWillStart( | 1769 if (!info->resource_handler()->OnWillStart( |
1751 info->GetRequestID(), request->url(), | 1770 info->GetRequestID(), request->url(), |
1752 &defer_start)) { | 1771 &defer_start)) { |
1753 CancelRequestInternal(request, false); | 1772 CancelRequestInternal(request, false, false); |
1754 return; | 1773 return; |
1755 } | 1774 } |
1756 | 1775 |
1757 if (!defer_start) | 1776 if (!defer_start) |
1758 StartRequest(request); | 1777 StartRequest(request); |
1759 } | 1778 } |
1760 | 1779 |
1761 void ResourceDispatcherHostImpl::StartRequest(net::URLRequest* request) { | 1780 void ResourceDispatcherHostImpl::StartRequest(net::URLRequest* request) { |
1762 request->Start(); | 1781 request->Start(); |
1763 | 1782 |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1946 if (!request || !request->status().is_success()) { | 1965 if (!request || !request->status().is_success()) { |
1947 NOTREACHED(); | 1966 NOTREACHED(); |
1948 return false; | 1967 return false; |
1949 } | 1968 } |
1950 | 1969 |
1951 ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest(request); | 1970 ResourceRequestInfoImpl* info = ResourceRequestInfoImpl::ForRequest(request); |
1952 | 1971 |
1953 bool defer = false; | 1972 bool defer = false; |
1954 if (!info->resource_handler()->OnReadCompleted(info->GetRequestID(), | 1973 if (!info->resource_handler()->OnReadCompleted(info->GetRequestID(), |
1955 bytes_read, &defer)) { | 1974 bytes_read, &defer)) { |
1956 CancelRequestInternal(request, false); | 1975 CancelRequestInternal(request, false, false); |
1957 return false; | 1976 return false; |
1958 } | 1977 } |
1959 | 1978 |
1960 if (defer) | 1979 if (defer) |
1961 PauseRequest(info->GetChildID(), info->GetRequestID(), true); | 1980 PauseRequest(info->GetChildID(), info->GetRequestID(), true); |
1962 | 1981 |
1963 return *bytes_read != 0; | 1982 return *bytes_read != 0; |
1964 } | 1983 } |
1965 | 1984 |
1966 void ResourceDispatcherHostImpl::ResponseCompleted(net::URLRequest* request) { | 1985 void ResourceDispatcherHostImpl::ResponseCompleted(net::URLRequest* request) { |
(...skipping 394 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2361 return allow_cross_origin_auth_prompt_; | 2380 return allow_cross_origin_auth_prompt_; |
2362 } | 2381 } |
2363 | 2382 |
2364 bool ResourceDispatcherHostImpl::IsTransferredNavigation( | 2383 bool ResourceDispatcherHostImpl::IsTransferredNavigation( |
2365 const GlobalRequestID& transferred_request_id) const { | 2384 const GlobalRequestID& transferred_request_id) const { |
2366 return transferred_navigations_.find(transferred_request_id) != | 2385 return transferred_navigations_.find(transferred_request_id) != |
2367 transferred_navigations_.end(); | 2386 transferred_navigations_.end(); |
2368 } | 2387 } |
2369 | 2388 |
2370 } // namespace content | 2389 } // namespace content |
OLD | NEW |