Robbie McElrath | 2a5553c | 2019-03-28 06:28:55 | [diff] [blame] | 1 | // Copyright 2019 The Chromium Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "content/browser/about_url_loader_factory.h" |
| 6 | |
Lucas Furukawa Gadani | 81e294b | 2019-08-29 16:26:32 | [diff] [blame] | 7 | #include "services/network/public/cpp/resource_response.h" |
Robbie McElrath | 2a5553c | 2019-03-28 06:28:55 | [diff] [blame] | 8 | #include "services/network/public/mojom/url_loader.mojom.h" |
| 9 | |
| 10 | namespace content { |
| 11 | |
| 12 | AboutURLLoaderFactory::AboutURLLoaderFactory() = default; |
| 13 | AboutURLLoaderFactory::~AboutURLLoaderFactory() = default; |
| 14 | |
| 15 | void AboutURLLoaderFactory::CreateLoaderAndStart( |
| 16 | network::mojom::URLLoaderRequest loader, |
| 17 | int32_t routing_id, |
| 18 | int32_t request_id, |
| 19 | uint32_t options, |
| 20 | const network::ResourceRequest& request, |
| 21 | network::mojom::URLLoaderClientPtr client, |
| 22 | const net::MutableNetworkTrafficAnnotationTag& traffic_annotation) { |
| 23 | network::ResourceResponseHead response_head; |
| 24 | response_head.mime_type = "text/html"; |
| 25 | client->OnReceiveResponse(response_head); |
| 26 | |
| 27 | // Create a data pipe for transmitting the empty response. The |producer| |
| 28 | // doesn't add any data. |
| 29 | mojo::ScopedDataPipeProducerHandle producer; |
| 30 | mojo::ScopedDataPipeConsumerHandle consumer; |
| 31 | if (CreateDataPipe(nullptr, &producer, &consumer) != MOJO_RESULT_OK) { |
| 32 | client->OnComplete( |
| 33 | network::URLLoaderCompletionStatus(net::ERR_INSUFFICIENT_RESOURCES)); |
| 34 | return; |
| 35 | } |
| 36 | |
| 37 | client->OnStartLoadingResponseBody(std::move(consumer)); |
| 38 | client->OnComplete(network::URLLoaderCompletionStatus(net::OK)); |
| 39 | } |
| 40 | |
| 41 | void AboutURLLoaderFactory::Clone( |
Julie Jeongeun Kim | 7f8e26a2 | 2019-10-10 12:09:52 | [diff] [blame] | 42 | mojo::PendingReceiver<network::mojom::URLLoaderFactory> loader) { |
| 43 | receivers_.Add(this, std::move(loader)); |
Robbie McElrath | 2a5553c | 2019-03-28 06:28:55 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | } // namespace content |