blob: d78311dc842aea0cf4564f5800b509d9609a6657 [file] [log] [blame]
Robbie McElrath2a5553c2019-03-28 06:28:551// 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 Gadani81e294b2019-08-29 16:26:327#include "services/network/public/cpp/resource_response.h"
Robbie McElrath2a5553c2019-03-28 06:28:558#include "services/network/public/mojom/url_loader.mojom.h"
9
10namespace content {
11
12AboutURLLoaderFactory::AboutURLLoaderFactory() = default;
13AboutURLLoaderFactory::~AboutURLLoaderFactory() = default;
14
15void 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
41void AboutURLLoaderFactory::Clone(
Julie Jeongeun Kim7f8e26a22019-10-10 12:09:5242 mojo::PendingReceiver<network::mojom::URLLoaderFactory> loader) {
43 receivers_.Add(this, std::move(loader));
Robbie McElrath2a5553c2019-03-28 06:28:5544}
45
46} // namespace content