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/blob_storage/blob_internals_url_loader.h" | 14 #include "content/browser/blob_storage/blob_internals_url_loader.h" |
15 #include "content/browser/blob_storage/chrome_blob_storage_context.h" | 15 #include "content/browser/blob_storage/chrome_blob_storage_context.h" |
16 #include "content/browser/frame_host/frame_tree_node.h" | 16 #include "content/browser/frame_host/frame_tree_node.h" |
17 #include "content/browser/frame_host/render_frame_host_impl.h" | 17 #include "content/browser/frame_host/render_frame_host_impl.h" |
18 #include "content/browser/histogram_internals_url_loader.h" | 18 #include "content/browser/histogram_internals_url_loader.h" |
19 #include "content/browser/resource_context_impl.h" | 19 #include "content/browser/resource_context_impl.h" |
20 #include "content/browser/webui/network_error_url_loader.h" | 20 #include "content/browser/webui/network_error_url_loader.h" |
21 #include "content/browser/webui/url_data_manager_backend.h" | 21 #include "content/browser/webui/url_data_manager_backend.h" |
22 #include "content/browser/webui/url_data_source_impl.h" | 22 #include "content/browser/webui/url_data_source_impl.h" |
| 23 #include "content/common/network_service.mojom.h" |
23 #include "content/public/browser/browser_context.h" | 24 #include "content/public/browser/browser_context.h" |
24 #include "content/public/browser/browser_thread.h" | 25 #include "content/public/browser/browser_thread.h" |
25 #include "content/public/browser/render_process_host.h" | 26 #include "content/public/browser/render_process_host.h" |
26 #include "content/public/browser/web_contents.h" | 27 #include "content/public/browser/web_contents.h" |
| 28 #include "content/public/common/service_manager_connection.h" |
| 29 #include "content/public/common/service_names.mojom.h" |
27 #include "content/public/common/url_constants.h" | 30 #include "content/public/common/url_constants.h" |
28 #include "mojo/public/cpp/bindings/binding_set.h" | 31 #include "mojo/public/cpp/bindings/binding_set.h" |
| 32 #include "services/service_manager/public/cpp/connector.h" |
29 #include "third_party/zlib/google/compression_utils.h" | 33 #include "third_party/zlib/google/compression_utils.h" |
30 #include "ui/base/template_expressions.h" | 34 #include "ui/base/template_expressions.h" |
31 | 35 |
32 namespace content { | 36 namespace content { |
33 | 37 |
34 namespace { | 38 namespace { |
35 | 39 |
36 class WebUIURLLoaderFactory; | 40 class WebUIURLLoaderFactory; |
37 base::LazyInstance<std::map<int, std::unique_ptr<WebUIURLLoaderFactory>>>::Leaky | 41 base::LazyInstance<std::map<int, std::unique_ptr<WebUIURLLoaderFactory>>>::Leaky |
38 g_factories = LAZY_INSTANCE_INITIALIZER; | 42 g_factories = LAZY_INSTANCE_INITIALIZER; |
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
234 } | 238 } |
235 | 239 |
236 // mojom::URLLoaderFactory implementation: | 240 // mojom::URLLoaderFactory implementation: |
237 void CreateLoaderAndStart(mojom::URLLoaderAssociatedRequest loader, | 241 void CreateLoaderAndStart(mojom::URLLoaderAssociatedRequest loader, |
238 int32_t routing_id, | 242 int32_t routing_id, |
239 int32_t request_id, | 243 int32_t request_id, |
240 uint32_t options, | 244 uint32_t options, |
241 const ResourceRequest& request, | 245 const ResourceRequest& request, |
242 mojom::URLLoaderClientPtr client) override { | 246 mojom::URLLoaderClientPtr client) override { |
243 DCHECK_CURRENTLY_ON(BrowserThread::UI); | 247 DCHECK_CURRENTLY_ON(BrowserThread::UI); |
| 248 if (request.url.host_piece() == kChromeUINetworkViewCacheHost) { |
| 249 mojom::NetworkServicePtr network_service; |
| 250 ServiceManagerConnection::GetForProcess()->GetConnector()->BindInterface( |
| 251 mojom::kNetworkServiceName, &network_service); |
| 252 network_service->HandleViewCacheRequest(request, std::move(client)); |
| 253 return; |
| 254 } |
| 255 |
244 if (request.url.host_piece() == kChromeUIBlobInternalsHost) { | 256 if (request.url.host_piece() == kChromeUIBlobInternalsHost) { |
245 BrowserThread::PostTask( | 257 BrowserThread::PostTask( |
246 BrowserThread::IO, FROM_HERE, | 258 BrowserThread::IO, FROM_HERE, |
247 base::BindOnce( | 259 base::BindOnce( |
248 &StartBlobInternalsURLLoader, request, client.PassInterface(), | 260 &StartBlobInternalsURLLoader, request, client.PassInterface(), |
249 base::Unretained( | 261 base::Unretained( |
250 ChromeBlobStorageContext::GetFor(browser_context_)))); | 262 ChromeBlobStorageContext::GetFor(browser_context_)))); |
251 return; | 263 return; |
252 } else if (request.url.host_piece() == kChromeUINetworkErrorHost || | 264 } |
253 request.url.host_piece() == kChromeUIDinoHost) { | 265 |
| 266 if (request.url.host_piece() == kChromeUINetworkErrorHost || |
| 267 request.url.host_piece() == kChromeUIDinoHost) { |
254 StartNetworkErrorsURLLoader(request, std::move(client)); | 268 StartNetworkErrorsURLLoader(request, std::move(client)); |
255 return; | 269 return; |
256 } else if (request.url.host_piece() == kChromeUIHistogramHost) { | 270 } |
| 271 |
| 272 if (request.url.host_piece() == kChromeUIHistogramHost) { |
257 StartHistogramInternalsURLLoader(request, std::move(client)); | 273 StartHistogramInternalsURLLoader(request, std::move(client)); |
258 return; | 274 return; |
259 } | 275 } |
260 | 276 |
261 BrowserThread::PostTask( | 277 BrowserThread::PostTask( |
262 BrowserThread::IO, FROM_HERE, | 278 BrowserThread::IO, FROM_HERE, |
263 base::BindOnce(&StartURLLoader, request, frame_tree_node_id_, | 279 base::BindOnce(&StartURLLoader, request, frame_tree_node_id_, |
264 client.PassInterface(), | 280 client.PassInterface(), |
265 browser_context_->GetResourceContext())); | 281 browser_context_->GetResourceContext())); |
266 } | 282 } |
(...skipping 21 matching lines...) Expand all Loading... |
288 } // namespace | 304 } // namespace |
289 | 305 |
290 mojom::URLLoaderFactoryPtr GetWebUIURLLoader(FrameTreeNode* node) { | 306 mojom::URLLoaderFactoryPtr GetWebUIURLLoader(FrameTreeNode* node) { |
291 int ftn_id = node->frame_tree_node_id(); | 307 int ftn_id = node->frame_tree_node_id(); |
292 if (g_factories.Get()[ftn_id].get() == nullptr) | 308 if (g_factories.Get()[ftn_id].get() == nullptr) |
293 g_factories.Get()[ftn_id] = base::MakeUnique<WebUIURLLoaderFactory>(node); | 309 g_factories.Get()[ftn_id] = base::MakeUnique<WebUIURLLoaderFactory>(node); |
294 return g_factories.Get()[ftn_id]->CreateBinding(); | 310 return g_factories.Get()[ftn_id]->CreateBinding(); |
295 } | 311 } |
296 | 312 |
297 } // namespace content | 313 } // namespace content |
OLD | NEW |