| 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/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
| 10 #include "base/memory/ptr_util.h" | 10 #include "base/memory/ptr_util.h" |
| 11 #include "base/trace_event/trace_event.h" | 11 #include "base/trace_event/trace_event.h" |
| 12 #include "content/browser/blob_storage/chrome_blob_storage_context.h" | 12 #include "content/browser/blob_storage/chrome_blob_storage_context.h" |
| 13 #include "content/browser/frame_host/frame_tree_node.h" | 13 #include "content/browser/frame_host/frame_tree_node.h" |
| 14 #include "content/browser/frame_host/navigation_request_info.h" | 14 #include "content/browser/frame_host/navigation_request_info.h" |
| 15 #include "content/browser/loader/navigation_resource_handler.h" | 15 #include "content/browser/loader/navigation_resource_handler.h" |
| 16 #include "content/browser/loader/navigation_resource_throttle.h" | 16 #include "content/browser/loader/navigation_resource_throttle.h" |
| 17 #include "content/browser/loader/navigation_url_loader_delegate.h" | 17 #include "content/browser/loader/navigation_url_loader_delegate.h" |
| 18 #include "content/browser/webui/url_data_manager_backend.h" |
| 18 #include "content/browser/webui/web_ui_url_loader_factory.h" | 19 #include "content/browser/webui/web_ui_url_loader_factory.h" |
| 19 #include "content/public/browser/browser_thread.h" | 20 #include "content/public/browser/browser_thread.h" |
| 20 #include "content/public/browser/global_request_id.h" | 21 #include "content/public/browser/global_request_id.h" |
| 21 #include "content/public/browser/navigation_data.h" | 22 #include "content/public/browser/navigation_data.h" |
| 22 #include "content/public/browser/navigation_ui_data.h" | 23 #include "content/public/browser/navigation_ui_data.h" |
| 23 #include "content/public/browser/ssl_status.h" | 24 #include "content/public/browser/ssl_status.h" |
| 24 #include "content/public/browser/stream_handle.h" | 25 #include "content/public/browser/stream_handle.h" |
| 25 #include "content/public/common/referrer.h" | 26 #include "content/public/common/referrer.h" |
| 26 #include "content/public/common/service_manager_connection.h" | 27 #include "content/public/common/service_manager_connection.h" |
| 27 #include "content/public/common/service_names.mojom.h" | 28 #include "content/public/common/service_names.mojom.h" |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 | 208 |
| 208 mojom::URLLoaderFactory* factory = nullptr; | 209 mojom::URLLoaderFactory* factory = nullptr; |
| 209 // This |factory_ptr| will be destroyed when it goes out of scope. Because | 210 // This |factory_ptr| will be destroyed when it goes out of scope. Because |
| 210 // |url_loader_associated_ptr_| is associated with it, it will be disconnected | 211 // |url_loader_associated_ptr_| is associated with it, it will be disconnected |
| 211 // as well. That means NavigationURLLoaderNetworkService::FollowRedirect() | 212 // as well. That means NavigationURLLoaderNetworkService::FollowRedirect() |
| 212 // won't work as expected, the |url_loader_associated_ptr_| will silently drop | 213 // won't work as expected, the |url_loader_associated_ptr_| will silently drop |
| 213 // calls. | 214 // calls. |
| 214 // This is fine for now since the only user of this is WebUI which doesn't | 215 // This is fine for now since the only user of this is WebUI which doesn't |
| 215 // need this, but we'll have to fix this when other consumers come up. | 216 // need this, but we'll have to fix this when other consumers come up. |
| 216 mojom::URLLoaderFactoryPtr factory_ptr; | 217 mojom::URLLoaderFactoryPtr factory_ptr; |
| 217 if (request->url.SchemeIs(kChromeUIScheme)) { | 218 const auto& schemes = URLDataManagerBackend::GetWebUISchemes(); |
| 219 if (std::find(schemes.begin(), schemes.end(), request->url.scheme()) != |
| 220 schemes.end()) { |
| 218 FrameTreeNode* frame_tree_node = | 221 FrameTreeNode* frame_tree_node = |
| 219 FrameTreeNode::GloballyFindByID(request_info_->frame_tree_node_id); | 222 FrameTreeNode::GloballyFindByID(request_info_->frame_tree_node_id); |
| 220 factory_ptr = GetWebUIURLLoader(frame_tree_node); | 223 factory_ptr = GetWebUIURLLoader(frame_tree_node); |
| 221 factory = factory_ptr.get(); | 224 factory = factory_ptr.get(); |
| 222 } | 225 } |
| 223 | 226 |
| 224 if (!factory) | 227 if (!factory) |
| 225 factory = GetURLLoaderFactory(); | 228 factory = GetURLLoaderFactory(); |
| 226 | 229 |
| 227 factory->CreateLoaderAndStart(mojo::MakeRequest(&url_loader_associated_ptr_), | 230 factory->CreateLoaderAndStart(mojo::MakeRequest(&url_loader_associated_ptr_), |
| 228 0 /* routing_id? */, 0 /* request_id? */, | 231 0 /* routing_id? */, 0 /* request_id? */, |
| 229 mojom::kURLLoadOptionSendSSLInfo, *request, | 232 mojom::kURLLoadOptionSendSSLInfo, *request, |
| 230 std::move(url_loader_client_ptr_to_pass)); | 233 std::move(url_loader_client_ptr_to_pass)); |
| 231 } | 234 } |
| 232 | 235 |
| 233 mojom::URLLoaderFactory* | 236 mojom::URLLoaderFactory* |
| 234 NavigationURLLoaderNetworkService::GetURLLoaderFactory() { | 237 NavigationURLLoaderNetworkService::GetURLLoaderFactory() { |
| 235 // TODO(yzshen): We will need the ability to customize the factory per frame | 238 // TODO(yzshen): We will need the ability to customize the factory per frame |
| 236 // e.g., for appcache or service worker. | 239 // e.g., for appcache or service worker. |
| 237 if (!g_url_loader_factory.Get()) { | 240 if (!g_url_loader_factory.Get()) { |
| 238 ServiceManagerConnection::GetForProcess()->GetConnector()->BindInterface( | 241 ServiceManagerConnection::GetForProcess()->GetConnector()->BindInterface( |
| 239 mojom::kNetworkServiceName, &g_url_loader_factory.Get()); | 242 mojom::kNetworkServiceName, &g_url_loader_factory.Get()); |
| 240 } | 243 } |
| 241 | 244 |
| 242 return g_url_loader_factory.Get().get(); | 245 return g_url_loader_factory.Get().get(); |
| 243 } | 246 } |
| 244 | 247 |
| 245 } // namespace content | 248 } // namespace content |
| OLD | NEW |