| 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/loader/navigation_resource_handler.h" | 5 #include "content/browser/loader/navigation_resource_handler.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "content/browser/devtools/devtools_netlog_observer.h" | 8 #include "content/browser/devtools/devtools_netlog_observer.h" |
| 9 #include "content/browser/loader/navigation_url_loader_impl_core.h" | 9 #include "content/browser/loader/navigation_url_loader_impl_core.h" |
| 10 #include "content/browser/loader/resource_request_info_impl.h" | 10 #include "content/browser/loader/resource_request_info_impl.h" |
| 11 #include "content/browser/resource_context_impl.h" | 11 #include "content/browser/resource_context_impl.h" |
| 12 #include "content/browser/streams/stream.h" | 12 #include "content/browser/streams/stream.h" |
| 13 #include "content/browser/streams/stream_context.h" | 13 #include "content/browser/streams/stream_context.h" |
| 14 #include "content/public/browser/resource_controller.h" | 14 #include "content/public/browser/resource_controller.h" |
| 15 #include "content/public/browser/stream_handle.h" | 15 #include "content/public/browser/stream_handle.h" |
| 16 #include "content/public/common/resource_response.h" | 16 #include "content/public/common/resource_response.h" |
| 17 #include "net/base/net_errors.h" | 17 #include "net/base/net_errors.h" |
| 18 #include "net/url_request/url_request.h" | 18 #include "net/url_request/url_request.h" |
| 19 | 19 |
| 20 namespace content { | 20 namespace content { |
| 21 | 21 |
| 22 NavigationResourceHandler::NavigationResourceHandler( | 22 NavigationResourceHandler::NavigationResourceHandler( |
| 23 net::URLRequest* request, | 23 net::URLRequest* request, |
| 24 NavigationURLLoaderImplCore* core) | 24 NavigationURLLoaderImplCore* core) |
| 25 : ResourceHandler(request), | 25 : ResourceHandler(request), |
| 26 core_(core) { | 26 core_(core) { |
| 27 core_->set_resource_handler(this); | 27 core_->set_resource_handler(this); |
| 28 writer_.set_immediate_mode(true); | 28 // writer_.set_immediate_mode(true); |
| 29 } | 29 } |
| 30 | 30 |
| 31 NavigationResourceHandler::~NavigationResourceHandler() { | 31 NavigationResourceHandler::~NavigationResourceHandler() { |
| 32 if (core_) { | 32 if (core_) { |
| 33 core_->NotifyRequestFailed(false, net::ERR_ABORTED); | 33 core_->NotifyRequestFailed(false, net::ERR_ABORTED); |
| 34 DetachFromCore(); | 34 DetachFromCore(); |
| 35 } | 35 } |
| 36 } | 36 } |
| 37 | 37 |
| 38 void NavigationResourceHandler::Cancel() { | 38 void NavigationResourceHandler::Cancel() { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 // If the MimeTypeResourceHandler intercepted this request and converted it | 72 // If the MimeTypeResourceHandler intercepted this request and converted it |
| 73 // into a download, it will still call OnResponseStarted and immediately | 73 // into a download, it will still call OnResponseStarted and immediately |
| 74 // cancel. Ignore the call; OnReadCompleted will happen shortly. | 74 // cancel. Ignore the call; OnReadCompleted will happen shortly. |
| 75 // | 75 // |
| 76 // TODO(davidben): Move the dispatch out of MimeTypeResourceHandler. Perhaps | 76 // TODO(davidben): Move the dispatch out of MimeTypeResourceHandler. Perhaps |
| 77 // all the way to the UI thread. Downloads, user certificates, etc., should be | 77 // all the way to the UI thread. Downloads, user certificates, etc., should be |
| 78 // dispatched at the navigation layer. | 78 // dispatched at the navigation layer. |
| 79 if (info->IsDownload() || info->is_stream()) | 79 if (info->IsDownload() || info->is_stream()) |
| 80 return true; | 80 return true; |
| 81 | 81 |
| 82 StreamContext* stream_context = | 82 mojo::ScopedDataPipeConsumerHandle data_consumer_handle; |
| 83 GetStreamContextForResourceContext(info->GetContext()); | 83 writer_.InitializeStream(&data_consumer_handle); |
| 84 writer_.InitializeStream(stream_context->registry(), | |
| 85 request()->url().GetOrigin()); | |
| 86 | 84 |
| 87 // Detach from the loader; at this point, the request is now owned by the | 85 // Detach from the loader; at this point, the request is now owned by the |
| 88 // StreamHandle. | 86 // StreamHandle. |
| 89 DevToolsNetLogObserver::PopulateResponseInfo(request(), response); | 87 DevToolsNetLogObserver::PopulateResponseInfo(request(), response); |
| 90 core_->NotifyResponseStarted(response, writer_.stream()->CreateHandle()); | 88 // MAYBE SHOULD SEND THE CONSUMER HANDLE REFERENCE DIRECTLY FROM HERE? |
| 89 core_->NotifyResponseStarted( |
| 90 response, scoped_ptr<StreamHandle>(), std::move(data_consumer_handle)); |
| 91 DetachFromCore(); | 91 DetachFromCore(); |
| 92 return true; | 92 return true; |
| 93 } | 93 } |
| 94 | 94 |
| 95 bool NavigationResourceHandler::OnWillStart(const GURL& url, bool* defer) { | 95 bool NavigationResourceHandler::OnWillStart(const GURL& url, bool* defer) { |
| 96 return true; | 96 return true; |
| 97 } | 97 } |
| 98 | 98 |
| 99 bool NavigationResourceHandler::OnBeforeNetworkStart(const GURL& url, | 99 bool NavigationResourceHandler::OnBeforeNetworkStart(const GURL& url, |
| 100 bool* defer) { | 100 bool* defer) { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 114 } | 114 } |
| 115 | 115 |
| 116 void NavigationResourceHandler::OnResponseCompleted( | 116 void NavigationResourceHandler::OnResponseCompleted( |
| 117 const net::URLRequestStatus& status, | 117 const net::URLRequestStatus& status, |
| 118 const std::string& security_info, | 118 const std::string& security_info, |
| 119 bool* defer) { | 119 bool* defer) { |
| 120 // If the request has already committed, close the stream and leave it as-is. | 120 // If the request has already committed, close the stream and leave it as-is. |
| 121 // | 121 // |
| 122 // TODO(davidben): The net error code should be passed through StreamWriter | 122 // TODO(davidben): The net error code should be passed through StreamWriter |
| 123 // down to the stream's consumer. See https://crbug.com/426162. | 123 // down to the stream's consumer. See https://crbug.com/426162. |
| 124 if (writer_.stream()) { | 124 if (writer_.has_stream()) { |
| 125 writer_.Finalize(); | 125 writer_.Finalize(); |
| 126 return; | 126 return; |
| 127 } | 127 } |
| 128 | 128 |
| 129 if (core_) { | 129 if (core_) { |
| 130 DCHECK_NE(net::OK, status.error()); | 130 DCHECK_NE(net::OK, status.error()); |
| 131 core_->NotifyRequestFailed(request()->response_info().was_cached, | 131 core_->NotifyRequestFailed(request()->response_info().was_cached, |
| 132 status.error()); | 132 status.error()); |
| 133 DetachFromCore(); | 133 DetachFromCore(); |
| 134 } | 134 } |
| 135 } | 135 } |
| 136 | 136 |
| 137 void NavigationResourceHandler::OnDataDownloaded(int bytes_downloaded) { | 137 void NavigationResourceHandler::OnDataDownloaded(int bytes_downloaded) { |
| 138 NOTREACHED(); | 138 NOTREACHED(); |
| 139 } | 139 } |
| 140 | 140 |
| 141 void NavigationResourceHandler::DetachFromCore() { | 141 void NavigationResourceHandler::DetachFromCore() { |
| 142 DCHECK(core_); | 142 DCHECK(core_); |
| 143 core_->set_resource_handler(nullptr); | 143 core_->set_resource_handler(nullptr); |
| 144 core_ = nullptr; | 144 core_ = nullptr; |
| 145 } | 145 } |
| 146 | 146 |
| 147 } // namespace content | 147 } // namespace content |
| OLD | NEW |