Chromium Code Reviews| 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 <memory> | 7 #include <memory> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "content/browser/loader/navigation_url_loader_impl_core.h" | 10 #include "content/browser/loader/navigation_url_loader_impl_core.h" |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 87 *defer = true; | 87 *defer = true; |
| 88 return true; | 88 return true; |
| 89 } | 89 } |
| 90 | 90 |
| 91 bool NavigationResourceHandler::OnResponseStarted(ResourceResponse* response, | 91 bool NavigationResourceHandler::OnResponseStarted(ResourceResponse* response, |
| 92 bool* defer) { | 92 bool* defer) { |
| 93 DCHECK(core_); | 93 DCHECK(core_); |
| 94 | 94 |
| 95 ResourceRequestInfoImpl* info = GetRequestInfo(); | 95 ResourceRequestInfoImpl* info = GetRequestInfo(); |
| 96 | 96 |
| 97 // If the MimeTypeResourceHandler intercepted this request and converted it | |
| 98 // into a download, it will still call OnResponseStarted and immediately | |
| 99 // cancel. Ignore the call; OnReadCompleted will happen shortly. | |
| 100 // | |
| 101 // TODO(davidben): Move the dispatch out of MimeTypeResourceHandler. Perhaps | |
| 102 // all the way to the UI thread. Downloads, user certificates, etc., should be | |
| 103 // dispatched at the navigation layer. | |
| 104 if (info->IsDownload()) | |
| 105 return true; | |
| 106 | |
| 107 StreamContext* stream_context = | 97 StreamContext* stream_context = |
| 108 GetStreamContextForResourceContext(info->GetContext()); | 98 GetStreamContextForResourceContext(info->GetContext()); |
| 109 writer_.InitializeStream(stream_context->registry(), | 99 writer_.InitializeStream(stream_context->registry(), |
| 110 request()->url().GetOrigin()); | 100 request()->url().GetOrigin()); |
| 111 | 101 |
| 112 NetLogObserver::PopulateResponseInfo(request(), response); | 102 NetLogObserver::PopulateResponseInfo(request(), response); |
| 113 | 103 |
| 114 std::unique_ptr<NavigationData> cloned_data; | 104 std::unique_ptr<NavigationData> cloned_data; |
| 115 if (resource_dispatcher_host_delegate_) { | 105 if (resource_dispatcher_host_delegate_) { |
| 116 // Ask the embedder for a NavigationData instance. | 106 // Ask the embedder for a NavigationData instance. |
| 117 NavigationData* navigation_data = | 107 NavigationData* navigation_data = |
| 118 resource_dispatcher_host_delegate_->GetNavigationData(request()); | 108 resource_dispatcher_host_delegate_->GetNavigationData(request()); |
| 119 | 109 |
| 120 // Clone the embedder's NavigationData before moving it to the UI thread. | 110 // Clone the embedder's NavigationData before moving it to the UI thread. |
| 121 if (navigation_data) | 111 if (navigation_data) |
| 122 cloned_data = navigation_data->Clone(); | 112 cloned_data = navigation_data->Clone(); |
| 123 } | 113 } |
| 124 | 114 |
| 125 SSLStatus ssl_status; | 115 SSLStatus ssl_status; |
| 126 if (request()->ssl_info().cert.get()) { | 116 if (request()->ssl_info().cert.get()) { |
| 127 GetSSLStatusForRequest(request()->url(), request()->ssl_info(), | 117 GetSSLStatusForRequest(request()->url(), request()->ssl_info(), |
| 128 info->GetChildID(), &ssl_status); | 118 info->GetChildID(), &ssl_status); |
| 129 } | 119 } |
| 130 | 120 |
| 131 core_->NotifyResponseStarted(response, writer_.stream()->CreateHandle(), | 121 core_->NotifyResponseStarted(response, writer_.stream()->CreateHandle(), |
| 132 ssl_status, std::move(cloned_data)); | 122 ssl_status, std::move(cloned_data), |
| 133 // Don't defer stream based requests. This includes requests initiated via | 123 info->IsDownload()); |
| 134 // mime type sniffing, etc. | 124 // Don't defer stream based or download requests. This includes requests |
| 125 // initiated via mime type sniffing, etc. | |
| 135 // TODO(ananta) | 126 // TODO(ananta) |
| 136 // Make sure that the requests go through the throttle checks. Currently this | 127 // Make sure that the requests go through the throttle checks. Currently this |
| 137 // does not work as the InterceptingResourceHandler is above us and hence it | 128 // does not work as the InterceptingResourceHandler is above us and hence it |
| 138 // does not expect the old handler to defer the request. | 129 // does not expect the old handler to defer the request. |
| 139 if (!info->is_stream()) | 130 if (!info->is_stream() && !info->IsDownload()) |
|
clamy
2016/11/25 10:46:00
I think we should call DetachFromCore if the reque
yzshen1
2016/11/28 22:03:59
In practice it won't cause trouble because before
| |
| 140 *defer = true; | 131 *defer = true; |
| 141 return true; | 132 return true; |
| 142 } | 133 } |
| 143 | 134 |
| 144 bool NavigationResourceHandler::OnWillStart(const GURL& url, bool* defer) { | 135 bool NavigationResourceHandler::OnWillStart(const GURL& url, bool* defer) { |
| 145 return true; | 136 return true; |
| 146 } | 137 } |
| 147 | 138 |
| 148 bool NavigationResourceHandler::OnWillRead(scoped_refptr<net::IOBuffer>* buf, | 139 bool NavigationResourceHandler::OnWillRead(scoped_refptr<net::IOBuffer>* buf, |
| 149 int* buf_size, | 140 int* buf_size, |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 178 NOTREACHED(); | 169 NOTREACHED(); |
| 179 } | 170 } |
| 180 | 171 |
| 181 void NavigationResourceHandler::DetachFromCore() { | 172 void NavigationResourceHandler::DetachFromCore() { |
| 182 DCHECK(core_); | 173 DCHECK(core_); |
| 183 core_->set_resource_handler(nullptr); | 174 core_->set_resource_handler(nullptr); |
| 184 core_ = nullptr; | 175 core_ = nullptr; |
| 185 } | 176 } |
| 186 | 177 |
| 187 } // namespace content | 178 } // namespace content |
| OLD | NEW |