| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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_url_loader_network_service.h" | 5 #include "content/browser/loader/navigation_url_loader_network_service.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/bind_helpers.h" | 8 #include "base/bind_helpers.h" |
| 9 #include "base/memory/ptr_util.h" | 9 #include "base/memory/ptr_util.h" |
| 10 #include "base/trace_event/trace_event.h" | 10 #include "base/trace_event/trace_event.h" |
| 11 #include "content/browser/appcache/appcache_navigation_handle.h" | 11 #include "content/browser/appcache/appcache_navigation_handle.h" |
| 12 #include "content/browser/appcache/appcache_request_handler.h" | 12 #include "content/browser/appcache/appcache_request_handler.h" |
| 13 #include "content/browser/blob_storage/chrome_blob_storage_context.h" | 13 #include "content/browser/blob_storage/chrome_blob_storage_context.h" |
| 14 #include "content/browser/frame_host/frame_tree_node.h" | 14 #include "content/browser/frame_host/frame_tree_node.h" |
| 15 #include "content/browser/frame_host/navigation_request_info.h" | 15 #include "content/browser/frame_host/navigation_request_info.h" |
| 16 #include "content/browser/loader/navigation_resource_handler.h" | 16 #include "content/browser/loader/navigation_resource_handler.h" |
| 17 #include "content/browser/loader/navigation_resource_throttle.h" | 17 #include "content/browser/loader/navigation_resource_throttle.h" |
| 18 #include "content/browser/loader/navigation_url_loader_delegate.h" | 18 #include "content/browser/loader/navigation_url_loader_delegate.h" |
| 19 #include "content/browser/loader/url_loader_request_handler.h" | 19 #include "content/browser/loader/url_loader_request_handler.h" |
| 20 #include "content/browser/resource_context_impl.h" | 20 #include "content/browser/resource_context_impl.h" |
| 21 #include "content/browser/service_worker/service_worker_navigation_handle.h" | 21 #include "content/browser/service_worker/service_worker_navigation_handle.h" |
| 22 #include "content/browser/service_worker/service_worker_navigation_handle_core.h
" | 22 #include "content/browser/service_worker/service_worker_navigation_handle_core.h
" |
| 23 #include "content/browser/service_worker/service_worker_request_handler.h" | 23 #include "content/browser/service_worker/service_worker_request_handler.h" |
| 24 #include "content/browser/storage_partition_impl.h" | 24 #include "content/browser/storage_partition_impl.h" |
| 25 #include "content/browser/url_loader_factory_getter.h" | 25 #include "content/browser/url_loader_factory_getter.h" |
| 26 #include "content/browser/web_contents/web_contents_impl.h" | 26 #include "content/browser/web_contents/web_contents_impl.h" |
| 27 #include "content/browser/webui/url_data_manager_backend.h" | 27 #include "content/browser/webui/url_data_manager_backend.h" |
| 28 #include "content/browser/webui/web_ui_url_loader_factory.h" | 28 #include "content/browser/webui/web_ui_url_loader_factory.h" |
| 29 #include "content/common/throttling_url_loader.h" |
| 30 #include "content/common/url_loader_factory.mojom.h" |
| 29 #include "content/public/browser/browser_context.h" | 31 #include "content/public/browser/browser_context.h" |
| 30 #include "content/public/browser/browser_thread.h" | 32 #include "content/public/browser/browser_thread.h" |
| 33 #include "content/public/browser/content_browser_client.h" |
| 31 #include "content/public/browser/global_request_id.h" | 34 #include "content/public/browser/global_request_id.h" |
| 32 #include "content/public/browser/navigation_data.h" | 35 #include "content/public/browser/navigation_data.h" |
| 33 #include "content/public/browser/navigation_ui_data.h" | 36 #include "content/public/browser/navigation_ui_data.h" |
| 34 #include "content/public/browser/ssl_status.h" | 37 #include "content/public/browser/ssl_status.h" |
| 35 #include "content/public/browser/stream_handle.h" | 38 #include "content/public/browser/stream_handle.h" |
| 36 #include "content/public/common/referrer.h" | 39 #include "content/public/common/referrer.h" |
| 37 #include "content/public/common/url_constants.h" | 40 #include "content/public/common/url_constants.h" |
| 38 #include "mojo/public/cpp/bindings/strong_binding.h" | |
| 39 #include "net/base/load_flags.h" | 41 #include "net/base/load_flags.h" |
| 40 #include "net/traffic_annotation/network_traffic_annotation.h" | 42 #include "net/traffic_annotation/network_traffic_annotation.h" |
| 41 #include "net/url_request/url_request_context.h" | 43 #include "net/url_request/url_request_context.h" |
| 44 #include "services/service_manager/public/cpp/connector.h" |
| 42 | 45 |
| 43 namespace content { | 46 namespace content { |
| 44 | 47 |
| 45 namespace { | 48 namespace { |
| 46 | 49 |
| 47 // Request ID for browser initiated requests. We start at -2 on the same lines | 50 // Request ID for browser initiated requests. We start at -2 on the same lines |
| 48 // as ResourceDispatcherHostImpl. | 51 // as ResourceDispatcherHostImpl. |
| 49 int g_next_request_id = -2; | 52 int g_next_request_id = -2; |
| 50 | 53 |
| 51 WebContents* GetWebContentsFromFrameTreeNodeID(int frame_tree_node_id) { | 54 WebContents* GetWebContentsFromFrameTreeNodeID(int frame_tree_node_id) { |
| 52 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 55 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 53 FrameTreeNode* frame_tree_node = | 56 FrameTreeNode* frame_tree_node = |
| 54 FrameTreeNode::GloballyFindByID(frame_tree_node_id); | 57 FrameTreeNode::GloballyFindByID(frame_tree_node_id); |
| 55 if (!frame_tree_node) | 58 if (!frame_tree_node) |
| 56 return nullptr; | 59 return nullptr; |
| 57 | 60 |
| 58 return WebContentsImpl::FromFrameTreeNode(frame_tree_node); | 61 return WebContentsImpl::FromFrameTreeNode(frame_tree_node); |
| 59 } | 62 } |
| 60 | 63 |
| 61 class AssociatedURLLoaderWrapper final : public mojom::URLLoader { | |
| 62 public: | |
| 63 static void CreateLoaderAndStart( | |
| 64 mojom::URLLoaderFactory* factory, | |
| 65 mojom::URLLoaderRequest request, | |
| 66 uint32_t options, | |
| 67 const ResourceRequest& resource_request, | |
| 68 mojom::URLLoaderClientPtr client, | |
| 69 const net::MutableNetworkTrafficAnnotationTag& traffic_annotation) { | |
| 70 mojom::URLLoaderAssociatedPtr associated_ptr; | |
| 71 mojom::URLLoaderAssociatedRequest associated_request = | |
| 72 mojo::MakeRequest(&associated_ptr); | |
| 73 factory->CreateLoaderAndStart( | |
| 74 std::move(associated_request), 0 /* routing_id */, 0 /* request_id */, | |
| 75 options, resource_request, std::move(client), traffic_annotation); | |
| 76 mojo::MakeStrongBinding( | |
| 77 base::MakeUnique<AssociatedURLLoaderWrapper>(std::move(associated_ptr)), | |
| 78 std::move(request)); | |
| 79 } | |
| 80 | |
| 81 explicit AssociatedURLLoaderWrapper( | |
| 82 mojom::URLLoaderAssociatedPtr associated_ptr) | |
| 83 : associated_ptr_(std::move(associated_ptr)) {} | |
| 84 ~AssociatedURLLoaderWrapper() override {} | |
| 85 | |
| 86 void FollowRedirect() override { associated_ptr_->FollowRedirect(); } | |
| 87 | |
| 88 void SetPriority(net::RequestPriority priority, | |
| 89 int intra_priority_value) override { | |
| 90 associated_ptr_->SetPriority(priority, intra_priority_value); | |
| 91 } | |
| 92 | |
| 93 private: | |
| 94 mojom::URLLoaderAssociatedPtr associated_ptr_; | |
| 95 DISALLOW_COPY_AND_ASSIGN(AssociatedURLLoaderWrapper); | |
| 96 }; | |
| 97 | |
| 98 } // namespace | 64 } // namespace |
| 99 | 65 |
| 100 // Kept around during the lifetime of the navigation request, and is | 66 // Kept around during the lifetime of the navigation request, and is |
| 101 // responsible for dispatching a ResourceRequest to the appropriate | 67 // responsible for dispatching a ResourceRequest to the appropriate |
| 102 // URLLoader. In order to get the right URLLoader it builds a vector | 68 // URLLoader. In order to get the right URLLoader it builds a vector |
| 103 // of URLLoaderRequestHandler's and successively calls MaybeCreateLoader | 69 // of URLLoaderRequestHandler's and successively calls MaybeCreateLoader |
| 104 // on each until the request is successfully handled. The same sequence | 70 // on each until the request is successfully handled. The same sequence |
| 105 // may be performed multiple times when redirects happen. | 71 // may be performed multiple times when redirects happen. |
| 106 class NavigationURLLoaderNetworkService::URLLoaderRequestController { | 72 class NavigationURLLoaderNetworkService::URLLoaderRequestController |
| 73 : public mojom::URLLoaderClient { |
| 107 public: | 74 public: |
| 108 URLLoaderRequestController( | 75 URLLoaderRequestController( |
| 109 std::unique_ptr<ResourceRequest> resource_request, | 76 std::unique_ptr<ResourceRequest> resource_request, |
| 110 ResourceContext* resource_context, | 77 ResourceContext* resource_context, |
| 111 scoped_refptr<URLLoaderFactoryGetter> url_loader_factory_getter) | 78 scoped_refptr<URLLoaderFactoryGetter> url_loader_factory_getter, |
| 79 const base::WeakPtr<NavigationURLLoaderNetworkService>& owner) |
| 112 : resource_request_(std::move(resource_request)), | 80 : resource_request_(std::move(resource_request)), |
| 113 resource_context_(resource_context), | 81 resource_context_(resource_context), |
| 114 url_loader_factory_getter_(url_loader_factory_getter) {} | 82 url_loader_factory_getter_(url_loader_factory_getter), |
| 83 owner_(owner) {} |
| 115 | 84 |
| 116 virtual ~URLLoaderRequestController() { | 85 ~URLLoaderRequestController() override { |
| 117 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 86 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 118 } | 87 } |
| 119 | 88 |
| 120 void Start( | 89 void Start( |
| 121 ServiceWorkerNavigationHandleCore* service_worker_navigation_handle_core, | 90 ServiceWorkerNavigationHandleCore* service_worker_navigation_handle_core, |
| 122 AppCacheNavigationHandleCore* appcache_handle_core, | 91 AppCacheNavigationHandleCore* appcache_handle_core, |
| 123 std::unique_ptr<NavigationRequestInfo> request_info, | 92 std::unique_ptr<NavigationRequestInfo> request_info, |
| 124 mojom::URLLoaderFactoryPtrInfo factory_for_webui, | 93 mojom::URLLoaderFactoryPtrInfo factory_for_webui, |
| 125 const base::Callback<WebContents*(void)>& web_contents_getter, | 94 const base::Callback<WebContents*(void)>& web_contents_getter, |
| 126 mojom::URLLoaderRequest url_loader_request, | |
| 127 mojom::URLLoaderClientPtrInfo url_loader_client_ptr_info, | |
| 128 std::unique_ptr<service_manager::Connector> connector) { | 95 std::unique_ptr<service_manager::Connector> connector) { |
| 129 DCHECK_CURRENTLY_ON(BrowserThread::IO); | 96 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 130 url_loader_client_ptr_.Bind(std::move(url_loader_client_ptr_info)); | 97 web_contents_getter_ = web_contents_getter; |
| 131 const ResourceType resource_type = request_info->is_main_frame | 98 const ResourceType resource_type = request_info->is_main_frame |
| 132 ? RESOURCE_TYPE_MAIN_FRAME | 99 ? RESOURCE_TYPE_MAIN_FRAME |
| 133 : RESOURCE_TYPE_SUB_FRAME; | 100 : RESOURCE_TYPE_SUB_FRAME; |
| 134 | 101 |
| 135 if (resource_request_->request_body) { | 102 if (resource_request_->request_body) { |
| 136 AttachRequestBodyBlobDataHandles(resource_request_->request_body.get(), | 103 AttachRequestBodyBlobDataHandles(resource_request_->request_body.get(), |
| 137 resource_context_); | 104 resource_context_); |
| 138 } | 105 } |
| 139 | 106 |
| 140 // Requests to WebUI scheme won't get redirected to/from other schemes | 107 // Requests to WebUI scheme won't get redirected to/from other schemes |
| 141 // or be intercepted, so we just let it go here. | 108 // or be intercepted, so we just let it go here. |
| 142 if (factory_for_webui.is_valid()) { | 109 if (factory_for_webui.is_valid()) { |
| 143 mojom::URLLoaderFactoryPtr factory_ptr; | 110 webui_factory_ptr_.Bind(std::move(factory_for_webui)); |
| 144 factory_ptr.Bind(std::move(factory_for_webui)); | 111 url_loader_ = ThrottlingURLLoader::CreateLoaderAndStart( |
| 145 AssociatedURLLoaderWrapper::CreateLoaderAndStart( | 112 webui_factory_ptr_.get(), |
| 146 factory_ptr.get(), std::move(url_loader_request), | 113 GetContentClient()->browser()->CreateURLLoaderThrottles( |
| 147 mojom::kURLLoadOptionSendSSLInfo, *resource_request_, | 114 web_contents_getter_), |
| 148 std::move(url_loader_client_ptr_), | 115 0 /* routing_id? */, 0 /* request_id? */, |
| 116 mojom::kURLLoadOptionSendSSLInfo, *resource_request_, this, |
| 149 net::MutableNetworkTrafficAnnotationTag(NO_TRAFFIC_ANNOTATION_YET)); | 117 net::MutableNetworkTrafficAnnotationTag(NO_TRAFFIC_ANNOTATION_YET)); |
| 150 return; | 118 return; |
| 151 } | 119 } |
| 152 | 120 |
| 153 DCHECK(handlers_.empty()); | 121 DCHECK(handlers_.empty()); |
| 154 if (service_worker_navigation_handle_core) { | 122 if (service_worker_navigation_handle_core) { |
| 155 RequestContextFrameType frame_type = | 123 RequestContextFrameType frame_type = |
| 156 request_info->is_main_frame ? REQUEST_CONTEXT_FRAME_TYPE_TOP_LEVEL | 124 request_info->is_main_frame ? REQUEST_CONTEXT_FRAME_TYPE_TOP_LEVEL |
| 157 : REQUEST_CONTEXT_FRAME_TYPE_NESTED; | 125 : REQUEST_CONTEXT_FRAME_TYPE_NESTED; |
| 158 | 126 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 171 } | 139 } |
| 172 | 140 |
| 173 if (appcache_handle_core) { | 141 if (appcache_handle_core) { |
| 174 std::unique_ptr<URLLoaderRequestHandler> appcache_handler = | 142 std::unique_ptr<URLLoaderRequestHandler> appcache_handler = |
| 175 AppCacheRequestHandler::InitializeForNavigationNetworkService( | 143 AppCacheRequestHandler::InitializeForNavigationNetworkService( |
| 176 *resource_request_, appcache_handle_core); | 144 *resource_request_, appcache_handle_core); |
| 177 if (appcache_handler) | 145 if (appcache_handler) |
| 178 handlers_.push_back(std::move(appcache_handler)); | 146 handlers_.push_back(std::move(appcache_handler)); |
| 179 } | 147 } |
| 180 | 148 |
| 181 Restart(std::move(url_loader_request), std::move(url_loader_client_ptr_)); | 149 Restart(); |
| 182 } | 150 } |
| 183 | 151 |
| 184 // This could be called multiple times. | 152 // This could be called multiple times. |
| 185 void Restart(mojom::URLLoaderRequest url_loader_request, | 153 void Restart() { |
| 186 mojom::URLLoaderClientPtr url_loader_client_ptr) { | |
| 187 url_loader_request_ = std::move(url_loader_request); | |
| 188 url_loader_client_ptr_ = std::move(url_loader_client_ptr); | |
| 189 handler_index_ = 0; | 154 handler_index_ = 0; |
| 190 MaybeStartLoader(StartLoaderCallback()); | 155 MaybeStartLoader(StartLoaderCallback()); |
| 191 } | 156 } |
| 192 | 157 |
| 193 void MaybeStartLoader(StartLoaderCallback start_loader_callback) { | 158 void MaybeStartLoader(StartLoaderCallback start_loader_callback) { |
| 194 DCHECK(url_loader_client_ptr_.is_bound()); | |
| 195 | |
| 196 if (start_loader_callback) { | 159 if (start_loader_callback) { |
| 197 std::move(start_loader_callback) | 160 url_loader_ = ThrottlingURLLoader::CreateLoaderAndStart( |
| 198 .Run(std::move(url_loader_request_), | 161 std::move(start_loader_callback), |
| 199 std::move(url_loader_client_ptr_)); | 162 GetContentClient()->browser()->CreateURLLoaderThrottles( |
| 163 web_contents_getter_), |
| 164 *resource_request_, this); |
| 200 return; | 165 return; |
| 201 } | 166 } |
| 202 | 167 |
| 203 if (handler_index_ < handlers_.size()) { | 168 if (handler_index_ < handlers_.size()) { |
| 204 handlers_[handler_index_++]->MaybeCreateLoader( | 169 handlers_[handler_index_++]->MaybeCreateLoader( |
| 205 *resource_request_, resource_context_, | 170 *resource_request_, resource_context_, |
| 206 base::BindOnce(&URLLoaderRequestController::MaybeStartLoader, | 171 base::BindOnce(&URLLoaderRequestController::MaybeStartLoader, |
| 207 base::Unretained(this))); | 172 base::Unretained(this))); |
| 208 return; | 173 return; |
| 209 } | 174 } |
| 210 | 175 |
| 211 mojom::URLLoaderFactory* factory = nullptr; | 176 mojom::URLLoaderFactory* factory = nullptr; |
| 212 DCHECK_EQ(handlers_.size(), handler_index_); | 177 DCHECK_EQ(handlers_.size(), handler_index_); |
| 213 if (resource_request_->url.SchemeIs(url::kBlobScheme)) { | 178 if (resource_request_->url.SchemeIs(url::kBlobScheme)) { |
| 214 factory = url_loader_factory_getter_->GetBlobFactory()->get(); | 179 factory = url_loader_factory_getter_->GetBlobFactory()->get(); |
| 215 } else { | 180 } else { |
| 216 factory = url_loader_factory_getter_->GetNetworkFactory()->get(); | 181 factory = url_loader_factory_getter_->GetNetworkFactory()->get(); |
| 217 } | 182 } |
| 218 AssociatedURLLoaderWrapper::CreateLoaderAndStart( | 183 url_loader_ = ThrottlingURLLoader::CreateLoaderAndStart( |
| 219 factory, std::move(url_loader_request_), | 184 factory, |
| 220 mojom::kURLLoadOptionSendSSLInfo, *resource_request_, | 185 GetContentClient()->browser()->CreateURLLoaderThrottles( |
| 221 std::move(url_loader_client_ptr_), | 186 web_contents_getter_), |
| 187 0 /* routing_id? */, 0 /* request_id? */, |
| 188 mojom::kURLLoadOptionSendSSLInfo, *resource_request_, this, |
| 222 net::MutableNetworkTrafficAnnotationTag(NO_TRAFFIC_ANNOTATION_YET)); | 189 net::MutableNetworkTrafficAnnotationTag(NO_TRAFFIC_ANNOTATION_YET)); |
| 223 } | 190 } |
| 224 | 191 |
| 192 void FollowRedirect() { |
| 193 DCHECK_CURRENTLY_ON(BrowserThread::IO); |
| 194 DCHECK(url_loader_); |
| 195 |
| 196 url_loader_->FollowRedirect(); |
| 197 } |
| 198 |
| 225 private: | 199 private: |
| 200 // mojom::URLLoaderClient implementation: |
| 201 void OnReceiveResponse( |
| 202 const ResourceResponseHead& head, |
| 203 const base::Optional<net::SSLInfo>& ssl_info, |
| 204 mojom::DownloadedTempFilePtr downloaded_file) override { |
| 205 BrowserThread::PostTask( |
| 206 BrowserThread::UI, FROM_HERE, |
| 207 base::Bind(&NavigationURLLoaderNetworkService::OnReceiveResponse, |
| 208 owner_, head, ssl_info, base::Passed(&downloaded_file))); |
| 209 } |
| 210 |
| 211 void OnReceiveRedirect(const net::RedirectInfo& redirect_info, |
| 212 const ResourceResponseHead& head) override { |
| 213 BrowserThread::PostTask( |
| 214 BrowserThread::UI, FROM_HERE, |
| 215 base::Bind(&NavigationURLLoaderNetworkService::OnReceiveRedirect, |
| 216 owner_, redirect_info, head)); |
| 217 } |
| 218 |
| 219 void OnDataDownloaded(int64_t data_length, int64_t encoded_length) override {} |
| 220 |
| 221 void OnUploadProgress(int64_t current_position, |
| 222 int64_t total_size, |
| 223 OnUploadProgressCallback callback) override {} |
| 224 |
| 225 void OnReceiveCachedMetadata(const std::vector<uint8_t>& data) override {} |
| 226 |
| 227 void OnTransferSizeUpdated(int32_t transfer_size_diff) override {} |
| 228 |
| 229 void OnStartLoadingResponseBody( |
| 230 mojo::ScopedDataPipeConsumerHandle body) override { |
| 231 BrowserThread::PostTask( |
| 232 BrowserThread::UI, FROM_HERE, |
| 233 base::Bind( |
| 234 &NavigationURLLoaderNetworkService::OnStartLoadingResponseBody, |
| 235 owner_, base::Passed(&body))); |
| 236 } |
| 237 |
| 238 void OnComplete( |
| 239 const ResourceRequestCompletionStatus& completion_status) override { |
| 240 BrowserThread::PostTask( |
| 241 BrowserThread::UI, FROM_HERE, |
| 242 base::Bind(&NavigationURLLoaderNetworkService::OnComplete, owner_, |
| 243 completion_status)); |
| 244 } |
| 245 |
| 226 std::vector<std::unique_ptr<URLLoaderRequestHandler>> handlers_; | 246 std::vector<std::unique_ptr<URLLoaderRequestHandler>> handlers_; |
| 227 size_t handler_index_ = 0; | 247 size_t handler_index_ = 0; |
| 228 | 248 |
| 229 std::unique_ptr<ResourceRequest> resource_request_; | 249 std::unique_ptr<ResourceRequest> resource_request_; |
| 230 ResourceContext* resource_context_; | 250 ResourceContext* resource_context_; |
| 251 base::Callback<WebContents*()> web_contents_getter_; |
| 231 | 252 |
| 232 scoped_refptr<URLLoaderFactoryGetter> url_loader_factory_getter_; | 253 scoped_refptr<URLLoaderFactoryGetter> url_loader_factory_getter_; |
| 233 | 254 |
| 234 // Kept around until we create a loader. | 255 mojom::URLLoaderFactoryPtr webui_factory_ptr_; |
| 235 mojom::URLLoaderRequest url_loader_request_; | 256 |
| 236 mojom::URLLoaderClientPtr url_loader_client_ptr_; | 257 std::unique_ptr<ThrottlingURLLoader> url_loader_; |
| 258 |
| 259 // This is referenced only on the UI thread. |
| 260 base::WeakPtr<NavigationURLLoaderNetworkService> owner_; |
| 237 | 261 |
| 238 DISALLOW_COPY_AND_ASSIGN(URLLoaderRequestController); | 262 DISALLOW_COPY_AND_ASSIGN(URLLoaderRequestController); |
| 239 }; | 263 }; |
| 240 | 264 |
| 241 NavigationURLLoaderNetworkService::NavigationURLLoaderNetworkService( | 265 NavigationURLLoaderNetworkService::NavigationURLLoaderNetworkService( |
| 242 ResourceContext* resource_context, | 266 ResourceContext* resource_context, |
| 243 StoragePartition* storage_partition, | 267 StoragePartition* storage_partition, |
| 244 std::unique_ptr<NavigationRequestInfo> request_info, | 268 std::unique_ptr<NavigationRequestInfo> request_info, |
| 245 std::unique_ptr<NavigationUIData> navigation_ui_data, | 269 std::unique_ptr<NavigationUIData> navigation_ui_data, |
| 246 ServiceWorkerNavigationHandle* service_worker_navigation_handle, | 270 ServiceWorkerNavigationHandle* service_worker_navigation_handle, |
| 247 AppCacheNavigationHandle* appcache_handle, | 271 AppCacheNavigationHandle* appcache_handle, |
| 248 NavigationURLLoaderDelegate* delegate) | 272 NavigationURLLoaderDelegate* delegate) |
| 249 : delegate_(delegate), binding_(this) { | 273 : delegate_(delegate), weak_factory_(this) { |
| 250 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 274 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 251 | 275 |
| 252 TRACE_EVENT_ASYNC_BEGIN_WITH_TIMESTAMP1( | 276 TRACE_EVENT_ASYNC_BEGIN_WITH_TIMESTAMP1( |
| 253 "navigation", "Navigation timeToResponseStarted", this, | 277 "navigation", "Navigation timeToResponseStarted", this, |
| 254 request_info->common_params.navigation_start, "FrameTreeNode id", | 278 request_info->common_params.navigation_start, "FrameTreeNode id", |
| 255 request_info->frame_tree_node_id); | 279 request_info->frame_tree_node_id); |
| 256 | 280 |
| 257 // TODO(scottmg): Port over stuff from RDHI::BeginNavigationRequest() here. | 281 // TODO(scottmg): Port over stuff from RDHI::BeginNavigationRequest() here. |
| 258 auto new_request = base::MakeUnique<ResourceRequest>(); | 282 auto new_request = base::MakeUnique<ResourceRequest>(); |
| 259 | 283 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 279 // Sync loads should have maximum priority and should be the only | 303 // Sync loads should have maximum priority and should be the only |
| 280 // requests that have the ignore limits flag set. | 304 // requests that have the ignore limits flag set. |
| 281 DCHECK(!(load_flags & net::LOAD_IGNORE_LIMITS)); | 305 DCHECK(!(load_flags & net::LOAD_IGNORE_LIMITS)); |
| 282 | 306 |
| 283 new_request->load_flags = load_flags; | 307 new_request->load_flags = load_flags; |
| 284 | 308 |
| 285 new_request->request_body = request_info->common_params.post_data.get(); | 309 new_request->request_body = request_info->common_params.post_data.get(); |
| 286 | 310 |
| 287 int frame_tree_node_id = request_info->frame_tree_node_id; | 311 int frame_tree_node_id = request_info->frame_tree_node_id; |
| 288 | 312 |
| 289 mojom::URLLoaderRequest loader_request = mojo::MakeRequest(&url_loader_ptr_); | |
| 290 mojom::URLLoaderClientPtr url_loader_client_ptr_to_pass; | |
| 291 binding_.Bind(mojo::MakeRequest(&url_loader_client_ptr_to_pass)); | |
| 292 | |
| 293 // Check if a web UI scheme wants to handle this request. | 313 // Check if a web UI scheme wants to handle this request. |
| 294 mojom::URLLoaderFactoryPtrInfo factory_for_webui; | 314 mojom::URLLoaderFactoryPtrInfo factory_for_webui; |
| 295 const auto& schemes = URLDataManagerBackend::GetWebUISchemes(); | 315 const auto& schemes = URLDataManagerBackend::GetWebUISchemes(); |
| 296 if (std::find(schemes.begin(), schemes.end(), new_request->url.scheme()) != | 316 if (std::find(schemes.begin(), schemes.end(), new_request->url.scheme()) != |
| 297 schemes.end()) { | 317 schemes.end()) { |
| 298 FrameTreeNode* frame_tree_node = | 318 FrameTreeNode* frame_tree_node = |
| 299 FrameTreeNode::GloballyFindByID(frame_tree_node_id); | 319 FrameTreeNode::GloballyFindByID(frame_tree_node_id); |
| 300 factory_for_webui = CreateWebUIURLLoader(frame_tree_node).PassInterface(); | 320 factory_for_webui = CreateWebUIURLLoader(frame_tree_node).PassInterface(); |
| 301 } | 321 } |
| 302 | 322 |
| 303 g_next_request_id--; | 323 g_next_request_id--; |
| 304 | 324 |
| 305 DCHECK(!request_controller_); | 325 DCHECK(!request_controller_); |
| 306 request_controller_ = base::MakeUnique<URLLoaderRequestController>( | 326 request_controller_ = base::MakeUnique<URLLoaderRequestController>( |
| 307 std::move(new_request), resource_context, | 327 std::move(new_request), resource_context, |
| 308 static_cast<StoragePartitionImpl*>(storage_partition) | 328 static_cast<StoragePartitionImpl*>(storage_partition) |
| 309 ->url_loader_factory_getter()); | 329 ->url_loader_factory_getter(), |
| 330 weak_factory_.GetWeakPtr()); |
| 310 BrowserThread::PostTask( | 331 BrowserThread::PostTask( |
| 311 BrowserThread::IO, FROM_HERE, | 332 BrowserThread::IO, FROM_HERE, |
| 312 base::Bind( | 333 base::Bind( |
| 313 &URLLoaderRequestController::Start, | 334 &URLLoaderRequestController::Start, |
| 314 base::Unretained(request_controller_.get()), | 335 base::Unretained(request_controller_.get()), |
| 315 service_worker_navigation_handle | 336 service_worker_navigation_handle |
| 316 ? service_worker_navigation_handle->core() | 337 ? service_worker_navigation_handle->core() |
| 317 : nullptr, | 338 : nullptr, |
| 318 appcache_handle ? appcache_handle->core() : nullptr, | 339 appcache_handle ? appcache_handle->core() : nullptr, |
| 319 base::Passed(std::move(request_info)), | 340 base::Passed(std::move(request_info)), |
| 320 base::Passed(std::move(factory_for_webui)), | 341 base::Passed(std::move(factory_for_webui)), |
| 321 base::Bind(&GetWebContentsFromFrameTreeNodeID, frame_tree_node_id), | 342 base::Bind(&GetWebContentsFromFrameTreeNodeID, frame_tree_node_id), |
| 322 base::Passed(std::move(loader_request)), | |
| 323 base::Passed(url_loader_client_ptr_to_pass.PassInterface()), | |
| 324 base::Passed(ServiceManagerConnection::GetForProcess() | 343 base::Passed(ServiceManagerConnection::GetForProcess() |
| 325 ->GetConnector() | 344 ->GetConnector() |
| 326 ->Clone()))); | 345 ->Clone()))); |
| 327 } | 346 } |
| 328 | 347 |
| 329 NavigationURLLoaderNetworkService::~NavigationURLLoaderNetworkService() { | 348 NavigationURLLoaderNetworkService::~NavigationURLLoaderNetworkService() { |
| 330 BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, | 349 BrowserThread::DeleteSoon(BrowserThread::IO, FROM_HERE, |
| 331 request_controller_.release()); | 350 request_controller_.release()); |
| 332 } | 351 } |
| 333 | 352 |
| 334 void NavigationURLLoaderNetworkService::FollowRedirect() { | 353 void NavigationURLLoaderNetworkService::FollowRedirect() { |
| 335 url_loader_ptr_->FollowRedirect(); | 354 BrowserThread::PostTask( |
| 355 BrowserThread::IO, FROM_HERE, |
| 356 base::Bind(&URLLoaderRequestController::FollowRedirect, |
| 357 base::Unretained(request_controller_.get()))); |
| 336 } | 358 } |
| 337 | 359 |
| 338 void NavigationURLLoaderNetworkService::ProceedWithResponse() {} | 360 void NavigationURLLoaderNetworkService::ProceedWithResponse() {} |
| 339 | 361 |
| 340 void NavigationURLLoaderNetworkService::OnReceiveResponse( | 362 void NavigationURLLoaderNetworkService::OnReceiveResponse( |
| 341 const ResourceResponseHead& head, | 363 const ResourceResponseHead& head, |
| 342 const base::Optional<net::SSLInfo>& ssl_info, | 364 const base::Optional<net::SSLInfo>& ssl_info, |
| 343 mojom::DownloadedTempFilePtr downloaded_file) { | 365 mojom::DownloadedTempFilePtr downloaded_file) { |
| 344 // TODO(scottmg): This needs to do more of what | 366 // TODO(scottmg): This needs to do more of what |
| 345 // NavigationResourceHandler::OnReponseStarted() does. Or maybe in | 367 // NavigationResourceHandler::OnReponseStarted() does. Or maybe in |
| 346 // OnStartLoadingResponseBody(). | 368 // OnStartLoadingResponseBody(). |
| 347 if (ssl_info && ssl_info->cert) | 369 if (ssl_info && ssl_info->cert) |
| 348 NavigationResourceHandler::GetSSLStatusForRequest(*ssl_info, &ssl_status_); | 370 NavigationResourceHandler::GetSSLStatusForRequest(*ssl_info, &ssl_status_); |
| 349 response_ = base::MakeRefCounted<ResourceResponse>(); | 371 response_ = base::MakeRefCounted<ResourceResponse>(); |
| 350 response_->head = head; | 372 response_->head = head; |
| 351 } | 373 } |
| 352 | 374 |
| 353 void NavigationURLLoaderNetworkService::OnReceiveRedirect( | 375 void NavigationURLLoaderNetworkService::OnReceiveRedirect( |
| 354 const net::RedirectInfo& redirect_info, | 376 const net::RedirectInfo& redirect_info, |
| 355 const ResourceResponseHead& head) { | 377 const ResourceResponseHead& head) { |
| 356 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 378 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 357 // TODO(kinuko): Perform the necessary check and call | 379 // TODO(kinuko): Perform the necessary check and call |
| 358 // URLLoaderRequestController::Restart with the new URL?? | 380 // URLLoaderRequestController::Restart with the new URL?? |
| 359 scoped_refptr<ResourceResponse> response(new ResourceResponse()); | 381 scoped_refptr<ResourceResponse> response(new ResourceResponse()); |
| 360 response->head = head; | 382 response->head = head; |
| 361 delegate_->OnRequestRedirected(redirect_info, response); | 383 delegate_->OnRequestRedirected(redirect_info, response); |
| 362 } | 384 } |
| 363 | 385 |
| 364 void NavigationURLLoaderNetworkService::OnDataDownloaded( | |
| 365 int64_t data_length, | |
| 366 int64_t encoded_length) {} | |
| 367 | |
| 368 void NavigationURLLoaderNetworkService::OnUploadProgress( | |
| 369 int64_t current_position, | |
| 370 int64_t total_size, | |
| 371 OnUploadProgressCallback callback) {} | |
| 372 | |
| 373 void NavigationURLLoaderNetworkService::OnReceiveCachedMetadata( | |
| 374 const std::vector<uint8_t>& data) {} | |
| 375 | |
| 376 void NavigationURLLoaderNetworkService::OnTransferSizeUpdated( | |
| 377 int32_t transfer_size_diff) {} | |
| 378 | |
| 379 void NavigationURLLoaderNetworkService::OnStartLoadingResponseBody( | 386 void NavigationURLLoaderNetworkService::OnStartLoadingResponseBody( |
| 380 mojo::ScopedDataPipeConsumerHandle body) { | 387 mojo::ScopedDataPipeConsumerHandle body) { |
| 381 DCHECK(response_); | 388 DCHECK(response_); |
| 382 | 389 |
| 383 TRACE_EVENT_ASYNC_END2("navigation", "Navigation timeToResponseStarted", this, | 390 TRACE_EVENT_ASYNC_END2("navigation", "Navigation timeToResponseStarted", this, |
| 384 "&NavigationURLLoaderNetworkService", this, "success", | 391 "&NavigationURLLoaderNetworkService", this, "success", |
| 385 true); | 392 true); |
| 386 | 393 |
| 387 // Temporarily, we pass both a stream (null) and the data pipe to the | 394 // Temporarily, we pass both a stream (null) and the data pipe to the |
| 388 // delegate until PlzNavigate has shipped and we can be comfortable fully | 395 // delegate until PlzNavigate has shipped and we can be comfortable fully |
| (...skipping 10 matching lines...) Expand all Loading... |
| 399 TRACE_EVENT_ASYNC_END2("navigation", "Navigation timeToResponseStarted", | 406 TRACE_EVENT_ASYNC_END2("navigation", "Navigation timeToResponseStarted", |
| 400 this, "&NavigationURLLoaderNetworkService", this, | 407 this, "&NavigationURLLoaderNetworkService", this, |
| 401 "success", false); | 408 "success", false); |
| 402 | 409 |
| 403 delegate_->OnRequestFailed(completion_status.exists_in_cache, | 410 delegate_->OnRequestFailed(completion_status.exists_in_cache, |
| 404 completion_status.error_code); | 411 completion_status.error_code); |
| 405 } | 412 } |
| 406 } | 413 } |
| 407 | 414 |
| 408 } // namespace content | 415 } // namespace content |
| OLD | NEW |