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/webui/web_ui_url_loader_factory.h" | 5 #include "content/browser/webui/web_ui_url_loader_factory.h" |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/lazy_instance.h" | 10 #include "base/lazy_instance.h" |
11 #include "base/logging.h" | 11 #include "base/logging.h" |
12 #include "base/memory/ref_counted_memory.h" | 12 #include "base/memory/ref_counted_memory.h" |
13 #include "base/strings/string_piece.h" | 13 #include "base/strings/string_piece.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/render_frame_host_impl.h" | 15 #include "content/browser/frame_host/render_frame_host_impl.h" |
16 #include "content/browser/resource_context_impl.h" | 16 #include "content/browser/resource_context_impl.h" |
17 #include "content/browser/webui/url_data_manager_backend.h" | 17 #include "content/browser/webui/url_data_manager_backend.h" |
18 #include "content/browser/webui/url_data_source_impl.h" | 18 #include "content/browser/webui/url_data_source_impl.h" |
| 19 #include "content/common/network_service.mojom.h" |
19 #include "content/public/browser/browser_context.h" | 20 #include "content/public/browser/browser_context.h" |
20 #include "content/public/browser/browser_thread.h" | 21 #include "content/public/browser/browser_thread.h" |
21 #include "content/public/browser/render_process_host.h" | 22 #include "content/public/browser/render_process_host.h" |
22 #include "content/public/browser/web_contents.h" | 23 #include "content/public/browser/web_contents.h" |
| 24 #include "content/public/common/service_manager_connection.h" |
| 25 #include "content/public/common/service_names.mojom.h" |
| 26 #include "content/public/common/url_constants.h" |
23 #include "mojo/public/cpp/bindings/binding_set.h" | 27 #include "mojo/public/cpp/bindings/binding_set.h" |
| 28 #include "services/service_manager/public/cpp/connector.h" |
24 #include "third_party/zlib/google/compression_utils.h" | 29 #include "third_party/zlib/google/compression_utils.h" |
25 #include "ui/base/template_expressions.h" | 30 #include "ui/base/template_expressions.h" |
26 | 31 |
27 namespace content { | 32 namespace content { |
28 | 33 |
29 namespace { | 34 namespace { |
30 | 35 |
31 class WebUIURLLoaderFactory; | 36 class WebUIURLLoaderFactory; |
32 base::LazyInstance<std::map<int, std::unique_ptr<WebUIURLLoaderFactory>>>::Leaky | 37 base::LazyInstance<std::map<int, std::unique_ptr<WebUIURLLoaderFactory>>>::Leaky |
33 g_factories = LAZY_INSTANCE_INITIALIZER; | 38 g_factories = LAZY_INSTANCE_INITIALIZER; |
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
231 } | 236 } |
232 | 237 |
233 // mojom::URLLoaderFactory implementation: | 238 // mojom::URLLoaderFactory implementation: |
234 void CreateLoaderAndStart(mojom::URLLoaderAssociatedRequest loader, | 239 void CreateLoaderAndStart(mojom::URLLoaderAssociatedRequest loader, |
235 int32_t routing_id, | 240 int32_t routing_id, |
236 int32_t request_id, | 241 int32_t request_id, |
237 uint32_t options, | 242 uint32_t options, |
238 const ResourceRequest& request, | 243 const ResourceRequest& request, |
239 mojom::URLLoaderClientPtr client) override { | 244 mojom::URLLoaderClientPtr client) override { |
240 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 245 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 246 if (request.url.host_piece() == kChromeUINetworkViewCacheHost) { |
| 247 mojom::NetworkServicePtr network_service; |
| 248 ServiceManagerConnection::GetForProcess()->GetConnector()->BindInterface( |
| 249 mojom::kNetworkServiceName, &network_service); |
| 250 network_service->HandleViewCacheRequest(request, std::move(client)); |
| 251 return; |
| 252 } |
| 253 |
241 BrowserThread::PostTask( | 254 BrowserThread::PostTask( |
242 BrowserThread::IO, FROM_HERE, | 255 BrowserThread::IO, FROM_HERE, |
243 base::BindOnce(&StartURLLoader, request, frame_tree_node_id_, | 256 base::BindOnce(&StartURLLoader, request, frame_tree_node_id_, |
244 client.PassInterface(), resource_context_)); | 257 client.PassInterface(), resource_context_)); |
245 } | 258 } |
246 | 259 |
247 void SyncLoad(int32_t routing_id, | 260 void SyncLoad(int32_t routing_id, |
248 int32_t request_id, | 261 int32_t request_id, |
249 const ResourceRequest& request, | 262 const ResourceRequest& request, |
250 SyncLoadCallback callback) override { | 263 SyncLoadCallback callback) override { |
(...skipping 16 matching lines...) Expand all Loading... |
267 } // namespace | 280 } // namespace |
268 | 281 |
269 mojom::URLLoaderFactoryPtr GetWebUIURLLoader(FrameTreeNode* node) { | 282 mojom::URLLoaderFactoryPtr GetWebUIURLLoader(FrameTreeNode* node) { |
270 int ftn_id = node->frame_tree_node_id(); | 283 int ftn_id = node->frame_tree_node_id(); |
271 if (g_factories.Get()[ftn_id].get() == nullptr) | 284 if (g_factories.Get()[ftn_id].get() == nullptr) |
272 g_factories.Get()[ftn_id] = base::MakeUnique<WebUIURLLoaderFactory>(node); | 285 g_factories.Get()[ftn_id] = base::MakeUnique<WebUIURLLoaderFactory>(node); |
273 return g_factories.Get()[ftn_id]->CreateBinding(); | 286 return g_factories.Get()[ftn_id]->CreateBinding(); |
274 } | 287 } |
275 | 288 |
276 } // namespace content | 289 } // namespace content |
OLD | NEW |