| 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_message_filter.h" |
| 10 #include "content/browser/loader/resource_request_info_impl.h" | 11 #include "content/browser/loader/resource_request_info_impl.h" |
| 11 #include "content/browser/resource_context_impl.h" | 12 #include "content/browser/resource_context_impl.h" |
| 12 #include "content/browser/streams/stream.h" | 13 #include "content/browser/streams/stream.h" |
| 13 #include "content/browser/streams/stream_context.h" | 14 #include "content/browser/streams/stream_context.h" |
| 15 #include "content/common/resource_messages.h" |
| 14 #include "content/public/browser/resource_controller.h" | 16 #include "content/public/browser/resource_controller.h" |
| 15 #include "content/public/browser/stream_handle.h" | 17 #include "content/public/browser/stream_handle.h" |
| 16 #include "content/public/common/resource_response.h" | 18 #include "content/public/common/resource_response.h" |
| 17 #include "net/base/net_errors.h" | 19 #include "net/base/net_errors.h" |
| 18 #include "net/url_request/url_request.h" | 20 #include "net/url_request/url_request.h" |
| 19 | 21 |
| 20 namespace content { | 22 namespace content { |
| 21 | 23 |
| 22 NavigationResourceHandler::NavigationResourceHandler( | 24 NavigationResourceHandler::NavigationResourceHandler( |
| 23 net::URLRequest* request, | 25 net::URLRequest* request, |
| 24 NavigationURLLoaderImplCore* core) | 26 NavigationURLLoaderImplCore* core) |
| 25 : ResourceHandler(request), | 27 : ResourceHandler(request), |
| 26 core_(core) { | 28 core_(core) { |
| 27 core_->set_resource_handler(this); | 29 core_->set_resource_handler(this); |
| 28 writer_.set_immediate_mode(true); | |
| 29 } | 30 } |
| 30 | 31 |
| 31 NavigationResourceHandler::~NavigationResourceHandler() { | 32 NavigationResourceHandler::~NavigationResourceHandler() { |
| 32 if (core_) { | 33 if (core_) { |
| 33 core_->NotifyRequestFailed(false, net::ERR_ABORTED); | 34 core_->NotifyRequestFailed(false, net::ERR_ABORTED); |
| 34 DetachFromCore(); | 35 DetachFromCore(); |
| 35 } | 36 } |
| 36 } | 37 } |
| 37 | 38 |
| 38 void NavigationResourceHandler::Cancel() { | 39 void NavigationResourceHandler::Cancel() { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 53 const net::RedirectInfo& redirect_info, | 54 const net::RedirectInfo& redirect_info, |
| 54 ResourceResponse* response, | 55 ResourceResponse* response, |
| 55 bool* defer) { | 56 bool* defer) { |
| 56 DCHECK(core_); | 57 DCHECK(core_); |
| 57 | 58 |
| 58 // TODO(davidben): Perform a CSP check here, and anything else that would have | 59 // TODO(davidben): Perform a CSP check here, and anything else that would have |
| 59 // been done renderer-side. | 60 // been done renderer-side. |
| 60 DevToolsNetLogObserver::PopulateResponseInfo(request(), response); | 61 DevToolsNetLogObserver::PopulateResponseInfo(request(), response); |
| 61 core_->NotifyRequestRedirected(redirect_info, response); | 62 core_->NotifyRequestRedirected(redirect_info, response); |
| 62 *defer = true; | 63 *defer = true; |
| 64 |
| 63 return true; | 65 return true; |
| 64 } | 66 } |
| 65 | 67 |
| 66 bool NavigationResourceHandler::OnResponseStarted(ResourceResponse* response, | 68 bool NavigationResourceHandler::OnResponseStarted(ResourceResponse* response, |
| 67 bool* defer) { | 69 bool* defer) { |
| 70 // TODO(carlosk): review the TODO below. :) When I wrote it I thought we |
| 71 // needed to send ResourceMsg_ReceivedResponse from here but it seems we |
| 72 // don't. |
| 73 // TODO(carlosk): More "work" is done in |
| 74 // AsyncResourceHandler::OnResponseStarted than here. Now that this is the |
| 75 // resource handler actually carrying out the navigation load, some of that |
| 76 // has to be done here to. I'm adding TODOs below for some that but I'm not |
| 77 // fully sure of what's needed and what's not and further investigation is |
| 78 // need. |
| 79 // I'm assuming anything mentioning "upload", RDH delegate (we don't have one |
| 80 // in this class), "download", InliningHelper (I don't think we need one) are |
| 81 // not needed here. |
| 82 // TODO(carlosk): The same as above should affect other methods existing in |
| 83 // both classes. |
| 68 DCHECK(core_); | 84 DCHECK(core_); |
| 69 | 85 |
| 86 // TODO(carlosk): see if we need the time recording in |
| 87 // response_started_ticks_ used later for UMA metrics. |
| 88 |
| 70 ResourceRequestInfoImpl* info = GetRequestInfo(); | 89 ResourceRequestInfoImpl* info = GetRequestInfo(); |
| 90 LOG(ERROR) |
| 91 << "*** NavigationResourceHandler::OnResponseStarted frame_tree_node_id: " |
| 92 << info->frame_tree_node_id(); |
| 93 |
| 94 // TODO(carlosk): see if we need the filter check. |
| 71 | 95 |
| 72 // If the MimeTypeResourceHandler intercepted this request and converted it | 96 // If the MimeTypeResourceHandler intercepted this request and converted it |
| 73 // into a download, it will still call OnResponseStarted and immediately | 97 // into a download, it will still call OnResponseStarted and immediately |
| 74 // cancel. Ignore the call; OnReadCompleted will happen shortly. | 98 // cancel. Ignore the call; OnReadCompleted will happen shortly. |
| 75 // | 99 // |
| 76 // TODO(davidben): Move the dispatch out of MimeTypeResourceHandler. Perhaps | 100 // TODO(davidben): Move the dispatch out of MimeTypeResourceHandler. Perhaps |
| 77 // all the way to the UI thread. Downloads, user certificates, etc., should be | 101 // all the way to the UI thread. Downloads, user certificates, etc., should be |
| 78 // dispatched at the navigation layer. | 102 // dispatched at the navigation layer. |
| 79 if (info->IsDownload() || info->is_stream()) | 103 if (info->IsDownload() || info->is_stream()) |
| 80 return true; | 104 return true; |
| 81 | 105 |
| 82 StreamContext* stream_context = | 106 mojo::ScopedDataPipeConsumerHandle data_consumer_handle; |
| 83 GetStreamContextForResourceContext(info->GetContext()); | 107 writer_.InitializeStream(&data_consumer_handle); |
| 84 writer_.InitializeStream(stream_context->registry(), | |
| 85 request()->url().GetOrigin()); | |
| 86 | 108 |
| 87 // Detach from the loader; at this point, the request is now owned by the | 109 // Detach from the loader; at this point, the request is now owned by the |
| 88 // StreamHandle. | 110 // StreamHandle. |
| 89 DevToolsNetLogObserver::PopulateResponseInfo(request(), response); | 111 DevToolsNetLogObserver::PopulateResponseInfo(request(), response); |
| 90 core_->NotifyResponseStarted(response, writer_.stream()->CreateHandle()); | 112 // MAYBE SHOULD SEND THE CONSUMER HANDLE REFERENCE DIRECTLY FROM HERE? |
| 113 core_->NotifyResponseStarted(response, std::move(data_consumer_handle), |
| 114 GetRequestID()); |
| 91 DetachFromCore(); | 115 DetachFromCore(); |
| 116 |
| 117 // TODO(carlosk): see if we need the zoom level control here (I assume we do). |
| 118 |
| 119 response->head.request_start = request()->creation_time(); |
| 120 response->head.response_start = base::TimeTicks::Now(); |
| 121 |
| 122 // TODO(carlosk): see if we need the guard for http://crbug.com/124680 using |
| 123 // sent_received_response_msg_. |
| 124 |
| 125 // TODO(carlosk): see if we need to send ResourceMsg_ReceivedCachedMetadata. |
| 126 |
| 92 return true; | 127 return true; |
| 93 } | 128 } |
| 94 | 129 |
| 95 bool NavigationResourceHandler::OnWillStart(const GURL& url, bool* defer) { | 130 bool NavigationResourceHandler::OnWillStart(const GURL& url, bool* defer) { |
| 96 return true; | 131 return true; |
| 97 } | 132 } |
| 98 | 133 |
| 99 bool NavigationResourceHandler::OnBeforeNetworkStart(const GURL& url, | 134 bool NavigationResourceHandler::OnBeforeNetworkStart(const GURL& url, |
| 100 bool* defer) { | 135 bool* defer) { |
| 101 return true; | 136 return true; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 114 } | 149 } |
| 115 | 150 |
| 116 void NavigationResourceHandler::OnResponseCompleted( | 151 void NavigationResourceHandler::OnResponseCompleted( |
| 117 const net::URLRequestStatus& status, | 152 const net::URLRequestStatus& status, |
| 118 const std::string& security_info, | 153 const std::string& security_info, |
| 119 bool* defer) { | 154 bool* defer) { |
| 120 // If the request has already committed, close the stream and leave it as-is. | 155 // If the request has already committed, close the stream and leave it as-is. |
| 121 // | 156 // |
| 122 // TODO(davidben): The net error code should be passed through StreamWriter | 157 // TODO(davidben): The net error code should be passed through StreamWriter |
| 123 // down to the stream's consumer. See https://crbug.com/426162. | 158 // down to the stream's consumer. See https://crbug.com/426162. |
| 124 if (writer_.stream()) { | 159 if (writer_.has_stream()) { |
| 125 writer_.Finalize(); | 160 writer_.Finalize(); |
| 161 ResourceRequestInfoImpl* info = GetRequestInfo(); |
| 162 LOG(ERROR) << "*** NavigationResourceHandler::OnResponseCompleted " |
| 163 "frame_tree_node_id: " |
| 164 << info->frame_tree_node_id(); |
| 126 return; | 165 return; |
| 127 } | 166 } |
| 128 | 167 |
| 129 if (core_) { | 168 if (core_) { |
| 130 DCHECK_NE(net::OK, status.error()); | 169 DCHECK_NE(net::OK, status.error()); |
| 131 core_->NotifyRequestFailed(request()->response_info().was_cached, | 170 core_->NotifyRequestFailed(request()->response_info().was_cached, |
| 132 status.error()); | 171 status.error()); |
| 133 DetachFromCore(); | 172 DetachFromCore(); |
| 134 } | 173 } |
| 135 } | 174 } |
| 136 | 175 |
| 137 void NavigationResourceHandler::OnDataDownloaded(int bytes_downloaded) { | 176 void NavigationResourceHandler::OnDataDownloaded(int bytes_downloaded) { |
| 138 NOTREACHED(); | 177 NOTREACHED(); |
| 139 } | 178 } |
| 140 | 179 |
| 141 void NavigationResourceHandler::DetachFromCore() { | 180 void NavigationResourceHandler::DetachFromCore() { |
| 142 DCHECK(core_); | 181 DCHECK(core_); |
| 143 core_->set_resource_handler(nullptr); | 182 core_->set_resource_handler(nullptr); |
| 144 core_ = nullptr; | 183 core_ = nullptr; |
| 145 } | 184 } |
| 146 | 185 |
| 147 } // namespace content | 186 } // namespace content |
| OLD | NEW |